Add flag to output bare percentage
This commit is contained in:
parent
ad5eb2b935
commit
8af15ab62d
1 changed files with 19 additions and 6 deletions
25
src/main.rs
25
src/main.rs
|
@ -39,7 +39,11 @@ struct MuteArgs {}
|
|||
/// Get the current volume
|
||||
#[derive(Debug, Clone, Copy, PartialEq, FromArgs)]
|
||||
#[argh(subcommand, name = "get")]
|
||||
struct GetArgs {}
|
||||
struct GetArgs {
|
||||
/// output bare value
|
||||
#[argh(switch, short='b')]
|
||||
bare: bool,
|
||||
}
|
||||
|
||||
/// Set the volume
|
||||
#[derive(Debug, Clone, Copy, PartialEq, FromArgs)]
|
||||
|
@ -59,21 +63,30 @@ fn main() -> Result<(), Box<dyn Error>> {
|
|||
|
||||
let mut handler = SinkController::create()?;
|
||||
|
||||
let default_device = handler.get_default_device()?;
|
||||
let mut default_device = handler.get_default_device()?;
|
||||
let muted = default_device.mute;
|
||||
let volume_step = pulse::volume::Volume(pulse::volume::Volume::NORMAL.0 / 20);
|
||||
|
||||
match args.command {
|
||||
Subcommand::Up(_) => {
|
||||
handler.increase_device_volume_by_percent(default_device.index, 0.05);
|
||||
if default_device.volume.avg().0 < pulse::volume::Volume::NORMAL.0 {
|
||||
default_device.volume.inc_clamp(volume_step, pulse::volume::Volume::NORMAL);
|
||||
handler.set_device_volume_by_index(default_device.index, &default_device.volume);
|
||||
}
|
||||
}
|
||||
Subcommand::Down(_) => {
|
||||
handler.decrease_device_volume_by_percent(default_device.index, 0.05);
|
||||
default_device.volume.decrease(volume_step);
|
||||
handler.set_device_volume_by_index(default_device.index, &default_device.volume);
|
||||
}
|
||||
Subcommand::Mute(_) => {
|
||||
handler.set_device_mute_by_index(default_device.index, !muted);
|
||||
}
|
||||
Subcommand::Get(_) => {
|
||||
println!("Volume: {}", default_device.volume.avg());
|
||||
Subcommand::Get(GetArgs { bare }) => {
|
||||
if bare {
|
||||
print!("{}", ((default_device.volume.avg().0 as f64 / pulse::volume::Volume::NORMAL.0 as f64) * 100.0).round());
|
||||
} else {
|
||||
println!("Volume: {}", default_device.volume.avg());
|
||||
}
|
||||
return Ok(());
|
||||
}
|
||||
Subcommand::Set(SetArgs { volume }) => {
|
||||
|
|
Loading…
Reference in a new issue