Krolyxon
Commit a08c3a6

rmptuisrceventpl_rename_keys.rs

43 lines · 1.1 KB · Rust

1use crate::{
2 app::{App, AppResult},
3 ui::InputMode,
4};
5use crossterm::event::{KeyCode, KeyEvent};
6
7pub fn handle_pl_rename_keys(key_event: KeyEvent, app: &mut App) -> AppResult<()> {
8 match key_event.code {
9 KeyCode::Esc => {
10 app.pl_newname_input.clear();
11 app.reset_cursor();
12 app.inputmode = InputMode::Normal;
13 }
14 KeyCode::Char(to_insert) => {
15 app.enter_char(to_insert);
16 }
17 KeyCode::Enter => {
18 app.conn.conn.pl_rename(
19 app.pl_list.get_item_at_current_index(),
20 &app.pl_newname_input,
21 )?;
22 app.pl_list.list = App::get_playlist(&mut app.conn.conn)?;
23 app.pl_newname_input.clear();
24 app.reset_cursor();
25 app.inputmode = InputMode::Normal;
26 }
27
28 KeyCode::Backspace => {
29 app.delete_char();
30 }
31
32 KeyCode::Left => {
33 app.move_cursor_left();
34 }
35
36 KeyCode::Right => {
37 app.move_cursor_right();
38 }
39
40 _ => {}
41 }
42 Ok(())
43}