use crate::app::{AccountSwitcherState, App}; use crate::tdlib::TdClientTrait; use crossterm::event::{KeyCode, KeyEvent}; /// Обработка ввода в модалке переключения аккаунтов. pub async fn handle_account_switcher( app: &mut App, key: KeyEvent, command: Option, ) { let Some(state) = &app.account_switcher else { return; }; match state { AccountSwitcherState::SelectAccount { .. } => match command { Some(crate::config::Command::MoveUp) => { app.account_switcher_select_prev(); } Some(crate::config::Command::MoveDown) => { app.account_switcher_select_next(); } Some(crate::config::Command::SubmitMessage) => { app.account_switcher_confirm(); } Some(crate::config::Command::Cancel) => { app.close_account_switcher(); } _ => match key.code { KeyCode::Char('a') | KeyCode::Char('ф') => { app.account_switcher_start_add(); } _ => {} }, }, AccountSwitcherState::AddAccount { .. } => match key.code { KeyCode::Esc => { app.account_switcher_back(); } KeyCode::Enter => { app.account_switcher_confirm_add(); } KeyCode::Backspace => { if let Some(AccountSwitcherState::AddAccount { name_input, cursor_position, error, }) = &mut app.account_switcher { if *cursor_position > 0 { let mut chars: Vec = name_input.chars().collect(); chars.remove(*cursor_position - 1); *name_input = chars.into_iter().collect(); *cursor_position -= 1; *error = None; } } } KeyCode::Char(c) => { if let Some(AccountSwitcherState::AddAccount { name_input, cursor_position, error, }) = &mut app.account_switcher { let mut chars: Vec = name_input.chars().collect(); chars.insert(*cursor_position, c); *name_input = chars.into_iter().collect(); *cursor_position += 1; *error = None; } } _ => {} }, } }