From ae35c221fe7f42453a305242baaf99f0135da074 Mon Sep 17 00:00:00 2001 From: Paul Wilde Date: Wed, 22 Nov 2023 22:03:03 +0000 Subject: [PATCH] volurrme now working --- src/util/volurrme/src/volurrme.nim | 126 ----------------------------- src/util/volurrme/volurrme.nimble | 13 --- 2 files changed, 139 deletions(-) delete mode 100644 src/util/volurrme/src/volurrme.nim delete mode 100644 src/util/volurrme/volurrme.nimble diff --git a/src/util/volurrme/src/volurrme.nim b/src/util/volurrme/src/volurrme.nim deleted file mode 100644 index 6e842b7..0000000 --- a/src/util/volurrme/src/volurrme.nim +++ /dev/null @@ -1,126 +0,0 @@ -import ../../globurrl -import std/[os,strutils,sequtils,osproc] - -const audio_tools = @["ncpamixer", "pavucontrol"] -const vol_cmd = "pamixer" -const vol_up = vol_cmd & " -i %v" # where %v is amount by -const vol_down = vol_cmd & " -d %v" # where %v is amount by -const vol_set = vol_cmd & " --set-volume %v" # where %v is amount by -const vol_mute = vol_cmd & " -t" -const vol_default_by = "5" -const vol_get = vol_cmd & " --get-volume" -const vol_get_mute = vol_cmd & " --get-mute" -const default_bg = green -const default_fg = black - - -proc getCurrentVolume(): string {.gcsafe.} - -proc checkVolume(volume: string): string = - var vol = volume - if strip(vol) == "Connection error": - sleep(1000) - vol = getCurrentVolume() - vol = checkVolume(vol) - return vol - -proc getDesign(volume: string): (string,string) = - let vol = checkVolume(volume) - var icon = " " - if vol == "muted": - return (icon & "muted", icon & "muted") - let pcnt = parseInt(strip(vol)) - case pcnt: - of 85..100: - icon = " " - of 55..84: - icon = " " - of 35..54: - icon = " " - of 10..34: - icon = " " - else: - icon = " " - let main_text = icon & $pcnt & "%" - let text = "" & icon & "" & $pcnt & "%" - return (text, main_text) - -proc getCurrentVolume(): string = - let mute = execCmdEx(vol_get_mute) - if strip(mute.output) == "true": - return "muted" - 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) - var data = newInfo("Volurrme") - data.full_text = main_text - data.selected_bg = default_bg - data.selected_fg = default_fg - # i3bar stuff - data.html_text = text - data.color = foreground - data.border = green - data.background = black - let args = concat(@["up", "down", "mute", "---", "exit", "---"],audio_tools) - let option = outputData(data,args) - if option == "": - return - elif option in args: - if option in audio_tools: - discard(execCmd(option)) - return - case option: - of "up": - volumeUp() - getVolume() - of "down": - volumeDown() - getVolume() - of "mute": - volumeMute() - getVolume() - of "---": - getVolume() - of "exit": - return - else: - try: - let vol = parseInt(option) - let cmd = replace(vol_set, "%v", $vol) - let x = execCmd(cmd) - getVolume() - except: - echo getCurrentExceptionMsg() - getVolume() - -proc main() = - getVolume() - -if isMainModule: - block start: - for arg in args: - case arg: - of "up": - volumeUp() - break start - of "down": - volumeDown() - break start - of "mute": - volumeMute() - break start - main() diff --git a/src/util/volurrme/volurrme.nimble b/src/util/volurrme/volurrme.nimble deleted file mode 100644 index 382261e..0000000 --- a/src/util/volurrme/volurrme.nimble +++ /dev/null @@ -1,13 +0,0 @@ -# Package - -version = "0.1.0" -author = "Paul Wilde" -description = "Display and control volume with dmenu" -license = "GPL-3.0-or-later" -srcDir = "src" -bin = @["volurrme"] - - -# Dependencies - -requires "nim >= 1.6.6"