crossterm-rs / crossterm

Cross platform terminal library rust
MIT License
3.29k stars 280 forks source link

Terminal settings do not get restored on exit when using bash #858

Closed asomers closed 10 months ago

asomers commented 10 months ago

Describe the bug Ever since I ported my applications from Termion to Crossterm, the terminal settings do not get restored when the application quits. But that only happens if my login shell is bash. If my login shell is fish, then everything works fine. Is there some standard teardown command needs to be used with Crossterm?

To Reproduce

If using ZFS on FreeBSD (and presumably Linux too) Steps to reproduce the behavior:

  1. git clone git@github.com:asomers/ztop.git
  2. cd ztop
  3. cargo run
  4. press 'q'
  5. type 'stty' and press Enter
  6. Observe this garbled output
    speed 9600 baud;
                lflags: -icanon -isig -iexten -echo echoke echoctl
                                                                  iflags: -icrnl -ixon -ixany -imaxbel ignbrk -brkint
                                                                                                                     oflags: -opost tab0
                                                                                                                                        cflags: cs8 -parenb
  7. Type anything else and observe that commands aren't visibly echoed to the screen

If not using ZFS, but still using FreeBSD

  1. git clone git@github.com:asomers/gstat-rs.git
  2. cd gstat-rs
  3. cargo run
  4. press 'q'
  5. Observe this same problems as above

Expected behavior When the application exits, the terminal's original behavior should be restored. Keypresses should be echoed to the screen, and newlines should include a carriage return.

OS

Terminal/Console xterm-256color, tmux-256color, and reportedly some kind of OSX terminal, too.

asomers commented 10 months ago

Oh, I think I've figured out. I was missing crossterm::terminal::disable_raw_mode. I should've read the docs better. I guess I was just confused because I didn't need that with Termion, nor with certain shells.