volurrme now working
This commit is contained in:
parent
0c03850eb5
commit
deb43144aa
7 changed files with 141 additions and 2 deletions
|
@ -1,8 +1,10 @@
|
|||
import model/config
|
||||
import model/info
|
||||
import model/extraargs
|
||||
|
||||
export config
|
||||
export info
|
||||
export extraargs
|
||||
|
||||
var myConfig* = newConfig()
|
||||
|
||||
|
|
|
@ -3,6 +3,7 @@ import common
|
|||
import util/furrytime
|
||||
import util/pingclock
|
||||
import util/batturry
|
||||
import util/volurrme
|
||||
|
||||
proc dispatch*(cfg: Config) =
|
||||
case cfg.run
|
||||
|
@ -12,5 +13,7 @@ proc dispatch*(cfg: Config) =
|
|||
pingclock.go()
|
||||
of Batturry:
|
||||
batturry.go()
|
||||
of Volurrme:
|
||||
volurrme.go()
|
||||
else:
|
||||
echo "No valid run command given"
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
import os
|
||||
import parsetoml
|
||||
import extraargs
|
||||
|
||||
type
|
||||
Config* = ref object
|
||||
|
@ -7,11 +8,13 @@ type
|
|||
run*: Tool
|
||||
max_lines*: int
|
||||
prepend*: bool
|
||||
extra_args*: seq[ExtraArg]
|
||||
Tool* = enum
|
||||
None,
|
||||
FurryTime,
|
||||
PingClock,
|
||||
Batturry
|
||||
Batturry,
|
||||
Volurrme
|
||||
|
||||
let config_dir* = getHomeDir() & ".config/wm_tools/"
|
||||
let config_file* = config_dir & "config.toml"
|
||||
|
|
4
src/model/extraargs.nim
Normal file
4
src/model/extraargs.nim
Normal file
|
@ -0,0 +1,4 @@
|
|||
|
||||
type
|
||||
ExtraArg* = enum
|
||||
None, VolUp, VolDown, VolMute
|
|
@ -9,6 +9,7 @@ proc parseArgs*() =
|
|||
var p = newParser:
|
||||
help("WMTools : a set of tools to output option to your program of choice i.e. Rofi")
|
||||
arg("input",help="the tool to run, i.e. furrytime, pingclock, volurrme, etc.")
|
||||
arg("adjust", help="(up, down, mute) allows to send extra commands. i.e. when run with volurrme, allows to adjust the volume")
|
||||
try:
|
||||
var opts = p.parse(params)
|
||||
case opts.input
|
||||
|
@ -18,9 +19,18 @@ proc parseArgs*() =
|
|||
myConfig.run = PingClock
|
||||
of "batturry", "battery", "bat":
|
||||
myConfig.run = Batturry
|
||||
of "volurrme", "volume", "vol":
|
||||
myConfig.run = Volurrme
|
||||
else:
|
||||
echo p.help
|
||||
quit(1)
|
||||
case opts.adjust
|
||||
of "volup":
|
||||
myConfig.extra_args.add(VolUp)
|
||||
of "voldown":
|
||||
myConfig.extra_args.add(VolDown)
|
||||
of "mute","volmute":
|
||||
myConfig.extra_args.add(VolMute)
|
||||
except ShortCircuit as err:
|
||||
if err.flag == "argparse_help":
|
||||
echo err.help
|
||||
|
|
|
@ -1,5 +1,4 @@
|
|||
import strutils
|
||||
import os
|
||||
|
||||
import ../common
|
||||
import ../common/colours
|
||||
|
|
118
src/util/volurrme.nim
Normal file
118
src/util/volurrme.nim
Normal file
|
@ -0,0 +1,118 @@
|
|||
import os
|
||||
import strutils
|
||||
import sequtils
|
||||
import osproc
|
||||
|
||||
import ../common
|
||||
import ../output
|
||||
|
||||
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"
|
||||
|
||||
|
||||
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 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 =
|
||||
let vol = checkVolume(volume)
|
||||
var icon = " "
|
||||
if vol == "muted":
|
||||
return 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 & "%"
|
||||
return main_text
|
||||
|
||||
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*() =
|
||||
let vol = getCurrentVolume()
|
||||
let main_text = getDesign(vol)
|
||||
var data = newInfo("Volurrme")
|
||||
data.full_text = main_text
|
||||
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)
|
||||
discard execCmd(cmd)
|
||||
getVolume()
|
||||
except:
|
||||
echo getCurrentExceptionMsg()
|
||||
getVolume()
|
||||
|
||||
proc go*() =
|
||||
block start:
|
||||
for arg in myConfig.extra_args:
|
||||
case arg
|
||||
of VolUp:
|
||||
volumeUp()
|
||||
break start
|
||||
of VolDown:
|
||||
volumeDown()
|
||||
break start
|
||||
of VolMute:
|
||||
volumeMute()
|
||||
break start
|
||||
else:
|
||||
continue
|
||||
getVolume()
|
Loading…
Reference in a new issue