mirror of
https://github.com/figsoda/mmtc
synced 2024-11-22 15:13:03 +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)]
|
#[derive(Debug, Deserialize)]
|
||||||
pub enum Condition {
|
pub enum Condition {
|
||||||
Playing,
|
Playing,
|
||||||
|
Repeat,
|
||||||
|
Random,
|
||||||
|
Single,
|
||||||
|
Oneshot,
|
||||||
|
Consume,
|
||||||
TitleExist,
|
TitleExist,
|
||||||
ArtistExist,
|
ArtistExist,
|
||||||
AlbumExist,
|
AlbumExist,
|
||||||
|
|
|
@ -102,13 +102,12 @@ pub fn render(
|
||||||
}
|
}
|
||||||
Widget::Textbox(xss) => {
|
Widget::Textbox(xss) => {
|
||||||
let mut spans = Vec::new();
|
let mut spans = Vec::new();
|
||||||
let (current_elapsed, current_track) = if let Some(Song { pos, elapsed }) = status.song
|
let current_track = if let Some(Song { pos, .. }) = status.song {
|
||||||
{
|
queue.get(pos)
|
||||||
(Some(elapsed), queue.get(pos))
|
|
||||||
} else {
|
} 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);
|
frame.render_widget(Paragraph::new(Spans::from(spans)), size);
|
||||||
}
|
}
|
||||||
Widget::Queue { columns } => {
|
Widget::Queue { columns } => {
|
||||||
|
@ -125,11 +124,10 @@ pub fn render(
|
||||||
});
|
});
|
||||||
|
|
||||||
let len = columns.capacity();
|
let len = columns.capacity();
|
||||||
let (current_elapsed, current_track) = if let Some(Song { pos, elapsed }) = status.song
|
let current_track = if let Some(Song { pos, .. }) = status.song {
|
||||||
{
|
queue.get(pos)
|
||||||
(Some(elapsed), queue.get(pos))
|
|
||||||
} else {
|
} else {
|
||||||
(None, None)
|
None
|
||||||
};
|
};
|
||||||
for column in columns {
|
for column in columns {
|
||||||
match column {
|
match column {
|
||||||
|
@ -137,7 +135,7 @@ pub fn render(
|
||||||
let mut items = Vec::with_capacity(len);
|
let mut items = Vec::with_capacity(len);
|
||||||
for x in queue {
|
for x in queue {
|
||||||
let mut spans = Vec::new();
|
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)));
|
items.push(ListItem::new(Spans::from(spans)));
|
||||||
}
|
}
|
||||||
ws.push(List::new(items));
|
ws.push(List::new(items));
|
||||||
|
@ -147,7 +145,7 @@ pub fn render(
|
||||||
let mut items = Vec::with_capacity(len);
|
let mut items = Vec::with_capacity(len);
|
||||||
for x in queue {
|
for x in queue {
|
||||||
let mut spans = Vec::new();
|
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)));
|
items.push(ListItem::new(Spans::from(spans)));
|
||||||
}
|
}
|
||||||
ws.push(List::new(items));
|
ws.push(List::new(items));
|
||||||
|
@ -157,7 +155,7 @@ pub fn render(
|
||||||
let mut items = Vec::with_capacity(len);
|
let mut items = Vec::with_capacity(len);
|
||||||
for x in queue {
|
for x in queue {
|
||||||
let mut spans = Vec::new();
|
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)));
|
items.push(ListItem::new(Spans::from(spans)));
|
||||||
}
|
}
|
||||||
ws.push(List::new(items));
|
ws.push(List::new(items));
|
||||||
|
@ -183,7 +181,7 @@ pub fn render(
|
||||||
fn flatten(
|
fn flatten(
|
||||||
spans: &mut Vec<Span>,
|
spans: &mut Vec<Span>,
|
||||||
xs: &Texts,
|
xs: &Texts,
|
||||||
current_elapsed: Option<u16>,
|
status: &Status,
|
||||||
current_track: Option<&Track>,
|
current_track: Option<&Track>,
|
||||||
queue_track: Option<&Track>,
|
queue_track: Option<&Track>,
|
||||||
) {
|
) {
|
||||||
|
@ -191,11 +189,11 @@ fn flatten(
|
||||||
Texts::Empty => (),
|
Texts::Empty => (),
|
||||||
Texts::Plain(x) => spans.push(Span::raw(x.clone())),
|
Texts::Plain(x) => spans.push(Span::raw(x.clone())),
|
||||||
Texts::CurrentElapsed => {
|
Texts::CurrentElapsed => {
|
||||||
if let Some(current_elapsed) = current_elapsed {
|
if let Some(Song { elapsed, .. }) = status.song {
|
||||||
spans.push(Span::raw(format!(
|
spans.push(Span::raw(format!(
|
||||||
"{:02}:{:02}",
|
"{:02}:{:02}",
|
||||||
current_elapsed / 60,
|
elapsed / 60,
|
||||||
current_elapsed % 60
|
elapsed % 60
|
||||||
)))
|
)))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -271,12 +269,17 @@ fn flatten(
|
||||||
}
|
}
|
||||||
Texts::Parts(xss) => {
|
Texts::Parts(xss) => {
|
||||||
for xs in 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) => {
|
Texts::If(cond, box yes, box no) => {
|
||||||
let xs = if match cond {
|
let xs = if match cond {
|
||||||
Condition::Playing => current_track.is_some(),
|
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 => {
|
Condition::TitleExist => {
|
||||||
matches!(current_track, Some(Track { title: Some(_), .. }))
|
matches!(current_track, Some(Track { title: Some(_), .. }))
|
||||||
}
|
}
|
||||||
|
@ -292,7 +295,7 @@ fn flatten(
|
||||||
} else {
|
} else {
|
||||||
no
|
no
|
||||||
};
|
};
|
||||||
flatten(spans, xs, current_elapsed, current_track, queue_track);
|
flatten(spans, xs, status, current_track, queue_track);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue