diff --git a/src/commands.rs b/src/commands.rs index e614a8a..7d0410b 100644 --- a/src/commands.rs +++ b/src/commands.rs @@ -217,7 +217,12 @@ impl CommandManager { } } - fn handle_callbacks(&self, s: &mut Cursive, cmd: &String, args: &[String]) -> Result, String> { + fn handle_callbacks( + &self, + s: &mut Cursive, + cmd: &str, + args: &[String], + ) -> Result, String> { let local = { let mut main: ViewRef = s.find_id("main").unwrap(); main.on_command(s, cmd, args)? @@ -226,9 +231,7 @@ impl CommandManager { if let CommandResult::Consumed(output) = local { Ok(output) } else if let Some(callback) = self.callbacks.get(cmd) { - callback.as_ref() - .map(|cb| cb(s, args)) - .unwrap_or(Ok(None)) + callback.as_ref().map(|cb| cb(s, args)).unwrap_or(Ok(None)) } else { Err("Unknown command.".to_string()) } diff --git a/src/main.rs b/src/main.rs index db4b2ab..831647f 100644 --- a/src/main.rs +++ b/src/main.rs @@ -154,7 +154,11 @@ fn main() { cmd_manager.register_all(spotify.clone(), queue.clone(), playlists.clone()); let cmd_manager = Arc::new(cmd_manager); - CommandManager::register_keybindings(cmd_manager.clone(), &mut cursive, cfg.keybindings.clone()); + CommandManager::register_keybindings( + cmd_manager.clone(), + &mut cursive, + cfg.keybindings.clone(), + ); let search = ui::search::SearchView::new(spotify.clone(), queue.clone()); diff --git a/src/traits.rs b/src/traits.rs index 767feaa..cc48594 100644 --- a/src/traits.rs +++ b/src/traits.rs @@ -16,24 +16,25 @@ pub trait ListItem { } pub trait ViewExt: View { - fn on_command(&mut self, + fn on_command( + &mut self, _s: &mut Cursive, - _cmd: &String, - _args: &[String] + _cmd: &str, + _args: &[String], ) -> Result { Ok(CommandResult::Ignored) } } impl ViewExt for IdView { - fn on_command(&mut self, + fn on_command( + &mut self, s: &mut Cursive, - cmd: &String, - args: &[String] + cmd: &str, + args: &[String], ) -> Result { - self.with_view_mut(move |v| { - v.on_command(s, cmd, args) - }).unwrap() + self.with_view_mut(move |v| v.on_command(s, cmd, args)) + .unwrap() } } diff --git a/src/ui/layout.rs b/src/ui/layout.rs index 1c92808..9ef2a49 100644 --- a/src/ui/layout.rs +++ b/src/ui/layout.rs @@ -12,9 +12,9 @@ use cursive::views::EditView; use cursive::{Cursive, Printer}; use unicode_width::UnicodeWidthStr; -use events; -use traits::{ViewExt, IntoBoxedViewExt}; use commands::CommandResult; +use events; +use traits::{IntoBoxedViewExt, ViewExt}; struct Screen { title: String, @@ -77,7 +77,12 @@ impl Layout { self.focus = Some(s); } - pub fn view, T: IntoBoxedViewExt>(mut self, id: S, view: T, title: &str) -> Self { + pub fn view, T: IntoBoxedViewExt>( + mut self, + id: S, + view: T, + title: &str, + ) -> Self { (&mut self).add_view(id, view, title); self } @@ -156,7 +161,10 @@ impl View for Layout { printer.with_color(style, |printer| { printer.print_hline((0, printer.size.y - cmdline_height), printer.size.x, " "); - printer.print((0, printer.size.y - cmdline_height), &format!("ERROR: {}", e)); + printer.print( + (0, printer.size.y - cmdline_height), + &format!("ERROR: {}", e), + ); }); } @@ -248,10 +256,11 @@ impl View for Layout { } impl ViewExt for Layout { - fn on_command(&mut self, + fn on_command( + &mut self, s: &mut Cursive, - cmd: &String, - args: &[String] + cmd: &str, + args: &[String], ) -> Result { if cmd == "focus" { if let Some(view) = args.get(0) { diff --git a/src/ui/listview.rs b/src/ui/listview.rs index a68a6f6..e7b4375 100644 --- a/src/ui/listview.rs +++ b/src/ui/listview.rs @@ -9,9 +9,9 @@ use cursive::view::ScrollBase; use cursive::{Cursive, Printer, Rect, Vec2}; use unicode_width::UnicodeWidthStr; +use commands::CommandResult; use queue::Queue; use traits::{ListItem, ViewExt}; -use commands::CommandResult; pub struct ListView { content: Arc>>, @@ -174,10 +174,11 @@ impl View for ListView { } impl ViewExt for ListView { - fn on_command(&mut self, + fn on_command( + &mut self, _s: &mut Cursive, - cmd: &String, - args: &[String] + cmd: &str, + args: &[String], ) -> Result { if cmd == "play" { let content = self.content.read().unwrap(); @@ -195,27 +196,25 @@ impl ViewExt for ListView { return Ok(CommandResult::Consumed(None)); } - if cmd != "move" { - return Ok(CommandResult::Ignored); - } + if cmd == "move" { + if let Some(dir) = args.get(0) { + let amount: i32 = args + .get(1) + .unwrap_or(&"1".to_string()) + .parse() + .map_err(|e| format!("{:?}", e))?; - if let Some(dir) = args.get(0) { - let amount: i32 = args - .get(1) - .unwrap_or(&"1".to_string()) - .parse() - .map_err(|e| format!("{:?}", e))?; + let len = self.content.read().unwrap().len(); - let len = self.content.read().unwrap().len(); + if dir == "up" && self.selected > 0 { + self.move_focus(-amount); + return Ok(CommandResult::Consumed(None)); + } - if dir == "up" && self.selected > 0 { - self.move_focus(amount * -1); - return Ok(CommandResult::Consumed(None)); - } - - if dir == "down" && self.selected < len - 1 { - self.move_focus(amount); - return Ok(CommandResult::Consumed(None)); + if dir == "down" && self.selected < len - 1 { + self.move_focus(amount); + return Ok(CommandResult::Consumed(None)); + } } } diff --git a/src/ui/playlists.rs b/src/ui/playlists.rs index 3805873..d4426c3 100644 --- a/src/ui/playlists.rs +++ b/src/ui/playlists.rs @@ -56,10 +56,11 @@ impl ViewWrapper for PlaylistView { } impl ViewExt for PlaylistView { - fn on_command(&mut self, + fn on_command( + &mut self, s: &mut Cursive, - cmd: &String, - args: &[String] + cmd: &str, + args: &[String], ) -> Result { if cmd == "delete" { if let Some(dialog) = self.delete_dialog() { @@ -69,6 +70,5 @@ impl ViewExt for PlaylistView { } self.list.on_command(s, cmd, args) - } } diff --git a/src/ui/queue.rs b/src/ui/queue.rs index 09c0bdd..54306a3 100644 --- a/src/ui/queue.rs +++ b/src/ui/queue.rs @@ -24,10 +24,19 @@ impl QueueView { pub fn new(queue: Arc, playlists: Arc) -> QueueView { let list = ListView::new(queue.queue.clone(), queue.clone()); - QueueView { list, playlists, queue } + QueueView { + list, + playlists, + queue, + } } - fn save_dialog_cb(s: &mut Cursive, queue: Arc, playlists: Arc, id: Option) { + fn save_dialog_cb( + s: &mut Cursive, + queue: Arc, + playlists: Arc, + id: Option, + ) { let tracks = queue.queue.read().unwrap().clone(); match id { Some(id) => { @@ -95,10 +104,11 @@ impl ViewWrapper for QueueView { } impl ViewExt for QueueView { - fn on_command(&mut self, + fn on_command( + &mut self, s: &mut Cursive, - cmd: &String, - args: &[String] + cmd: &str, + args: &[String], ) -> Result { if cmd == "play" { self.queue.play(self.list.get_selected_index(), true); @@ -114,8 +124,7 @@ impl ViewExt for QueueView { return Ok(CommandResult::Consumed(None)); } - self.with_view_mut(move |v| { - v.on_command(s, cmd, args) - }).unwrap() + self.with_view_mut(move |v| v.on_command(s, cmd, args)) + .unwrap() } } diff --git a/src/ui/search.rs b/src/ui/search.rs index 8eb7424..edaa304 100644 --- a/src/ui/search.rs +++ b/src/ui/search.rs @@ -47,7 +47,7 @@ impl SearchView { edit: searchfield, list, edit_focused: true, - spotify + spotify, } } @@ -118,12 +118,12 @@ impl View for SearchView { } } - impl ViewExt for SearchView { - fn on_command(&mut self, + fn on_command( + &mut self, s: &mut Cursive, - cmd: &String, - args: &[String] + cmd: &str, + args: &[String], ) -> Result { if cmd == "search" && !args.is_empty() { self.run_search(args.join(" "));