2020-10-30 16:20:37 +00:00
|
|
|
use tui::{
|
|
|
|
backend::Backend,
|
2020-11-01 19:56:46 +00:00
|
|
|
layout::{Alignment, Constraint, Direction, Layout, Rect},
|
2020-11-01 14:53:35 +00:00
|
|
|
style::{Modifier, Style},
|
2020-10-30 16:20:37 +00:00
|
|
|
text::{Span, Spans},
|
2020-10-31 19:19:45 +00:00
|
|
|
widgets::{List, ListItem, ListState, Paragraph},
|
2020-10-30 16:20:37 +00:00
|
|
|
Frame,
|
|
|
|
};
|
|
|
|
|
|
|
|
use crate::{
|
2020-11-01 19:29:39 +00:00
|
|
|
config::{AddStyle, Column, Condition, Constrained, Texts, Widget},
|
2020-10-30 16:20:37 +00:00
|
|
|
mpd::{Song, Status, Track},
|
|
|
|
};
|
|
|
|
|
|
|
|
pub fn render(
|
|
|
|
frame: &mut Frame<impl Backend>,
|
|
|
|
size: Rect,
|
|
|
|
widget: &Widget,
|
2020-11-02 23:45:49 +00:00
|
|
|
queue: &[Track],
|
2020-11-04 17:19:22 +00:00
|
|
|
searching: bool,
|
|
|
|
query: &str,
|
2020-11-04 21:19:27 +00:00
|
|
|
filtered: &[usize],
|
2020-10-30 16:20:37 +00:00
|
|
|
status: &Status,
|
2020-11-01 16:54:18 +00:00
|
|
|
liststate: &mut ListState,
|
2020-10-30 16:20:37 +00:00
|
|
|
) {
|
|
|
|
match widget {
|
|
|
|
Widget::Rows(xs) => {
|
|
|
|
let len = xs.capacity();
|
|
|
|
let mut ws = Vec::with_capacity(len);
|
|
|
|
let mut cs = Vec::with_capacity(len);
|
|
|
|
|
|
|
|
let denom = xs.iter().fold(0, |n, x| {
|
|
|
|
if let Constrained::Ratio(m, _) = x {
|
|
|
|
n + m
|
|
|
|
} else {
|
|
|
|
n
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
for x in xs {
|
2020-10-30 21:41:00 +00:00
|
|
|
let (w, constraint) = match x {
|
|
|
|
Constrained::Fixed(n, w) => (w, Constraint::Length(*n)),
|
2020-10-30 21:43:39 +00:00
|
|
|
Constrained::Max(n, w) => (w, Constraint::Max(*n)),
|
|
|
|
Constrained::Min(n, w) => (w, Constraint::Min(*n)),
|
2020-10-30 21:41:00 +00:00
|
|
|
Constrained::Ratio(n, w) => (w, Constraint::Ratio(*n, denom)),
|
|
|
|
};
|
|
|
|
ws.push(w);
|
|
|
|
cs.push(constraint);
|
2020-10-30 16:20:37 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
let layout = Layout::default()
|
|
|
|
.direction(Direction::Vertical)
|
|
|
|
.constraints(cs);
|
|
|
|
|
|
|
|
let mut chunks = layout.split(size).into_iter();
|
|
|
|
let mut ws = ws.into_iter();
|
|
|
|
|
|
|
|
while let (Some(chunk), Some(w)) = (chunks.next(), ws.next()) {
|
2020-11-04 17:19:22 +00:00
|
|
|
render(
|
|
|
|
frame, chunk, w, queue, searching, query, filtered, status, liststate,
|
|
|
|
);
|
2020-10-30 16:20:37 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
Widget::Columns(xs) => {
|
|
|
|
let len = xs.capacity();
|
|
|
|
let mut ws = Vec::with_capacity(len);
|
|
|
|
let mut cs = Vec::with_capacity(len);
|
|
|
|
|
|
|
|
let denom = xs.iter().fold(0, |n, x| {
|
|
|
|
if let Constrained::Ratio(m, _) = x {
|
|
|
|
n + m
|
|
|
|
} else {
|
|
|
|
n
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
for x in xs {
|
2020-10-30 21:41:00 +00:00
|
|
|
let (w, constraint) = match x {
|
|
|
|
Constrained::Fixed(n, w) => (w, Constraint::Length(*n)),
|
2020-10-30 21:43:39 +00:00
|
|
|
Constrained::Max(n, w) => (w, Constraint::Max(*n)),
|
|
|
|
Constrained::Min(n, w) => (w, Constraint::Min(*n)),
|
2020-10-30 21:41:00 +00:00
|
|
|
Constrained::Ratio(n, w) => (w, Constraint::Ratio(*n, denom)),
|
|
|
|
};
|
|
|
|
ws.push(w);
|
|
|
|
cs.push(constraint);
|
2020-10-30 16:20:37 +00:00
|
|
|
}
|
2020-10-30 21:41:00 +00:00
|
|
|
|
2020-10-30 16:20:37 +00:00
|
|
|
let layout = Layout::default()
|
|
|
|
.direction(Direction::Horizontal)
|
|
|
|
.constraints(cs);
|
|
|
|
|
|
|
|
let mut chunks = layout.split(size).into_iter();
|
|
|
|
let mut ws = ws.into_iter();
|
|
|
|
|
|
|
|
while let (Some(chunk), Some(w)) = (chunks.next(), ws.next()) {
|
2020-11-04 17:19:22 +00:00
|
|
|
render(
|
|
|
|
frame, chunk, w, queue, searching, query, filtered, status, liststate,
|
|
|
|
);
|
2020-10-30 16:20:37 +00:00
|
|
|
}
|
|
|
|
}
|
2020-11-01 19:58:15 +00:00
|
|
|
Widget::Textbox(xs) => {
|
2020-10-30 16:20:37 +00:00
|
|
|
let mut spans = Vec::new();
|
2020-10-31 22:06:10 +00:00
|
|
|
flatten(
|
|
|
|
&mut spans,
|
2020-11-01 19:58:15 +00:00
|
|
|
&xs,
|
2020-10-31 22:06:10 +00:00
|
|
|
status,
|
|
|
|
if let Some(Song { pos, .. }) = status.song {
|
|
|
|
queue.get(pos)
|
|
|
|
} else {
|
|
|
|
None
|
|
|
|
},
|
|
|
|
None,
|
|
|
|
false,
|
2020-11-03 13:11:41 +00:00
|
|
|
false,
|
2020-11-04 17:19:22 +00:00
|
|
|
searching,
|
|
|
|
query,
|
2020-10-31 22:06:10 +00:00
|
|
|
Style::default(),
|
|
|
|
);
|
2020-10-30 16:20:37 +00:00
|
|
|
frame.render_widget(Paragraph::new(Spans::from(spans)), size);
|
|
|
|
}
|
2020-11-01 19:58:15 +00:00
|
|
|
Widget::TextboxC(xs) => {
|
2020-11-01 19:56:46 +00:00
|
|
|
let mut spans = Vec::new();
|
|
|
|
flatten(
|
|
|
|
&mut spans,
|
2020-11-01 19:58:15 +00:00
|
|
|
&xs,
|
2020-11-01 19:56:46 +00:00
|
|
|
status,
|
|
|
|
if let Some(Song { pos, .. }) = status.song {
|
|
|
|
queue.get(pos)
|
|
|
|
} else {
|
|
|
|
None
|
|
|
|
},
|
|
|
|
None,
|
|
|
|
false,
|
2020-11-03 13:11:41 +00:00
|
|
|
false,
|
2020-11-04 17:19:22 +00:00
|
|
|
searching,
|
|
|
|
query,
|
2020-11-01 19:56:46 +00:00
|
|
|
Style::default(),
|
|
|
|
);
|
|
|
|
frame.render_widget(
|
|
|
|
Paragraph::new(Spans::from(spans)).alignment(Alignment::Center),
|
|
|
|
size,
|
|
|
|
);
|
|
|
|
}
|
2020-11-01 19:58:15 +00:00
|
|
|
Widget::TextboxR(xs) => {
|
2020-11-01 19:56:46 +00:00
|
|
|
let mut spans = Vec::new();
|
|
|
|
flatten(
|
|
|
|
&mut spans,
|
2020-11-01 19:58:15 +00:00
|
|
|
&xs,
|
2020-11-01 19:56:46 +00:00
|
|
|
status,
|
|
|
|
if let Some(Song { pos, .. }) = status.song {
|
|
|
|
queue.get(pos)
|
|
|
|
} else {
|
|
|
|
None
|
|
|
|
},
|
|
|
|
None,
|
|
|
|
false,
|
2020-11-03 13:11:41 +00:00
|
|
|
false,
|
2020-11-04 17:19:22 +00:00
|
|
|
searching,
|
|
|
|
query,
|
2020-11-01 19:56:46 +00:00
|
|
|
Style::default(),
|
|
|
|
);
|
|
|
|
frame.render_widget(
|
|
|
|
Paragraph::new(Spans::from(spans)).alignment(Alignment::Right),
|
|
|
|
size,
|
|
|
|
);
|
|
|
|
}
|
2020-11-01 19:29:39 +00:00
|
|
|
Widget::Queue(xs) => {
|
|
|
|
let len = xs.capacity();
|
2020-10-30 16:20:37 +00:00
|
|
|
let mut ws = Vec::with_capacity(len);
|
|
|
|
let mut cs = Vec::with_capacity(len);
|
|
|
|
|
2020-11-01 19:29:39 +00:00
|
|
|
let denom = xs.iter().fold(0, |n, Column { item, .. }| {
|
|
|
|
if let Constrained::Ratio(m, _) = item {
|
2020-10-30 16:20:37 +00:00
|
|
|
n + m
|
|
|
|
} else {
|
|
|
|
n
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2020-11-03 13:11:41 +00:00
|
|
|
let (pos, current_track) = if let Some(Song { pos, .. }) = status.song {
|
|
|
|
(Some(pos), queue.get(pos))
|
2020-10-30 16:20:37 +00:00
|
|
|
} else {
|
2020-11-03 13:11:41 +00:00
|
|
|
(None, None)
|
2020-10-30 16:20:37 +00:00
|
|
|
};
|
2020-10-30 21:41:00 +00:00
|
|
|
|
2020-11-01 19:29:39 +00:00
|
|
|
for column in xs {
|
2020-10-31 19:34:15 +00:00
|
|
|
let len = queue.len();
|
|
|
|
if len == 0 {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2020-11-01 19:29:39 +00:00
|
|
|
let (txts, constraint) = match &column.item {
|
|
|
|
Constrained::Fixed(n, txts) => (txts, Constraint::Length(*n)),
|
|
|
|
Constrained::Max(n, txts) => (txts, Constraint::Max(*n)),
|
|
|
|
Constrained::Min(n, txts) => (txts, Constraint::Min(*n)),
|
|
|
|
Constrained::Ratio(n, txts) => (txts, Constraint::Ratio(*n, denom)),
|
2020-10-30 21:41:00 +00:00
|
|
|
};
|
2020-10-31 19:19:45 +00:00
|
|
|
|
2020-10-30 21:41:00 +00:00
|
|
|
let mut items = Vec::with_capacity(len);
|
2020-11-04 21:19:27 +00:00
|
|
|
if query.is_empty() {
|
|
|
|
for (i, track) in queue.iter().enumerate() {
|
2020-11-04 17:19:22 +00:00
|
|
|
let mut spans = Vec::new();
|
|
|
|
flatten(
|
|
|
|
&mut spans,
|
|
|
|
txts,
|
|
|
|
status,
|
|
|
|
current_track,
|
2020-11-04 21:19:27 +00:00
|
|
|
Some(track),
|
|
|
|
pos == Some(i),
|
|
|
|
liststate.selected() == Some(i),
|
|
|
|
searching,
|
|
|
|
query,
|
|
|
|
Style::default(),
|
|
|
|
);
|
|
|
|
items.push(ListItem::new(Spans::from(spans)));
|
|
|
|
}
|
|
|
|
for (i, track) in queue.iter().enumerate() {
|
|
|
|
let mut spans = Vec::new();
|
|
|
|
flatten(
|
|
|
|
&mut spans,
|
|
|
|
txts,
|
|
|
|
status,
|
|
|
|
current_track,
|
|
|
|
Some(track),
|
2020-11-04 17:19:22 +00:00
|
|
|
pos == Some(i),
|
|
|
|
liststate.selected() == Some(i),
|
|
|
|
searching,
|
|
|
|
query,
|
|
|
|
Style::default(),
|
|
|
|
);
|
|
|
|
items.push(ListItem::new(Spans::from(spans)));
|
|
|
|
}
|
|
|
|
for (i, track) in queue.iter().enumerate() {
|
|
|
|
let mut spans = Vec::new();
|
|
|
|
flatten(
|
|
|
|
&mut spans,
|
|
|
|
txts,
|
|
|
|
status,
|
|
|
|
current_track,
|
|
|
|
Some(track),
|
|
|
|
pos == Some(i),
|
|
|
|
liststate.selected() == Some(i),
|
|
|
|
searching,
|
|
|
|
query,
|
|
|
|
Style::default(),
|
|
|
|
);
|
|
|
|
items.push(ListItem::new(Spans::from(spans)));
|
|
|
|
}
|
2020-11-04 21:19:27 +00:00
|
|
|
} else {
|
|
|
|
for &i in filtered {
|
|
|
|
let mut spans = Vec::new();
|
|
|
|
flatten(
|
|
|
|
&mut spans,
|
|
|
|
txts,
|
|
|
|
status,
|
|
|
|
current_track,
|
|
|
|
Some(&queue[i]),
|
|
|
|
pos == Some(i),
|
|
|
|
liststate.selected() == Some(i),
|
|
|
|
searching,
|
|
|
|
query,
|
|
|
|
Style::default(),
|
|
|
|
);
|
|
|
|
items.push(ListItem::new(Spans::from(spans)));
|
|
|
|
}
|
2020-10-30 16:20:37 +00:00
|
|
|
}
|
2020-11-01 19:29:39 +00:00
|
|
|
ws.push(
|
|
|
|
List::new(items)
|
|
|
|
.style(patch_style(Style::default(), &column.style))
|
|
|
|
.highlight_style(patch_style(Style::default(), &column.selected_style)),
|
|
|
|
);
|
2020-10-30 21:41:00 +00:00
|
|
|
cs.push(constraint);
|
2020-10-30 16:20:37 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
let layout = Layout::default()
|
|
|
|
.direction(Direction::Horizontal)
|
|
|
|
.constraints(cs);
|
|
|
|
|
|
|
|
let mut chunks = layout.split(size).into_iter();
|
|
|
|
let mut ws = ws.into_iter();
|
|
|
|
|
2020-11-01 16:54:18 +00:00
|
|
|
if let (Some(chunk), Some(w)) = (chunks.next(), ws.next()) {
|
|
|
|
frame.render_stateful_widget(w, chunk, liststate);
|
|
|
|
while let (Some(chunk), Some(w)) = (chunks.next(), ws.next()) {
|
|
|
|
frame.render_stateful_widget(w, chunk, &mut liststate.clone());
|
|
|
|
}
|
2020-10-30 16:20:37 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
fn flatten(
|
|
|
|
spans: &mut Vec<Span>,
|
|
|
|
xs: &Texts,
|
2020-10-30 21:07:22 +00:00
|
|
|
status: &Status,
|
2020-10-30 16:20:37 +00:00
|
|
|
current_track: Option<&Track>,
|
|
|
|
queue_track: Option<&Track>,
|
2020-11-03 13:11:41 +00:00
|
|
|
queue_current: bool,
|
2020-10-31 19:19:45 +00:00
|
|
|
selected: bool,
|
2020-11-04 17:19:22 +00:00
|
|
|
searching: bool,
|
|
|
|
query: &str,
|
2020-10-31 22:06:10 +00:00
|
|
|
style: Style,
|
2020-10-30 16:20:37 +00:00
|
|
|
) {
|
|
|
|
match xs {
|
2020-10-31 22:06:10 +00:00
|
|
|
Texts::Text(x) => spans.push(Span::styled(x.clone(), style)),
|
2020-10-30 20:27:25 +00:00
|
|
|
Texts::CurrentElapsed => {
|
2020-10-30 21:07:22 +00:00
|
|
|
if let Some(Song { elapsed, .. }) = status.song {
|
2020-10-31 22:06:10 +00:00
|
|
|
spans.push(Span::styled(
|
2020-11-03 12:36:42 +00:00
|
|
|
format!("{}:{:02}", elapsed / 60, elapsed % 60),
|
2020-10-31 22:06:10 +00:00
|
|
|
style,
|
2020-11-03 12:36:42 +00:00
|
|
|
));
|
2020-10-30 20:27:25 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
Texts::CurrentDuration => {
|
|
|
|
if let Some(Track { time, .. }) = current_track {
|
2020-10-31 22:06:10 +00:00
|
|
|
spans.push(Span::styled(
|
2020-11-03 12:36:42 +00:00
|
|
|
format!("{}:{:02}", time / 60, time % 60),
|
2020-10-31 22:06:10 +00:00
|
|
|
style,
|
2020-11-03 12:36:42 +00:00
|
|
|
));
|
2020-10-30 20:27:25 +00:00
|
|
|
}
|
|
|
|
}
|
2020-10-30 16:20:37 +00:00
|
|
|
Texts::CurrentFile => {
|
|
|
|
if let Some(Track { file, .. }) = current_track {
|
2020-10-31 22:06:10 +00:00
|
|
|
spans.push(Span::styled(file.clone(), style));
|
2020-10-30 16:20:37 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
Texts::CurrentTitle => {
|
|
|
|
if let Some(Track {
|
|
|
|
title: Some(title), ..
|
|
|
|
}) = current_track
|
|
|
|
{
|
2020-10-31 22:06:10 +00:00
|
|
|
spans.push(Span::styled(title.clone(), style));
|
2020-10-30 16:20:37 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
Texts::CurrentArtist => {
|
|
|
|
if let Some(Track {
|
|
|
|
artist: Some(artist),
|
|
|
|
..
|
|
|
|
}) = current_track
|
|
|
|
{
|
2020-10-31 22:06:10 +00:00
|
|
|
spans.push(Span::styled(artist.clone(), style));
|
2020-10-30 16:20:37 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
Texts::CurrentAlbum => {
|
|
|
|
if let Some(Track {
|
|
|
|
album: Some(album), ..
|
|
|
|
}) = current_track
|
|
|
|
{
|
2020-10-31 22:06:10 +00:00
|
|
|
spans.push(Span::styled(album.clone(), style));
|
2020-10-30 16:20:37 +00:00
|
|
|
}
|
|
|
|
}
|
2020-10-30 20:27:25 +00:00
|
|
|
Texts::QueueDuration => {
|
|
|
|
if let Some(Track { time, .. }) = queue_track {
|
2020-10-31 22:06:10 +00:00
|
|
|
spans.push(Span::styled(
|
2020-11-03 12:36:42 +00:00
|
|
|
format!("{}:{:02}", time / 60, time % 60),
|
2020-10-31 22:06:10 +00:00
|
|
|
style,
|
2020-11-03 12:36:42 +00:00
|
|
|
));
|
2020-10-30 20:27:25 +00:00
|
|
|
}
|
|
|
|
}
|
2020-10-30 16:20:37 +00:00
|
|
|
Texts::QueueFile => {
|
|
|
|
if let Some(Track { file, .. }) = current_track {
|
2020-10-31 22:06:10 +00:00
|
|
|
spans.push(Span::styled(file.clone(), style));
|
2020-10-30 16:20:37 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
Texts::QueueTitle => {
|
|
|
|
if let Some(Track {
|
|
|
|
title: Some(title), ..
|
|
|
|
}) = queue_track
|
|
|
|
{
|
2020-10-31 22:06:10 +00:00
|
|
|
spans.push(Span::styled(title.clone(), style));
|
2020-10-30 16:20:37 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
Texts::QueueArtist => {
|
|
|
|
if let Some(Track {
|
|
|
|
artist: Some(artist),
|
|
|
|
..
|
|
|
|
}) = queue_track
|
|
|
|
{
|
2020-10-31 22:06:10 +00:00
|
|
|
spans.push(Span::styled(artist.clone(), style));
|
2020-10-30 16:20:37 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
Texts::QueueAlbum => {
|
|
|
|
if let Some(Track {
|
|
|
|
album: Some(album), ..
|
|
|
|
}) = queue_track
|
|
|
|
{
|
2020-10-31 22:06:10 +00:00
|
|
|
spans.push(Span::styled(album.clone(), style));
|
2020-10-30 16:20:37 +00:00
|
|
|
}
|
|
|
|
}
|
2020-11-04 17:19:22 +00:00
|
|
|
Texts::Query => {
|
|
|
|
spans.push(Span::styled(String::from(query), style));
|
|
|
|
}
|
2020-10-31 22:06:10 +00:00
|
|
|
Texts::Styled(styles, box xs) => {
|
|
|
|
flatten(
|
|
|
|
spans,
|
|
|
|
xs,
|
|
|
|
status,
|
|
|
|
current_track,
|
|
|
|
queue_track,
|
2020-11-03 13:11:41 +00:00
|
|
|
queue_current,
|
2020-10-31 22:06:10 +00:00
|
|
|
selected,
|
2020-11-04 17:19:22 +00:00
|
|
|
searching,
|
|
|
|
query,
|
2020-11-01 19:29:39 +00:00
|
|
|
patch_style(style, styles),
|
2020-10-31 22:06:10 +00:00
|
|
|
);
|
|
|
|
}
|
2020-10-30 16:20:37 +00:00
|
|
|
Texts::Parts(xss) => {
|
|
|
|
for xs in xss {
|
2020-10-31 22:06:10 +00:00
|
|
|
flatten(
|
|
|
|
spans,
|
|
|
|
xs,
|
|
|
|
status,
|
|
|
|
current_track,
|
|
|
|
queue_track,
|
2020-11-03 13:11:41 +00:00
|
|
|
queue_current,
|
2020-10-31 22:06:10 +00:00
|
|
|
selected,
|
2020-11-04 17:19:22 +00:00
|
|
|
searching,
|
|
|
|
query,
|
2020-10-31 22:06:10 +00:00
|
|
|
style,
|
|
|
|
);
|
2020-10-30 16:20:37 +00:00
|
|
|
}
|
|
|
|
}
|
2020-10-31 20:53:49 +00:00
|
|
|
Texts::If(cond, box yes, Some(box no)) => {
|
2020-10-31 22:06:10 +00:00
|
|
|
flatten(
|
|
|
|
spans,
|
2020-11-04 17:19:22 +00:00
|
|
|
if eval_cond(
|
|
|
|
cond,
|
|
|
|
status,
|
|
|
|
current_track,
|
|
|
|
queue_current,
|
|
|
|
selected,
|
|
|
|
searching,
|
|
|
|
query,
|
|
|
|
) {
|
2020-10-31 22:06:10 +00:00
|
|
|
yes
|
|
|
|
} else {
|
|
|
|
no
|
|
|
|
},
|
|
|
|
status,
|
|
|
|
current_track,
|
|
|
|
queue_track,
|
2020-11-03 13:11:41 +00:00
|
|
|
queue_current,
|
2020-10-31 22:06:10 +00:00
|
|
|
selected,
|
2020-11-04 17:19:22 +00:00
|
|
|
searching,
|
|
|
|
query,
|
2020-10-31 22:06:10 +00:00
|
|
|
style,
|
|
|
|
);
|
2020-10-30 16:20:37 +00:00
|
|
|
}
|
2020-10-31 20:53:49 +00:00
|
|
|
Texts::If(cond, box xs, None) => {
|
2020-11-04 17:19:22 +00:00
|
|
|
if eval_cond(
|
|
|
|
cond,
|
|
|
|
status,
|
|
|
|
current_track,
|
|
|
|
queue_current,
|
|
|
|
selected,
|
|
|
|
searching,
|
|
|
|
query,
|
|
|
|
) {
|
2020-10-31 22:06:10 +00:00
|
|
|
flatten(
|
|
|
|
spans,
|
|
|
|
xs,
|
|
|
|
status,
|
|
|
|
current_track,
|
|
|
|
queue_track,
|
2020-11-03 13:11:41 +00:00
|
|
|
queue_current,
|
2020-10-31 22:06:10 +00:00
|
|
|
selected,
|
2020-11-04 17:19:22 +00:00
|
|
|
searching,
|
|
|
|
query,
|
2020-10-31 22:06:10 +00:00
|
|
|
style,
|
|
|
|
);
|
2020-10-31 20:53:49 +00:00
|
|
|
}
|
|
|
|
}
|
2020-10-30 16:20:37 +00:00
|
|
|
}
|
|
|
|
}
|
2020-11-01 21:39:32 +00:00
|
|
|
|
2020-11-02 23:45:49 +00:00
|
|
|
fn patch_style(style: Style, styles: &[AddStyle]) -> Style {
|
2020-11-01 19:29:39 +00:00
|
|
|
let mut style = style;
|
|
|
|
for add_style in styles {
|
|
|
|
match add_style {
|
|
|
|
AddStyle::Fg(color) => {
|
|
|
|
style.fg = Some(*color);
|
|
|
|
}
|
|
|
|
AddStyle::Bg(color) => {
|
|
|
|
style.bg = Some(*color);
|
|
|
|
}
|
|
|
|
AddStyle::Bold => {
|
|
|
|
style = style.add_modifier(Modifier::BOLD);
|
|
|
|
}
|
|
|
|
AddStyle::NoBold => {
|
|
|
|
style = style.remove_modifier(Modifier::BOLD);
|
|
|
|
}
|
|
|
|
AddStyle::Dim => {
|
|
|
|
style = style.add_modifier(Modifier::DIM);
|
|
|
|
}
|
|
|
|
AddStyle::NoDim => {
|
|
|
|
style = style.remove_modifier(Modifier::DIM);
|
|
|
|
}
|
|
|
|
AddStyle::Italic => {
|
|
|
|
style = style.add_modifier(Modifier::ITALIC);
|
|
|
|
}
|
|
|
|
AddStyle::NoItalic => {
|
|
|
|
style = style.remove_modifier(Modifier::ITALIC);
|
|
|
|
}
|
|
|
|
AddStyle::Underlined => {
|
|
|
|
style = style.add_modifier(Modifier::UNDERLINED);
|
|
|
|
}
|
|
|
|
AddStyle::NoUnderlined => {
|
|
|
|
style = style.remove_modifier(Modifier::UNDERLINED);
|
|
|
|
}
|
|
|
|
AddStyle::SlowBlink => {
|
|
|
|
style = style.add_modifier(Modifier::SLOW_BLINK);
|
|
|
|
}
|
|
|
|
AddStyle::NoSlowBlink => {
|
|
|
|
style = style.remove_modifier(Modifier::SLOW_BLINK);
|
|
|
|
}
|
|
|
|
AddStyle::RapidBlink => {
|
|
|
|
style = style.add_modifier(Modifier::RAPID_BLINK);
|
|
|
|
}
|
|
|
|
AddStyle::NoRapidBlink => {
|
|
|
|
style = style.remove_modifier(Modifier::RAPID_BLINK);
|
|
|
|
}
|
|
|
|
AddStyle::Reversed => {
|
|
|
|
style = style.add_modifier(Modifier::REVERSED);
|
|
|
|
}
|
|
|
|
AddStyle::NoReversed => {
|
|
|
|
style = style.remove_modifier(Modifier::REVERSED);
|
|
|
|
}
|
|
|
|
AddStyle::Hidden => {
|
|
|
|
style = style.add_modifier(Modifier::HIDDEN);
|
|
|
|
}
|
|
|
|
AddStyle::NoHidden => {
|
|
|
|
style = style.remove_modifier(Modifier::HIDDEN);
|
|
|
|
}
|
|
|
|
AddStyle::CrossedOut => {
|
|
|
|
style = style.add_modifier(Modifier::CROSSED_OUT);
|
|
|
|
}
|
|
|
|
AddStyle::NoCrossedOut => {
|
|
|
|
style = style.remove_modifier(Modifier::CROSSED_OUT);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
style
|
|
|
|
}
|
2020-10-31 17:33:51 +00:00
|
|
|
|
2020-10-31 19:19:45 +00:00
|
|
|
fn eval_cond(
|
|
|
|
cond: &Condition,
|
|
|
|
status: &Status,
|
|
|
|
current_track: Option<&Track>,
|
2020-11-03 13:11:41 +00:00
|
|
|
queue_current: bool,
|
2020-10-31 19:19:45 +00:00
|
|
|
selected: bool,
|
2020-11-04 17:19:22 +00:00
|
|
|
searching: bool,
|
|
|
|
query: &str,
|
2020-10-31 19:19:45 +00:00
|
|
|
) -> bool {
|
2020-10-31 17:33:51 +00:00
|
|
|
match cond {
|
|
|
|
Condition::Repeat => status.repeat,
|
|
|
|
Condition::Random => status.random,
|
|
|
|
Condition::Single => status.single == Some(true),
|
|
|
|
Condition::Oneshot => status.single == None,
|
|
|
|
Condition::Consume => status.consume,
|
2020-11-01 20:23:31 +00:00
|
|
|
Condition::Playing => status.state == Some(true),
|
|
|
|
Condition::Paused => status.state == Some(false),
|
|
|
|
Condition::Stopped => status.state == None,
|
2020-10-31 17:33:51 +00:00
|
|
|
Condition::TitleExist => matches!(current_track, Some(Track { title: Some(_), .. })),
|
|
|
|
Condition::ArtistExist => matches!(
|
|
|
|
current_track,
|
|
|
|
Some(Track {
|
|
|
|
artist: Some(_), ..
|
|
|
|
}),
|
|
|
|
),
|
|
|
|
Condition::AlbumExist => matches!(current_track, Some(Track { album: Some(_), .. })),
|
2020-11-03 13:11:41 +00:00
|
|
|
Condition::QueueCurrent => queue_current,
|
2020-10-31 19:19:45 +00:00
|
|
|
Condition::Selected => selected,
|
2020-11-04 17:19:22 +00:00
|
|
|
Condition::Searching => searching,
|
2020-11-04 19:22:19 +00:00
|
|
|
Condition::Filtered => !query.is_empty(),
|
2020-11-04 17:19:22 +00:00
|
|
|
Condition::Not(box x) => !eval_cond(
|
|
|
|
x,
|
|
|
|
status,
|
|
|
|
current_track,
|
|
|
|
queue_current,
|
|
|
|
selected,
|
|
|
|
searching,
|
|
|
|
query,
|
|
|
|
),
|
2020-10-31 17:33:51 +00:00
|
|
|
Condition::And(box x, box y) => {
|
2020-11-04 17:19:22 +00:00
|
|
|
eval_cond(
|
|
|
|
x,
|
|
|
|
status,
|
|
|
|
current_track,
|
|
|
|
queue_current,
|
|
|
|
selected,
|
|
|
|
searching,
|
|
|
|
query,
|
|
|
|
) && eval_cond(
|
|
|
|
y,
|
|
|
|
status,
|
|
|
|
current_track,
|
|
|
|
queue_current,
|
|
|
|
selected,
|
|
|
|
searching,
|
|
|
|
query,
|
|
|
|
)
|
2020-10-31 17:33:51 +00:00
|
|
|
}
|
|
|
|
Condition::Or(box x, box y) => {
|
2020-11-04 17:19:22 +00:00
|
|
|
eval_cond(
|
|
|
|
x,
|
|
|
|
status,
|
|
|
|
current_track,
|
|
|
|
queue_current,
|
|
|
|
selected,
|
|
|
|
searching,
|
|
|
|
query,
|
|
|
|
) || eval_cond(
|
|
|
|
y,
|
|
|
|
status,
|
|
|
|
current_track,
|
|
|
|
queue_current,
|
|
|
|
selected,
|
|
|
|
searching,
|
|
|
|
query,
|
|
|
|
)
|
2020-10-31 17:33:51 +00:00
|
|
|
}
|
|
|
|
Condition::Xor(box x, box y) => {
|
2020-11-04 17:19:22 +00:00
|
|
|
eval_cond(
|
|
|
|
x,
|
|
|
|
status,
|
|
|
|
current_track,
|
|
|
|
queue_current,
|
|
|
|
selected,
|
|
|
|
searching,
|
|
|
|
query,
|
|
|
|
) ^ eval_cond(
|
|
|
|
y,
|
|
|
|
status,
|
|
|
|
current_track,
|
|
|
|
queue_current,
|
|
|
|
selected,
|
|
|
|
searching,
|
|
|
|
query,
|
|
|
|
)
|
2020-10-31 17:33:51 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|