diff --git a/src/app.rs b/src/app.rs index 375e1ef..0dcfbee 100644 --- a/src/app.rs +++ b/src/app.rs @@ -11,7 +11,7 @@ use crate::profile; pub fn run(name: Option, notify: bool) -> Result<()> { let mut current = match name { Some(n) => n, - None => pick_profile()?, + None => pick_profile(None)?, }; loop { @@ -64,14 +64,14 @@ fn run_one(name: &str, notify: bool) -> Result> { /// Open the interactive profile picker; loops until a profile is selected to start. /// Manages the terminal lifecycle; stays in alternate screen on success so the /// TUI can take over seamlessly. -pub fn pick_profile() -> Result { +pub fn pick_profile(focus: Option<&str>) -> Result { enable_raw_mode()?; let mut stdout = io::stdout(); execute!(stdout, EnterAlternateScreen)?; let backend = CrosstermBackend::new(stdout); let mut terminal = Terminal::new(backend)?; - let result = pick_profile_loop(&mut terminal); + let result = pick_profile_loop(&mut terminal, focus); if result.is_err() { let _ = disable_raw_mode(); @@ -81,9 +81,12 @@ pub fn pick_profile() -> Result { result } -fn pick_profile_loop(terminal: &mut Terminal>) -> Result { +fn pick_profile_loop( + terminal: &mut Terminal>, + initial_focus: Option<&str>, +) -> Result { use crate::picker::{PickerAction, PickerItem}; - let mut focus: Option = None; + let mut focus: Option = initial_focus.map(|s| s.to_string()); loop { let config = crate::config::load(); let theme = &config.theme; diff --git a/src/tui/keys.rs b/src/tui/keys.rs index 63ea160..d09245b 100644 --- a/src/tui/keys.rs +++ b/src/tui/keys.rs @@ -16,7 +16,7 @@ impl super::app::App { // Quit confirmation captures all input if self.quit_confirm { match key.code { - KeyCode::Char('y') => { + KeyCode::Char('y') | KeyCode::Enter => { self.phone.hangup_all(); self.quit = true; } @@ -119,6 +119,11 @@ impl super::app::App { self.switch_to = true; self.quit = true; } + KeyCode::Esc => { + self.phone.hangup_all(); + self.switch_to = true; + self.quit = true; + } KeyCode::Char('d') if !ctrl => { self.dial.mode = InputMode::Dial; self.command.error = None; diff --git a/src/tui/mod.rs b/src/tui/mod.rs index ab984c6..9ca288e 100644 --- a/src/tui/mod.rs +++ b/src/tui/mod.rs @@ -168,7 +168,7 @@ pub fn run( } if app.switch_to { - match crate::app::pick_profile() { + match crate::app::pick_profile(Some(&app.profile_name)) { Ok(name) => return Ok(Some(name)), Err(_) => {} }