From cd646e7914470289919e13b8f328df815f72ff63 Mon Sep 17 00:00:00 2001 From: figsoda Date: Mon, 5 Dec 2022 10:14:47 -0500 Subject: [PATCH] add QueueTitleExist, fix QueueFile --- mmtc.ron | 4 ++-- src/config.rs | 1 + src/defaults.rs | 12 ++++++++++-- src/layout.rs | 6 +++++- 4 files changed, 18 insertions(+), 5 deletions(-) diff --git a/mmtc.ron b/mmtc.ron index 10a9e05..f145988 100644 --- a/mmtc.ron +++ b/mmtc.ron @@ -21,8 +21,8 @@ Config( Min(0, Queue([ Column( item: Ratio(12, If(QueueCurrent, - Styled([Italic], QueueTitle), - QueueTitle, + Styled([Italic], If(QueueTitleExist, QueueTitle, QueueFile)), + If(QueueTitleExist, QueueTitle, QueueFile), )), style: [Fg(Indexed(75))], selected_style: [Fg(Black), Bg(Indexed(75)), Bold], diff --git a/src/config.rs b/src/config.rs index d32c794..66b05f2 100644 --- a/src/config.rs +++ b/src/config.rs @@ -119,6 +119,7 @@ pub enum Condition { TitleExist, ArtistExist, AlbumExist, + QueueTitleExist, QueueCurrent, Selected, Searching, diff --git a/src/defaults.rs b/src/defaults.rs index 5dde201..386b15d 100644 --- a/src/defaults.rs +++ b/src/defaults.rs @@ -87,9 +87,17 @@ pub fn layout() -> Widget { Condition::QueueCurrent, Box::new(Texts::Styled( vec![AddStyle::Italic], - Box::new(Texts::QueueTitle), + Box::new(Texts::If( + Condition::QueueTitleExist, + Box::new(Texts::QueueTitle), + Some(Box::new(Texts::QueueFile)), + )), )), - Some(Box::new(Texts::QueueTitle)), + Some(Box::new(Texts::If( + Condition::QueueTitleExist, + Box::new(Texts::QueueTitle), + Some(Box::new(Texts::QueueFile)), + ))), ), ), style: vec![AddStyle::Fg(Color::Indexed(75))], diff --git a/src/layout.rs b/src/layout.rs index a793359..316bd87 100644 --- a/src/layout.rs +++ b/src/layout.rs @@ -28,6 +28,7 @@ struct FlattenState<'a, 'b> { struct ConditionState<'a> { status: &'a Status, current_track: Option<&'a Track>, + queue_track: Option<&'a Track>, queue_current: bool, selected: bool, searching: bool, @@ -343,7 +344,7 @@ fn _flatten<'a>(spans: &mut Vec>, xs: &'a Texts, s: &FlattenState<'a, ' } } Texts::QueueFile => { - if let Some(Track { file, .. }) = s.current_track { + if let Some(Track { file, .. }) = s.queue_track { spans.push(Span::styled(file, *s.style)); } } @@ -398,6 +399,7 @@ fn _flatten<'a>(spans: &mut Vec>, xs: &'a Texts, s: &FlattenState<'a, ' &ConditionState { status: s.status, current_track: s.current_track, + queue_track: s.queue_track, queue_current: s.queue_current, selected: s.selected, searching: s.searching, @@ -417,6 +419,7 @@ fn _flatten<'a>(spans: &mut Vec>, xs: &'a Texts, s: &FlattenState<'a, ' &ConditionState { status: s.status, current_track: s.current_track, + queue_track: s.queue_track, queue_current: s.queue_current, selected: s.selected, searching: s.searching, @@ -517,6 +520,7 @@ fn eval_cond(cond: &Condition, s: &ConditionState) -> bool { }) ), Condition::AlbumExist => matches!(s.current_track, Some(Track { album: Some(_), .. })), + Condition::QueueTitleExist => matches!(s.queue_track, Some(Track { title: Some(_), .. })), Condition::QueueCurrent => s.queue_current, Condition::Selected => s.selected, Condition::Searching => s.searching,