Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 8 additions & 5 deletions src/app.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ use crate::profile;
pub fn run(name: Option<String>, notify: bool) -> Result<()> {
let mut current = match name {
Some(n) => n,
None => pick_profile()?,
None => pick_profile(None)?,
};

loop {
Expand Down Expand Up @@ -64,14 +64,14 @@ fn run_one(name: &str, notify: bool) -> Result<Option<String>> {
/// 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<String> {
pub fn pick_profile(focus: Option<&str>) -> Result<String> {
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();
Expand All @@ -81,9 +81,12 @@ pub fn pick_profile() -> Result<String> {
result
}

fn pick_profile_loop(terminal: &mut Terminal<CrosstermBackend<io::Stdout>>) -> Result<String> {
fn pick_profile_loop(
terminal: &mut Terminal<CrosstermBackend<io::Stdout>>,
initial_focus: Option<&str>,
) -> Result<String> {
use crate::picker::{PickerAction, PickerItem};
let mut focus: Option<String> = None;
let mut focus: Option<String> = initial_focus.map(|s| s.to_string());
loop {
let config = crate::config::load();
let theme = &config.theme;
Expand Down
7 changes: 6 additions & 1 deletion src/tui/keys.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down Expand Up @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion src/tui/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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(_) => {}
}
Expand Down
Loading