mirror of
https://github.com/figsoda/mmtc
synced 2024-11-25 08:30:18 +00:00
add five conditions
repeat, random, single, oneshot, consume
This commit is contained in:
parent
85ba2e95b5
commit
d2b794e81f
2 changed files with 26 additions and 18 deletions
|
@ -63,6 +63,11 @@ pub enum Texts {
|
|||
#[derive(Debug, Deserialize)]
|
||||
pub enum Condition {
|
||||
Playing,
|
||||
Repeat,
|
||||
Random,
|
||||
Single,
|
||||
Oneshot,
|
||||
Consume,
|
||||
TitleExist,
|
||||
ArtistExist,
|
||||
AlbumExist,
|
||||
|
|
|
@ -102,13 +102,12 @@ pub fn render(
|
|||
}
|
||||
Widget::Textbox(xss) => {
|
||||
let mut spans = Vec::new();
|
||||
let (current_elapsed, current_track) = if let Some(Song { pos, elapsed }) = status.song
|
||||
{
|
||||
(Some(elapsed), queue.get(pos))
|
||||
let current_track = if let Some(Song { pos, .. }) = status.song {
|
||||
queue.get(pos)
|
||||
} else {
|
||||
(None, None)
|
||||
None
|
||||
};
|
||||
flatten(&mut spans, &xss, current_elapsed, current_track, None);
|
||||
flatten(&mut spans, &xss, status, current_track, None);
|
||||
frame.render_widget(Paragraph::new(Spans::from(spans)), size);
|
||||
}
|
||||
Widget::Queue { columns } => {
|
||||
|
@ -125,11 +124,10 @@ pub fn render(
|
|||
});
|
||||
|
||||
let len = columns.capacity();
|
||||
let (current_elapsed, current_track) = if let Some(Song { pos, elapsed }) = status.song
|
||||
{
|
||||
(Some(elapsed), queue.get(pos))
|
||||
let current_track = if let Some(Song { pos, .. }) = status.song {
|
||||
queue.get(pos)
|
||||
} else {
|
||||
(None, None)
|
||||
None
|
||||
};
|
||||
for column in columns {
|
||||
match column {
|
||||
|
@ -137,7 +135,7 @@ pub fn render(
|
|||
let mut items = Vec::with_capacity(len);
|
||||
for x in queue {
|
||||
let mut spans = Vec::new();
|
||||
flatten(&mut spans, xs, current_elapsed, current_track, Some(x));
|
||||
flatten(&mut spans, xs, status, current_track, Some(x));
|
||||
items.push(ListItem::new(Spans::from(spans)));
|
||||
}
|
||||
ws.push(List::new(items));
|
||||
|
@ -147,7 +145,7 @@ pub fn render(
|
|||
let mut items = Vec::with_capacity(len);
|
||||
for x in queue {
|
||||
let mut spans = Vec::new();
|
||||
flatten(&mut spans, xs, current_elapsed, current_track, Some(x));
|
||||
flatten(&mut spans, xs, status, current_track, Some(x));
|
||||
items.push(ListItem::new(Spans::from(spans)));
|
||||
}
|
||||
ws.push(List::new(items));
|
||||
|
@ -157,7 +155,7 @@ pub fn render(
|
|||
let mut items = Vec::with_capacity(len);
|
||||
for x in queue {
|
||||
let mut spans = Vec::new();
|
||||
flatten(&mut spans, xs, current_elapsed, current_track, Some(x));
|
||||
flatten(&mut spans, xs, status, current_track, Some(x));
|
||||
items.push(ListItem::new(Spans::from(spans)));
|
||||
}
|
||||
ws.push(List::new(items));
|
||||
|
@ -183,7 +181,7 @@ pub fn render(
|
|||
fn flatten(
|
||||
spans: &mut Vec<Span>,
|
||||
xs: &Texts,
|
||||
current_elapsed: Option<u16>,
|
||||
status: &Status,
|
||||
current_track: Option<&Track>,
|
||||
queue_track: Option<&Track>,
|
||||
) {
|
||||
|
@ -191,11 +189,11 @@ fn flatten(
|
|||
Texts::Empty => (),
|
||||
Texts::Plain(x) => spans.push(Span::raw(x.clone())),
|
||||
Texts::CurrentElapsed => {
|
||||
if let Some(current_elapsed) = current_elapsed {
|
||||
if let Some(Song { elapsed, .. }) = status.song {
|
||||
spans.push(Span::raw(format!(
|
||||
"{:02}:{:02}",
|
||||
current_elapsed / 60,
|
||||
current_elapsed % 60
|
||||
elapsed / 60,
|
||||
elapsed % 60
|
||||
)))
|
||||
}
|
||||
}
|
||||
|
@ -271,12 +269,17 @@ fn flatten(
|
|||
}
|
||||
Texts::Parts(xss) => {
|
||||
for xs in xss {
|
||||
flatten(spans, xs, current_elapsed, current_track, queue_track);
|
||||
flatten(spans, xs, status, current_track, queue_track);
|
||||
}
|
||||
}
|
||||
Texts::If(cond, box yes, box no) => {
|
||||
let xs = if match cond {
|
||||
Condition::Playing => current_track.is_some(),
|
||||
Condition::Repeat => status.repeat,
|
||||
Condition::Random => status.random,
|
||||
Condition::Single => status.single == Some(true),
|
||||
Condition::Oneshot => status.single == None,
|
||||
Condition::Consume => status.consume,
|
||||
Condition::TitleExist => {
|
||||
matches!(current_track, Some(Track { title: Some(_), .. }))
|
||||
}
|
||||
|
@ -292,7 +295,7 @@ fn flatten(
|
|||
} else {
|
||||
no
|
||||
};
|
||||
flatten(spans, xs, current_elapsed, current_track, queue_track);
|
||||
flatten(spans, xs, status, current_track, queue_track);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue