Add redraw command and bind to CTRL+L

solves #609
This commit is contained in:
Henrik Friedrichsen
2021-10-01 18:43:45 +02:00
parent 9e5160bd93
commit a78bbe6684
2 changed files with 9 additions and 0 deletions

View File

@@ -135,6 +135,7 @@ pub enum Command {
Sort(SortKey, SortDirection), Sort(SortKey, SortDirection),
Logout, Logout,
ShowRecommendations(TargetMode), ShowRecommendations(TargetMode),
Redraw,
} }
impl fmt::Display for Command { impl fmt::Display for Command {
@@ -195,6 +196,7 @@ impl fmt::Display for Command {
Command::Sort(key, direction) => format!("sort {} {}", key, direction), Command::Sort(key, direction) => format!("sort {} {}", key, direction),
Command::Logout => "logout".to_string(), Command::Logout => "logout".to_string(),
Command::ShowRecommendations(mode) => format!("similar {}", mode), Command::ShowRecommendations(mode) => format!("similar {}", mode),
Command::Redraw => "redraw".to_string(),
}; };
// escape the command separator // escape the command separator
let repr = repr.replace(";", ";;"); let repr = repr.replace(";", ";;");
@@ -462,6 +464,7 @@ pub fn parse(input: &str) -> Option<Vec<Command>> {
}) })
.map(Command::ShowRecommendations), .map(Command::ShowRecommendations),
"noop" => Some(Command::Noop), "noop" => Some(Command::Noop),
"redraw" => Some(Command::Redraw),
_ => None, _ => None,
}; };
commands.push(command?); commands.push(command?);

View File

@@ -119,6 +119,11 @@ impl CommandManager {
s.quit(); s.quit();
Ok(None) Ok(None)
} }
Command::Redraw => {
info!("Redrawing screen");
s.clear();
Ok(None)
}
Command::Stop => { Command::Stop => {
self.queue.stop(); self.queue.stop();
Ok(None) Ok(None)
@@ -346,6 +351,7 @@ impl CommandManager {
let mut kb = HashMap::new(); let mut kb = HashMap::new();
kb.insert("q".into(), vec![Command::Quit]); kb.insert("q".into(), vec![Command::Quit]);
kb.insert("Ctrl+l".into(), vec![Command::Redraw]);
kb.insert("Shift+p".into(), vec![Command::TogglePlay]); kb.insert("Shift+p".into(), vec![Command::TogglePlay]);
kb.insert("Shift+u".into(), vec![Command::UpdateLibrary]); kb.insert("Shift+u".into(), vec![Command::UpdateLibrary]);
kb.insert("Shift+s".into(), vec![Command::Stop]); kb.insert("Shift+s".into(), vec![Command::Stop]);