use ratatui::crossterm::event::KeyCode;
pub const Y_MOVE: &str = "↑↓/jk";
pub const CTRL_Y_MOVE: &str = "ctrl-↑↓/jk";
pub const X_MOVE: &str = "←→/hl";
pub const CTRL_X_MOVE: &str = "ctrl-←→/hl";
pub fn is_down(c: KeyCode) -> bool {
matches!(c, KeyCode::Char('j') | KeyCode::Down)
}
pub fn is_up(c: KeyCode) -> bool {
matches!(c, KeyCode::Char('k') | KeyCode::Up)
}
pub fn is_open(c: KeyCode) -> bool {
matches!(c, KeyCode::Enter)
}
pub fn is_back(c: KeyCode) -> bool {
matches!(c, KeyCode::Esc)
}
pub fn is_left(c: KeyCode) -> bool {
matches!(c, KeyCode::Char('h') | KeyCode::Left)
}
pub fn is_right(c: KeyCode) -> bool {
matches!(c, KeyCode::Char('l') | KeyCode::Right)
}
pub fn norm_esc(code: KeyCode, ctrl: bool) -> KeyCode {
if ctrl && matches!(code, KeyCode::Char('[')) {
KeyCode::Esc
} else {
code
}
}
pub fn char_to_byte(s: &str, idx: usize) -> usize {
s.char_indices().nth(idx).map(|(b, _)| b).unwrap_or(s.len())
}