Refactor command handling

This commit is contained in:
KoffeinFlummi
2019-03-28 03:05:25 +01:00
parent 83a394790f
commit 486bc7617e
10 changed files with 380 additions and 349 deletions

View File

@@ -1,9 +1,48 @@
use std::sync::Arc;
use cursive::view::{View, ViewWrapper};
use cursive::views::IdView;
use cursive::Cursive;
use commands::CommandResult;
use queue::Queue;
pub trait ListItem {
fn is_playing(&self, queue: Arc<Queue>) -> bool;
fn display_left(&self) -> String;
fn display_right(&self) -> String;
fn play(&self, queue: Arc<Queue>);
fn queue(&self, queue: Arc<Queue>);
}
pub trait ViewExt: View {
fn on_command(&mut self,
_s: &mut Cursive,
_cmd: &String,
_args: &[String]
) -> Result<CommandResult, String> {
Ok(CommandResult::Ignored)
}
}
impl<V: ViewExt> ViewExt for IdView<V> {
fn on_command(&mut self,
s: &mut Cursive,
cmd: &String,
args: &[String]
) -> Result<CommandResult, String> {
self.with_view_mut(move |v| {
v.on_command(s, cmd, args)
}).unwrap()
}
}
pub trait IntoBoxedViewExt {
fn as_boxed_view_ext(self) -> Box<dyn ViewExt>;
}
impl<V: ViewExt> IntoBoxedViewExt for V {
fn as_boxed_view_ext(self) -> Box<dyn ViewExt> {
Box::new(self)
}
}