| @@ -22,7 +22,15 @@ use matrix_sdk::ruma::OwnedUserId; |
| 22 | 22 | use modalkit::crossterm::{ |
| 23 | 23 | self, |
| 24 | 24 | cursor::Show as CursorShow, |
| 25 | | event::{poll, read, DisableBracketedPaste, EnableBracketedPaste, Event}, |
| 25 | event::{ |
| 26 | poll, |
| 27 | read, |
| 28 | DisableBracketedPaste, |
| 29 | DisableFocusChange, |
| 30 | EnableBracketedPaste, |
| 31 | EnableFocusChange, |
| 32 | Event, |
| 33 | }, |
| 26 | 34 | execute, |
| 27 | 35 | terminal::{EnterAlternateScreen, LeaveAlternateScreen, SetTitle}, |
| 28 | 36 | }; |
| @@ -109,6 +117,7 @@ struct Application { |
| 109 | 117 | bindings: KeyManager<TerminalKey, ProgramAction, RepeatType, ProgramContext>, |
| 110 | 118 | actstack: VecDeque<(ProgramAction, ProgramContext)>, |
| 111 | 119 | screen: ScreenState<IambWindow, IambInfo>, |
| 120 | focused: bool, |
| 112 | 121 | } |
| 113 | 122 | |
| 114 | 123 | impl Application { |
| @@ -120,6 +129,7 @@ impl Application { |
| 120 | 129 | crossterm::terminal::enable_raw_mode()?; |
| 121 | 130 | crossterm::execute!(stdout, EnterAlternateScreen)?; |
| 122 | 131 | crossterm::execute!(stdout, EnableBracketedPaste)?; |
| 132 | crossterm::execute!(stdout, EnableFocusChange)?; |
| 123 | 133 | |
| 124 | 134 | let title = format!("iamb ({})", settings.profile.user_id); |
| 125 | 135 | crossterm::execute!(stdout, SetTitle(title))?; |
| @@ -154,11 +164,13 @@ impl Application { |
| 154 | 164 | bindings, |
| 155 | 165 | actstack, |
| 156 | 166 | screen, |
| 167 | focused: true, |
| 157 | 168 | }) |
| 158 | 169 | } |
| 159 | 170 | |
| 160 | 171 | fn redraw(&mut self, full: bool, store: &mut ProgramStore) -> Result<(), std::io::Error> { |
| 161 | 172 | let bindings = &mut self.bindings; |
| 173 | let focused = self.focused; |
| 162 | 174 | let sstate = &mut self.screen; |
| 163 | 175 | let term = &mut self.terminal; |
| 164 | 176 | |
| @@ -176,7 +188,11 @@ impl Application { |
| 176 | 188 | // Don't show terminal cursor when we show a dialog. |
| 177 | 189 | let hide_cursor = !dialogstr.is_empty(); |
| 178 | 190 | |
| 179 | | let screen = Screen::new(store).show_dialog(dialogstr).show_mode(modestr).borders(true); |
| 191 | let screen = Screen::new(store) |
| 192 | .show_dialog(dialogstr) |
| 193 | .show_mode(modestr) |
| 194 | .borders(true) |
| 195 | .focus(focused); |
| 180 | 196 | f.render_stateful_widget(screen, area, sstate); |
| 181 | 197 | |
| 182 | 198 | if hide_cursor { |
| @@ -212,8 +228,11 @@ impl Application { |
| 212 | 228 | Event::Mouse(_) => { |
| 213 | 229 | // Do nothing for now. |
| 214 | 230 | }, |
| 215 | | Event::FocusGained | Event::FocusLost => { |
| 216 | | // Do nothing for now. |
| 231 | Event::FocusGained => { |
| 232 | self.focused = true; |
| 233 | }, |
| 234 | Event::FocusLost => { |
| 235 | self.focused = false; |
| 217 | 236 | }, |
| 218 | 237 | Event::Resize(_, _) => { |
| 219 | 238 | // We'll redraw for the new size next time step() is called. |
| @@ -532,13 +551,18 @@ async fn run(settings: ApplicationSettings) -> IambResult<()> { |
| 532 | 551 | |
| 533 | 552 | login(worker, &settings).await.unwrap_or_else(print_exit); |
| 534 | 553 | |
| 535 | | // Make sure panics clean up the terminal properly. |
| 536 | | let orig_hook = std::panic::take_hook(); |
| 537 | | std::panic::set_hook(Box::new(move |panic_info| { |
| 554 | fn restore_tty() { |
| 538 | 555 | let _ = crossterm::terminal::disable_raw_mode(); |
| 539 | 556 | let _ = crossterm::execute!(stdout(), DisableBracketedPaste); |
| 557 | let _ = crossterm::execute!(stdout(), DisableFocusChange); |
| 540 | 558 | let _ = crossterm::execute!(stdout(), LeaveAlternateScreen); |
| 541 | 559 | let _ = crossterm::execute!(stdout(), CursorShow); |
| 560 | } |
| 561 | |
| 562 | // Make sure panics clean up the terminal properly. |
| 563 | let orig_hook = std::panic::take_hook(); |
| 564 | std::panic::set_hook(Box::new(move |panic_info| { |
| 565 | restore_tty(); |
| 542 | 566 | orig_hook(panic_info); |
| 543 | 567 | process::exit(1); |
| 544 | 568 | })); |
| @@ -547,6 +571,7 @@ async fn run(settings: ApplicationSettings) -> IambResult<()> { |
| 547 | 571 | |
| 548 | 572 | // We can now run the application. |
| 549 | 573 | application.run().await?; |
| 574 | restore_tty(); |
| 550 | 575 | |
| 551 | 576 | Ok(()) |
| 552 | 577 | } |