Skip to content

Commit

Permalink
Added Lyrics view
Browse files Browse the repository at this point in the history
  • Loading branch information
Naapperas committed Jun 26, 2024
1 parent ff95a74 commit 52455e4
Show file tree
Hide file tree
Showing 6 changed files with 77 additions and 1 deletion.
3 changes: 3 additions & 0 deletions src/application.rs
Original file line number Diff line number Diff line change
Expand Up @@ -176,6 +176,8 @@ impl Application {

let queueview = ui::queue::QueueView::new(queue.clone(), library.clone());

let lyricsview = ui::lyrics::LyricsView::new(queue.clone());

#[cfg(feature = "cover")]
let coverview = ui::cover::CoverView::new(queue.clone(), library.clone(), &configuration);

Expand All @@ -185,6 +187,7 @@ impl Application {
ui::layout::Layout::new(status, &event_manager, theme, Arc::clone(&configuration))
.screen("search", search.with_name("search"))
.screen("library", libraryview.with_name("library"))
.screen("lyrics", lyricsview.with_name("lyrics"))
.screen("queue", queueview);

#[cfg(feature = "cover")]
Expand Down
2 changes: 1 addition & 1 deletion src/command.rs
Original file line number Diff line number Diff line change
Expand Up @@ -433,7 +433,7 @@ pub fn parse(input: &str) -> Result<Vec<Command>, CommandParseError> {
"focus" => {
let &target = args.first().ok_or(E::InsufficientArgs {
cmd: command.into(),
hint: Some("queue|search|library".into()),
hint: Some("queue|search|library|lyrics".into()), // TODO: these names should come from a "central" registrar for views so that contributors don't need to always keep updating it
})?;
// TODO: this really should be strongly typed
Command::Focus(target.into())
Expand Down
1 change: 1 addition & 0 deletions src/commands.rs
Original file line number Diff line number Diff line change
Expand Up @@ -473,6 +473,7 @@ impl CommandManager {
kb.insert("F1".into(), vec![Command::Focus("queue".into())]);
kb.insert("F2".into(), vec![Command::Focus("search".into())]);
kb.insert("F3".into(), vec![Command::Focus("library".into())]);
kb.insert("F4".into(), vec![Command::Focus("lyrics".into())]);
#[cfg(feature = "cover")]
kb.insert("F8".into(), vec![Command::Focus("cover".into())]);
kb.insert("?".into(), vec![Command::Help]);
Expand Down
Empty file added src/lyrics/mod.rs
Empty file.
71 changes: 71 additions & 0 deletions src/ui/lyrics.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
use std::sync::Arc;

use cursive::{
theme::Effect,
utils::markup::StyledString,
view::ViewWrapper,
views::{ScrollView, TextView},
};

use crate::{commands::CommandResult, queue::Queue, traits::ViewExt, command::Command};

pub struct LyricsView {
queue: Arc<Queue>,
view: ScrollView<TextView>,
}

impl LyricsView {
pub fn new(queue: Arc<Queue>) -> LyricsView {
let mut text = StyledString::styled("Keybindings\n\n", Effect::Bold);

let note = format!(
"Custom bindings can be set in the {} file within the [keybindings] section.\n\n",
"test"
);
text.append(StyledString::styled(note, Effect::Italic));

LyricsView {
queue,
view: ScrollView::new(TextView::new(text)),
}
}

pub fn save_lyrics(&mut self, lyrics: String) -> Result<CommandResult, String> {
// println!("Saving Lyrics: {}", lyrics);

self.view.get_inner_mut().set_content(lyrics);

Ok(CommandResult::Consumed(None))
}
}

impl ViewWrapper for LyricsView {
wrap_impl!(self.view: ScrollView<TextView>);
}

impl ViewExt for LyricsView {
fn title(&self) -> String {
"Lyrics".to_string()
}

fn title_sub(&self) -> String {
let current_track = self.queue.get_current().unwrap();

format!("{}", current_track)
}

fn on_leave(&self) {}

fn on_command(
&mut self,
_s: &mut cursive::Cursive,
cmd: &Command,
) -> Result<CommandResult, String> {
match cmd {
Command::Save => self.save_lyrics(format!("{}", cmd)),
Command::Quit => Ok(CommandResult::Ignored),
Command::Focus(_) => Ok(CommandResult::Ignored),
_ => Ok(CommandResult::Ignored)
}
}
}
1 change: 1 addition & 0 deletions src/ui/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ pub mod help;
pub mod layout;
pub mod library;
pub mod listview;
pub mod lyrics;
pub mod modal;
pub mod pagination;
pub mod playlist;
Expand Down

0 comments on commit 52455e4

Please sign in to comment.