mirror of
https://github.com/figsoda/mmtc
synced 2024-11-29 02:00:17 +00:00
feat(volume): Adding a volume widget in the UI
This commit is contained in:
parent
bf9a6e45c1
commit
ff7d5bcdf2
5 changed files with 48 additions and 24 deletions
|
@ -87,6 +87,7 @@ variant | struct, tuple or unit | fields (separated by comma) | description
|
|||
`Styled(styles, texts)` | tuple | list of [`Style`](#Style), [`Texts`](#Texts) | styled text
|
||||
`Parts(parts)` | tuple | list of [`Texts`](#Texts) | concatenate multiple parts of texts
|
||||
`If(condition, lhs, rhs)` or `If(condition, lhs)` | tuple | [`Condition`](#Condition), [`Texts`](#Texts), optional [`Texts`](#Texts) | if `condition` then `lhs` (else `rhs`)
|
||||
`CurrentVolume` | unit | | current volume level in %
|
||||
|
||||
### Style
|
||||
|
||||
|
@ -167,6 +168,7 @@ variant | struct, tuple or unit | fields (separated by comma) | description
|
|||
`And(lhs, rhs)` | tuple | [`Condition`](#Condition), [`Condition`](#Condition) | logical and
|
||||
`Or(lhs, rhs)` | tuple | [`Condition`](#Condition), [`Condition`](#Condition) | logical or
|
||||
`Xor(lhs, rhs)` | tuple | [`Condition`](#Condition), [`Condition`](#Condition) | logical exclusive or
|
||||
`VolumeMuted` | unit | | true if current volume is 0
|
||||
|
||||
### Column
|
||||
|
||||
|
|
56
mmtc.ron
56
mmtc.ron
|
@ -59,29 +59,43 @@ Config(
|
|||
Styled([Fg(Indexed(185))], Query),
|
||||
Styled([Fg(Indexed(185))], Text("⎸")),
|
||||
]),
|
||||
If(Not(Stopped), Parts([
|
||||
Styled([Fg(Indexed(113))], Parts([
|
||||
If(Playing, Text("[playing: "), Text("[paused: ")),
|
||||
CurrentElapsed,
|
||||
Text("/"),
|
||||
CurrentDuration,
|
||||
Text("] "),
|
||||
])),
|
||||
If(TitleExist,
|
||||
Parts([
|
||||
Styled([Fg(Indexed(149))], CurrentTitle),
|
||||
If(ArtistExist, Parts([
|
||||
Styled([Fg(Indexed(216))], Text(" ◆ ")),
|
||||
Styled([Fg(Indexed(185))], CurrentArtist),
|
||||
If(AlbumExist, Parts([
|
||||
Parts([
|
||||
Parts([
|
||||
Styled([Fg(Indexed(113))], Text("[")),
|
||||
If(VolumeMuted,
|
||||
Styled([Fg(Indexed(113))], Text("muted")),
|
||||
Parts([
|
||||
Styled([Fg(Indexed(113))], Text("vol: ")),
|
||||
Styled([Fg(Indexed(113))], CurrentVolume),
|
||||
Styled([Fg(Indexed(113))], Text("%")),
|
||||
]),
|
||||
),
|
||||
Styled([Fg(Indexed(113))], Text("]")),
|
||||
]),
|
||||
If(Not(Stopped), Parts([
|
||||
Styled([Fg(Indexed(113))], Parts([
|
||||
If(Playing, Text("[playing: "), Text("[paused: ")),
|
||||
CurrentElapsed,
|
||||
Text("/"),
|
||||
CurrentDuration,
|
||||
Text("] "),
|
||||
])),
|
||||
If(TitleExist,
|
||||
Parts([
|
||||
Styled([Fg(Indexed(149))], CurrentTitle),
|
||||
If(ArtistExist, Parts([
|
||||
Styled([Fg(Indexed(216))], Text(" ◆ ")),
|
||||
Styled([Fg(Indexed(221))], CurrentAlbum),
|
||||
Styled([Fg(Indexed(185))], CurrentArtist),
|
||||
If(AlbumExist, Parts([
|
||||
Styled([Fg(Indexed(216))], Text(" ◆ ")),
|
||||
Styled([Fg(Indexed(221))], CurrentAlbum),
|
||||
])),
|
||||
])),
|
||||
])),
|
||||
]),
|
||||
Styled([Fg(Indexed(185))], CurrentFile),
|
||||
),
|
||||
])),
|
||||
]),
|
||||
Styled([Fg(Indexed(185))], CurrentFile),
|
||||
),
|
||||
])),
|
||||
])
|
||||
)))),
|
||||
Fixed(7, TextboxR(Styled([Fg(Indexed(81))], Parts([
|
||||
Text("["),
|
||||
|
|
|
@ -80,6 +80,7 @@ pub enum Texts {
|
|||
Styled(Vec<AddStyle>, Box<Texts>),
|
||||
Parts(Vec<Texts>),
|
||||
If(Condition, Box<Texts>, Option<Box<Texts>>),
|
||||
CurrentVolume,
|
||||
}
|
||||
|
||||
#[derive(Deserialize)]
|
||||
|
@ -128,6 +129,7 @@ pub enum Condition {
|
|||
And(Box<Condition>, Box<Condition>),
|
||||
Or(Box<Condition>, Box<Condition>),
|
||||
Xor(Box<Condition>, Box<Condition>),
|
||||
VolumeMuted,
|
||||
}
|
||||
|
||||
#[derive(Deserialize)]
|
||||
|
@ -172,6 +174,7 @@ impl<'de> Deserialize<'de> for Texts {
|
|||
Styled,
|
||||
Parts,
|
||||
If,
|
||||
CurrentVolume,
|
||||
}
|
||||
|
||||
struct StyledVisitor;
|
||||
|
@ -245,6 +248,7 @@ impl<'de> Deserialize<'de> for Texts {
|
|||
Variant::Styled => va.tuple_variant(2, StyledVisitor),
|
||||
Variant::Parts => Ok(Texts::Parts(va.newtype_variant()?)),
|
||||
Variant::If => va.tuple_variant(3, IfVisitor),
|
||||
Variant::CurrentVolume => unit_variant!(CurrentVolume),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -432,6 +432,9 @@ fn _flatten<'a>(spans: &mut Vec<Span<'a>>, xs: &'a Texts, s: &FlattenState<'a, '
|
|||
_flatten(spans, xs, s);
|
||||
}
|
||||
}
|
||||
Texts::CurrentVolume => {
|
||||
spans.push(Span::styled(format!("{}", s.status.volume), *s.style));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -532,5 +535,6 @@ fn eval_cond(cond: &Condition, s: &ConditionState) -> bool {
|
|||
Condition::And(x, y) => eval_cond(x, s) && eval_cond(y, s),
|
||||
Condition::Or(x, y) => eval_cond(x, s) || eval_cond(y, s),
|
||||
Condition::Xor(x, y) => eval_cond(x, s) ^ eval_cond(y, s),
|
||||
Condition::VolumeMuted => s.status.volume == 0,
|
||||
}
|
||||
}
|
||||
|
|
|
@ -512,13 +512,13 @@ async fn run() -> Result<()> {
|
|||
cl.command(b"volume +1")
|
||||
.await
|
||||
.context("Failed to increase volume")?;
|
||||
0b100
|
||||
0b101
|
||||
}
|
||||
Command::VolumeDecrease => {
|
||||
cl.command(b"volume -1")
|
||||
.await
|
||||
.context("Failed to decrease volume")?;
|
||||
0b100
|
||||
0b101
|
||||
}
|
||||
Command::VolumeToggle => {
|
||||
let current_volume = s.status.volume;
|
||||
|
@ -533,7 +533,7 @@ async fn run() -> Result<()> {
|
|||
.context("Failed to mute/unmute volume")?;
|
||||
|
||||
last_volume = current_volume;
|
||||
0b100
|
||||
0b101
|
||||
}
|
||||
}) | updates.swap(0b000, Ordering::SeqCst)
|
||||
} else {
|
||||
|
|
Loading…
Reference in a new issue