use crossterm::event::{KeyCode, KeyEvent, KeyModifiers};
use crate::app::{App, InputMode};
use crate::integrations::IntegrationKind;
fn is_color_field(current_field: usize, integration: &IntegrationKind) -> bool {
let colors_start = match integration {
IntegrationKind::CustomCommands => 8,
IntegrationKind::Jira => 9,
};
current_field >= colors_start && current_field < colors_start + 6
}
fn is_hide_eye_candy_field(current_field: usize, integration: &IntegrationKind) -> bool {
match integration {
IntegrationKind::CustomCommands => current_field == 7,
IntegrationKind::Jira => current_field == 8,
}
}
fn is_passphrase_field(current_field: usize, integration: &IntegrationKind) -> bool {
match integration {
IntegrationKind::CustomCommands => current_field == 5,
IntegrationKind::Jira => current_field == 6,
}
}
fn is_triggers_field(current_field: usize, integration: &IntegrationKind) -> bool {
match integration {
IntegrationKind::CustomCommands => current_field == 6,
IntegrationKind::Jira => current_field == 7,
}
}
pub fn handle_settings_input(app: &mut App, key: KeyEvent) {
let (current_field, integration_kind) = if let InputMode::Settings {
current_field,
integration,
..
} = &app.input_mode
{
(*current_field, integration.clone())
} else {
(0, IntegrationKind::CustomCommands)
};
let legacy_field = app.settings_legacy_time_format_field();
let _passphrase_field = app.settings_passphrase_field();
let on_color = is_color_field(current_field, &integration_kind);
let on_passphrase = is_passphrase_field(current_field, &integration_kind);
let on_triggers = is_triggers_field(current_field, &integration_kind);
let on_hide_eye_candy = is_hide_eye_candy_field(current_field, &integration_kind);
match key.code {
KeyCode::Enter | KeyCode::Char(' ') if on_triggers => {
app.open_triggers();
}
KeyCode::Char(_) | KeyCode::Backspace if on_triggers => {
}
KeyCode::Enter if on_passphrase => {
let is_initial = !app.secrets.has_encrypted_file();
app.input_mode = InputMode::PassphraseChange {
old_passphrase: String::new(),
new_passphrase: String::new(),
confirm_passphrase: String::new(),
current_field: 0,
cursor_pos: 0,
error_message: None,
is_initial_setup: is_initial,
};
}
KeyCode::Char(' ') if on_passphrase => {
let is_initial = !app.secrets.has_encrypted_file();
app.input_mode = InputMode::PassphraseChange {
old_passphrase: String::new(),
new_passphrase: String::new(),
confirm_passphrase: String::new(),
current_field: 0,
cursor_pos: 0,
error_message: None,
is_initial_setup: is_initial,
};
}
KeyCode::Enter => {
if let Err(_e) = app.save_settings() {
}
}
KeyCode::Esc => {
app.cancel_input();
}
KeyCode::Tab if key.modifiers.contains(KeyModifiers::SHIFT) => {
app.previous_field()
}
KeyCode::Tab => app.next_field(),
KeyCode::Up if key.modifiers.contains(KeyModifiers::SHIFT) => {
app.scroll_debug_log(-1);
}
KeyCode::Down if key.modifiers.contains(KeyModifiers::SHIFT) => {
app.scroll_debug_log(1);
}
KeyCode::Up if key.modifiers.contains(KeyModifiers::CONTROL) => {
app.scroll_debug_log(-1);
}
KeyCode::Down if key.modifiers.contains(KeyModifiers::CONTROL) => {
app.scroll_debug_log(1);
}
KeyCode::Up => app.previous_field(),
KeyCode::Down => app.next_field(),
KeyCode::Left if current_field == 0 => {
app.cycle_integration();
}
KeyCode::Right if current_field == 0 => {
app.cycle_integration();
}
KeyCode::Char(' ') if current_field == 0 => {
app.cycle_integration();
}
KeyCode::Char(_) if current_field == 0 => {
}
KeyCode::Backspace if current_field == 0 => {
}
KeyCode::Left if current_field == legacy_field => {
app.toggle_legacy_time_format();
}
KeyCode::Right if current_field == legacy_field => {
app.toggle_legacy_time_format();
}
KeyCode::Char(' ') if current_field == legacy_field => {
app.toggle_legacy_time_format();
}
KeyCode::Char(_) if current_field == legacy_field => {
}
KeyCode::Backspace if current_field == legacy_field => {
}
KeyCode::Left if on_hide_eye_candy => app.toggle_hide_eye_candy(),
KeyCode::Right if on_hide_eye_candy => app.toggle_hide_eye_candy(),
KeyCode::Char(' ') if on_hide_eye_candy => app.toggle_hide_eye_candy(),
KeyCode::Char(_) if on_hide_eye_candy => {}
KeyCode::Backspace if on_hide_eye_candy => {}
KeyCode::Left if on_passphrase => {}
KeyCode::Right if on_passphrase => {}
KeyCode::Char(_) if on_passphrase => {}
KeyCode::Backspace if on_passphrase => {}
KeyCode::Left if on_color => app.cycle_color(false),
KeyCode::Right if on_color => app.cycle_color(true),
KeyCode::Left => app.cursor_left(),
KeyCode::Right => app.cursor_right(),
KeyCode::Char('+') if key.modifiers.contains(KeyModifiers::CONTROL) => {
app.insert_variable();
}
KeyCode::Char(c) => app.input_char(c),
KeyCode::Backspace => app.delete_char(),
_ => {}
}
}