From 65f76181d3cbee48096ebe0424869d4c78bac89b Mon Sep 17 00:00:00 2001 From: krolxon Date: Wed, 12 Jun 2024 18:13:05 +0530 Subject: new feature: add to new playlist --- src/event/new_pl_keys.rs | 45 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 45 insertions(+) create mode 100644 src/event/new_pl_keys.rs (limited to 'src/event/new_pl_keys.rs') diff --git a/src/event/new_pl_keys.rs b/src/event/new_pl_keys.rs new file mode 100644 index 0000000..75c9e97 --- /dev/null +++ b/src/event/new_pl_keys.rs @@ -0,0 +1,45 @@ +use crate::{ + app::{App, AppResult}, + ui::InputMode, +}; +use crossterm::event::{KeyCode, KeyEvent}; + +pub fn handle_new_pl_keys(key_event: KeyEvent, app: &mut App) -> AppResult<()> { + match key_event.code { + KeyCode::Esc => { + app.pl_new_pl_input.clear(); + app.reset_cursor(); + app.inputmode = InputMode::Normal; + } + KeyCode::Char(to_insert) => { + app.enter_char(to_insert); + } + KeyCode::Enter => { + let pl_name = &app.pl_new_pl_input; + + for song in app.pl_new_pl_songs_buffer.iter() { + app.conn.conn.pl_push(pl_name, song)?; + } + app.pl_new_pl_input.clear(); + + app.pl_list.list = App::get_playlist(&mut app.conn.conn)?; + app.reset_cursor(); + app.inputmode = InputMode::Normal; + } + + KeyCode::Backspace => { + app.delete_char(); + } + + KeyCode::Left => { + app.move_cursor_left(); + } + + KeyCode::Right => { + app.move_cursor_right(); + } + + _ => {} + } + Ok(()) +} -- cgit v1.2.3