added command_wrapper for various other dmenu styled tools

This commit is contained in:
Paul Wilde 2022-05-06 12:07:22 +01:00
parent 42a9b61a5b
commit 9639b17cbe
4 changed files with 68 additions and 21 deletions

View file

@ -5,16 +5,18 @@ about system status in dmenu. Some of them i.e. `volume` have options (up, down,
which are selectable options in dmenu. which are selectable options in dmenu.
## Tools ## Tools
- `pingclock` performs a single `ping` to a server and returns the response time - `pingclock` performs a single `ping` to a server and returns the response time
- `battery` shows the current battery level - `battery` shows the current battery level
- `brightness` shows the current backlight level and gives options to adjust it - `brightness` shows the current backlight level and gives options to adjust it
- `volume` shows the current volume level and gives options to adjust and manage it - `volume` shows the current volume level and gives options to adjust and manage it
- `date` shows the date - `date` shows the date
- `fuzzytime` shows the fuzzytime clock - `fuzzytime` shows the fuzzytime clock
- `wlan` shows the state of the wireless network interface. SSID connected to and signal level. - `wlan` shows the state of the wireless network interface. SSID connected to and signal level.
- `nic` shows the status and/or the ip address of the network interface card - `nic` shows the status and/or the ip address of the network interface card
- `temperature` shows the current CPU temperature - `temperature` shows the current CPU temperature
- `notes` a simple one liner note taking tool, displaying notes in dmenu/rofi - `notes` a simple one liner note taking tool, displaying notes in dmenu/rofi
- `passmenu_wrapper` a wrapper for passmenu. It basically just styles passmenu with no other features
- `command_wrapper` inspired by passmenu_wrapper, a basic tool to run other dmenu related tools with uniform styling
### Example in dmenu: ### Example in dmenu:

View file

@ -59,6 +59,9 @@ var loop* = false
var stoploop* = true var stoploop* = true
var dmenu* = true var dmenu* = true
var rofi* = false var rofi* = false
var passmenu* = false
var command_wrapper* = false
var run_command* = ""
proc newInfo*(title: string = "Info"): Info = proc newInfo*(title: string = "Info"): Info =
return Info( return Info(
@ -73,9 +76,9 @@ proc newInfo*(title: string = "Info"): Info =
color: foreground, color: foreground,
) )
proc newDmenuConfig(): Dmenu = proc newDmenuConfig(cmd: string = "dmenu"): Dmenu =
var dmenu = Dmenu() var dmenu = Dmenu()
dmenu.command = "dmenu" dmenu.command = cmd
dmenu.bottom = "-b" dmenu.bottom = "-b"
dmenu.grabkb = "-f" dmenu.grabkb = "-f"
dmenu.i_case = "-i" dmenu.i_case = "-i"
@ -97,6 +100,10 @@ proc newRofiConfig(): Dmenu =
proc newDmenu(): Dmenu = proc newDmenu(): Dmenu =
if rofi: if rofi:
return newRofiConfig() return newRofiConfig()
elif passmenu:
return newDmenuConfig("passmenu")
elif command_wrapper:
return newDmenuConfig(run_command)
return newDmenuConfig() return newDmenuConfig()
proc debugLog*(str: string) = proc debugLog*(str: string) =
@ -137,13 +144,7 @@ proc quote*(str: string): string =
return " \"" & text & "\" " return " \"" & text & "\" "
# ^ Add a spaces ^ so the previous flag isn't touching # ^ Add a spaces ^ so the previous flag isn't touching
proc getLines(num: int): int = proc genDmenuCmd*(data: Info, opts: varargs[string], rofi: bool = false): string =
if num > MAX_LINES:
return MAX_LINES
return num + 1
proc runDMenu*(data: Info, opts: varargs[string], rofi: bool = false): string =
# Build dmenu/rofi command # Build dmenu/rofi command
var cmd = "" var cmd = ""
# if the text is empty, we don't want to create a menu item of it # if the text is empty, we don't want to create a menu item of it
@ -157,14 +158,19 @@ proc runDMenu*(data: Info, opts: varargs[string], rofi: bool = false): string =
var dmenu = newDmenu() var dmenu = newDmenu()
cmd = cmd & dmenu.command & " " cmd = cmd & dmenu.command & " "
cmd = cmd & dmenu.lines_shown & " " & $20 & " " cmd = cmd & dmenu.lines_shown & " " & $MAX_LINES & " "
cmd = cmd & dmenu.prompt & quote(data.title) cmd = cmd & dmenu.prompt & quote(data.title)
cmd = cmd & dmenu.norm_bg & quote(data.unselected_bg) cmd = cmd & dmenu.norm_bg & quote(data.unselected_bg)
cmd = cmd & dmenu.norm_fg & quote(data.unselected_fg) cmd = cmd & dmenu.norm_fg & quote(data.unselected_fg)
cmd = cmd & dmenu.sel_bg & quote(data.selected_bg) cmd = cmd & dmenu.sel_bg & quote(data.selected_bg)
cmd = cmd & dmenu.sel_fg & quote(data.selected_fg) cmd = cmd & dmenu.sel_fg & quote(data.selected_fg)
cmd = cmd & dmenu.font & quote(font) cmd = cmd & dmenu.font & quote(font)
return cmd
proc runDMenu*(data: Info, opts: varargs[string], rofi: bool = false): string =
let cmd = genDmenuCmd(data, opts, rofi)
#echo cmd #echo cmd
# #
# Run command and get output # Run command and get output
@ -194,7 +200,8 @@ proc outputData*(data: Info, args: varargs[string]): string {.discardable.} =
# Switch bindsym mode back to default as it could be being used. # Switch bindsym mode back to default as it could be being used.
switchTwmMode() switchTwmMode()
for arg in getArguments(): let args* = getArguments()
for idx, arg in args:
case arg: case arg:
of "noloop": of "noloop":
stoploop = true stoploop = true
@ -209,5 +216,8 @@ for arg in getArguments():
of "rofi": of "rofi":
stoploop = true stoploop = true
rofi = true rofi = true
of ["pass","passmenu"]:
passmenu = true
break

22
command_wrapper.nim Normal file
View file

@ -0,0 +1,22 @@
import base
import std/[strutils,osproc]
# Basically just a wrapper to style passmenu nicely
proc main() =
var info = newInfo(capitalizeAscii(run_command))
let cmd = genDmenuCmd(info)
discard execCmd(cmd)
return
if isMainModule:
base.command_wrapper = true
for idx, arg in args:
case arg:
of "-r", "--run":
run_command = args[idx + 1]
else:
echo "No run tag given. Please run again with '--run _cmd_'"
break
if run_command != "":
main()

13
passmenu_wrapper.nim Normal file
View file

@ -0,0 +1,13 @@
import base
import std/osproc
# Basically just a wrapper to style passmenu nicely
proc main() =
var info = newInfo("Passmenu")
let cmd = genDmenuCmd(info)
discard execCmd(cmd)
return
if isMainModule:
passmenu = true
main()