From 9ce1df6f655a8d3308a2a0d8690a05d6ed16b979 Mon Sep 17 00:00:00 2001 From: Paul Wilde Date: Sat, 14 May 2022 14:15:11 +0100 Subject: [PATCH] added argument parsing in volume and brightness for ease of binding to wm keys --- base.nim | 2 +- brightness.nim | 25 ++++++++++++++++++++----- compile_all.sh | 0 fuzzytime.nim | 0 volume.nim | 35 ++++++++++++++++++++++++++++------- 5 files changed, 49 insertions(+), 13 deletions(-) mode change 100755 => 100644 compile_all.sh mode change 100755 => 100644 fuzzytime.nim mode change 100755 => 100644 volume.nim diff --git a/base.nim b/base.nim index bd0b2ac..0b9e4b8 100644 --- a/base.nim +++ b/base.nim @@ -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" diff --git a/brightness.nim b/brightness.nim index 783115b..4286029 100644 --- a/brightness.nim +++ b/brightness.nim @@ -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() diff --git a/compile_all.sh b/compile_all.sh old mode 100755 new mode 100644 diff --git a/fuzzytime.nim b/fuzzytime.nim old mode 100755 new mode 100644 diff --git a/volume.nim b/volume.nim old mode 100755 new mode 100644 index fa68ae9..641d53e --- a/volume.nim +++ b/volume.nim @@ -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()