@@ -85,6 +85,22 @@ fn setup_integration_logging() {
88+fn restore_term() -> Result<(), Error> {
89+ let mut stdout = stdout();
90+ // reset cursor shape
91+ write!(stdout, "\x1B[0 q")?;
92+ // Ignore errors on disabling, this might trigger on windows if we call
93+ // disable without calling enable previously
94+ let _ = execute!(stdout, DisableMouseCapture);
97+ DisableBracketedPaste,
98+ terminal::LeaveAlternateScreen
100+ terminal::disable_raw_mode()?;
88impl Application {
104impl Application {
89 pub fn new(args: Args, config: Config) -> Result<Self, Error> {
105 pub fn new(args: Args, config: Config) -> Result<Self, Error> {
90 #[cfg(feature = "integration")]
106 #[cfg(feature = "integration")]
@@ -389,7 +405,7 @@ impl Application {
389 match signal {
405 match signal {
390 signal::SIGTSTP => {
406 signal::SIGTSTP => {
391 self.compositor.save_cursor();
407 self.compositor.save_cursor();
392− self.restore_term().unwrap();
408+ restore_term().unwrap();
393 low_level::emulate_default_handler(signal::SIGTSTP).unwrap();
409 low_level::emulate_default_handler(signal::SIGTSTP).unwrap();
395 signal::SIGCONT => {
411 signal::SIGCONT => {
@@ -803,18 +819,6 @@ impl Application {
806− fn restore_term(&mut self) -> Result<(), Error> {
807− let mut stdout = stdout();
808− // reset cursor shape
809− write!(stdout, "\x1B[0 q")?;
810− // Ignore errors on disabling, this might trigger on windows if we call
811− // disable without calling enable previously
812− let _ = execute!(stdout, DisableMouseCapture);
813− execute!(stdout, terminal::LeaveAlternateScreen)?;
814− terminal::disable_raw_mode()?;
818 pub async fn run<S>(&mut self, input_stream: &mut S) -> Result<i32, Error>
822 pub async fn run<S>(&mut self, input_stream: &mut S) -> Result<i32, Error>
820 S: Stream<Item = crossterm::Result<crossterm::event::Event>> + Unpin,
824 S: Stream<Item = crossterm::Result<crossterm::event::Event>> + Unpin,
@@ -826,20 +830,14 @@ impl Application {
826 std::panic::set_hook(Box::new(move |info| {
830 std::panic::set_hook(Box::new(move |info| {
827 // We can't handle errors properly inside this closure. And it's
831 // We can't handle errors properly inside this closure. And it's
828 // probably not a good idea to `unwrap()` inside a panic handler.
832 // probably not a good idea to `unwrap()` inside a panic handler.
829− // So we just ignore the `Result`s.
833+ // So we just ignore the `Result`.
830− let _ = execute!(std::io::stdout(), DisableMouseCapture);
834+ let _ = restore_term();
833− terminal::LeaveAlternateScreen,
834− DisableBracketedPaste
836− let _ = terminal::disable_raw_mode();
837 hook(info);
835 hook(info);
840 self.event_loop(input_stream).await;
838 self.event_loop(input_stream).await;
841 self.close().await?;
839 self.close().await?;
842− self.restore_term()?;
840+ restore_term()?;
844 Ok(self.editor.exit_code)
842 Ok(self.editor.exit_code)