Krolyxon
Commit 6da9e0c

rmptuisrceventnew_pl_keys.rs

45 lines · 1.1 KB · Rust

1use crate::{
2 app::{App, AppResult},
3 ui::InputMode,
4};
5use crossterm::event::{KeyCode, KeyEvent};
6
7pub fn handle_new_pl_keys(key_event: KeyEvent, app: &mut App) -> AppResult<()> {
8 match key_event.code {
9 KeyCode::Esc => {
10 app.pl_new_pl_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 let pl_name = &app.pl_new_pl_input;
19
20 for song in app.pl_new_pl_songs_buffer.iter() {
21 app.conn.conn.pl_push(pl_name, song)?;
22 }
23 app.pl_new_pl_input.clear();
24
25 app.pl_list.list = App::get_playlist(&mut app.conn.conn)?;
26 app.reset_cursor();
27 app.inputmode = InputMode::Normal;
28 }
29
30 KeyCode::Backspace => {
31 app.delete_char();
32 }
33
34 KeyCode::Left => {
35 app.move_cursor_left();
36 }
37
38 KeyCode::Right => {
39 app.move_cursor_right();
40 }
41
42 _ => {}
43 }
44 Ok(())
45}