added argument parsing in volume and brightness for ease of binding to wm keys

This commit is contained in:
Paul Wilde 2022-05-14 14:15:11 +01:00
parent 07cc6d48ad
commit 9ce1df6f65
5 changed files with 49 additions and 13 deletions

View file

@ -32,7 +32,7 @@ type
x*: int
y*: int
const font = "Hermit-10"
const font = "Hermit-12"
const background* = "#000000"
const backgroundalt* = "#bb222222"
const backgroundalt2* = "#bb333333"

View file

@ -37,6 +37,13 @@ proc getDesign(pcnt: float): string =
let text = icon & " " & $percent & "%"
return text
proc brightnessUp() =
let cmd = replace(backlight_up,"%v",default_value)
discard execCmd(cmd)
proc brightnessDown() =
let cmd = replace(backlight_down,"%v",default_value)
discard execCmd(cmd)
proc getBrightness*(run_once: bool = false) =
var last_pcnt: float = 0
while true:
@ -55,12 +62,10 @@ proc getBrightness*(run_once: bool = false) =
if option in args:
case option:
of "up":
let cmd = replace(backlight_up,"%v",default_value)
discard execCmd(cmd)
brightnessUp()
getBrightness(true)
of "down":
let cmd = replace(backlight_down,"%v",default_value)
discard execCmd(cmd)
brightnessDown()
getBrightness(true)
else:
try:
@ -85,4 +90,14 @@ proc main() =
getBrightness()
if isMainModule:
main()
block start:
for arg in args:
case arg:
of "up":
brightnessUp()
break start
of "down":
brightnessDown()
break start
main()

0
compile_all.sh Executable file → Normal file
View file

0
fuzzytime.nim Executable file → Normal file
View file

35
volume.nim Executable file → Normal file
View file

@ -1,5 +1,5 @@
import base
import std/[os,strutils,sequtils,osproc,math]
import std/[os,strutils,sequtils,osproc]
const audio_tools = @["ncpamixer", "pavucontrol"]
const vol_cmd = "pamixer"
@ -52,6 +52,17 @@ proc getCurrentVolume(): string =
let vol = execCmdEx(vol_get)
return vol.output
proc volumeUp() =
let cmd = replace(vol_up, "%v", vol_default_by)
discard execCmd(cmd)
proc volumeDown() =
let cmd = replace(vol_down, "%v", vol_default_by)
discard execCmd(cmd)
proc volumeMute() =
discard execCmd(vol_mute)
proc getVolume*(run_once: bool = false) =
let vol = getCurrentVolume()
let (text, main_text) = getDesign(vol)
@ -74,15 +85,13 @@ proc getVolume*(run_once: bool = false) =
return
case option:
of "up":
let cmd = replace(vol_up, "%v", vol_default_by)
discard execCmd(cmd)
volumeUp()
getVolume()
of "down":
let cmd = replace(vol_down, "%v", vol_default_by)
discard execCmd(cmd)
volumeDown()
getVolume()
of "mute":
discard execCmd(vol_mute)
volumeMute()
getVolume()
of "---":
getVolume()
@ -102,4 +111,16 @@ proc main() =
getVolume()
if isMainModule:
main()
block start:
for arg in args:
case arg:
of "up":
volumeUp()
break start
of "down":
volumeDown()
break start
of "mute":
volumeMute()
break start
main()