Krolyxon
Commit 22c8c98

rmptuisrcevent_handlernew_pl_keys.rs

47 lines · 1.2 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.append_list = App::get_append_list(&mut app.conn.conn)?;
27
28 app.reset_cursor();
29 app.inputmode = InputMode::Normal;
30 }
31
32 KeyCode::Backspace => {
33 app.delete_char();
34 }
35
36 KeyCode::Left => {
37 app.move_cursor_left();
38 }
39
40 KeyCode::Right => {
41 app.move_cursor_right();
42 }
43
44 _ => {}
45 }
46 Ok(())
47}