switched default to rofi
This commit is contained in:
parent
d7128e0540
commit
836cfab8d8
8 changed files with 72 additions and 50 deletions
103
base.nim
103
base.nim
|
@ -15,7 +15,7 @@ type
|
|||
html_text*: string
|
||||
short_text*: string
|
||||
args*: seq[string]
|
||||
Dmenu = object
|
||||
Menu = object
|
||||
command: string
|
||||
bottom: string
|
||||
grab_kb: string
|
||||
|
@ -28,12 +28,13 @@ type
|
|||
norm_fg: string
|
||||
sel_bg: string
|
||||
sel_fg: string
|
||||
extra_cmd: string
|
||||
i3BarInput* = object
|
||||
button*: int
|
||||
x*: int
|
||||
y*: int
|
||||
|
||||
const font = "Hermit-12"
|
||||
const font = "Hermit-8"
|
||||
const background* = "#000000"
|
||||
const backgroundalt* = "#bb222222"
|
||||
const backgroundalt2* = "#bb333333"
|
||||
|
@ -58,8 +59,8 @@ const alert* = "#bd2c40"
|
|||
const MAX_LINES = 20
|
||||
var loop* = false
|
||||
var stoploop* = true
|
||||
var dmenu* = true
|
||||
var rofi* = false
|
||||
var dmenu* = false
|
||||
var rofi* = true
|
||||
var passmenu* = false
|
||||
var command_wrapper* = false
|
||||
var run_command* = ""
|
||||
|
@ -80,35 +81,41 @@ proc newInfo*(str: string = "Info"): Info =
|
|||
color: foreground,
|
||||
)
|
||||
|
||||
proc newDmenuConfig(cmd: string = "dmenu"): Dmenu =
|
||||
var dmenu = Dmenu()
|
||||
dmenu.command = cmd
|
||||
dmenu.bottom = "-b"
|
||||
dmenu.grabkb = "-f"
|
||||
dmenu.i_case = "-i"
|
||||
dmenu.lines_shown = "-l"
|
||||
dmenu.monitor = "-m"
|
||||
dmenu.prompt = "-p"
|
||||
dmenu.font = "-fn"
|
||||
dmenu.norm_bg = "-nb"
|
||||
dmenu.norm_fg = "-nf"
|
||||
dmenu.sel_bg = "-sb"
|
||||
dmenu.sel_fg = "-sf"
|
||||
return dmenu
|
||||
proc newMenuConfig(cmd: string = "rofi -dmenu"): Menu =
|
||||
var menu = Menu()
|
||||
menu.command = cmd
|
||||
menu.prompt = "-p"
|
||||
menu.i_case = "-i"
|
||||
menu.lines_shown = "-l"
|
||||
return menu
|
||||
|
||||
proc newRofiConfig(): Dmenu =
|
||||
var rofi = newDmenuConfig()
|
||||
rofi.command = "rofi -dmenu"
|
||||
return rofi
|
||||
proc newRofiConfig(): Menu =
|
||||
var menu = newMenuConfig()
|
||||
menu.extra_cmd = "-markup-rows -kb-row-select \"Tab\" -kb-row-tab \"\""
|
||||
return menu
|
||||
|
||||
proc newDmenu(): Dmenu =
|
||||
proc newDmenuConfig(cmd: string = "dmenu"): Menu =
|
||||
var menu = newMenuConfig("dmenu")
|
||||
menu.bottom = "-b"
|
||||
menu.grabkb = "-f"
|
||||
menu.monitor = "-m"
|
||||
menu.font = "-fn"
|
||||
menu.norm_bg = "-nb"
|
||||
menu.norm_fg = "-nf"
|
||||
menu.sel_bg = "-sb"
|
||||
menu.sel_fg = "-sf"
|
||||
return menu
|
||||
|
||||
proc newMenu(): Menu =
|
||||
if rofi:
|
||||
return newRofiConfig()
|
||||
if dmenu:
|
||||
return newDmenuConfig()
|
||||
elif passmenu:
|
||||
return newDmenuConfig("passmenu")
|
||||
return newMenuConfig("passmenu")
|
||||
elif command_wrapper:
|
||||
return newDmenuConfig(run_command)
|
||||
return newDmenuConfig()
|
||||
return newMenuConfig(run_command)
|
||||
return newMenuConfig()
|
||||
|
||||
proc debugLog*(str: string) =
|
||||
let f = open("/tmp/debug.txt",fmAppend)
|
||||
|
@ -147,34 +154,44 @@ proc quote*(str: string): string =
|
|||
# Put leading and ending quote marks in
|
||||
return " \"" & text & "\" "
|
||||
# ^ Add a spaces ^ so the previous flag isn't touching
|
||||
#
|
||||
proc markup(str: string): string =
|
||||
var text = str
|
||||
|
||||
proc genDmenuCmd*(data: Info, opts: varargs[string], rofi: bool = false): string =
|
||||
return text
|
||||
|
||||
proc genMenuCmd*(data: Info, opts: varargs[string], rofi: bool = false): string =
|
||||
# Build dmenu/rofi command
|
||||
var cmd = ""
|
||||
# if the text is empty, we don't want to create a menu item of it
|
||||
if data.full_text != "":
|
||||
cmd &= data.full_text & "\n"
|
||||
let text = markup(data.full_text)
|
||||
cmd &= text & "\n"
|
||||
for opt in opts:
|
||||
cmd = cmd & opt & "\n"
|
||||
let text = markup(opt)
|
||||
cmd = cmd & text & "\n"
|
||||
cmd.removeSuffix("\n")
|
||||
|
||||
cmd = "echo -e" & quote(cmd) & " | "
|
||||
|
||||
var dmenu = newDmenu()
|
||||
cmd = cmd & dmenu.command & " "
|
||||
cmd = cmd & dmenu.lines_shown & " " & $MAX_LINES & " "
|
||||
cmd = cmd & dmenu.prompt & quote(data.title)
|
||||
cmd = cmd & dmenu.norm_bg & quote(data.unselected_bg)
|
||||
cmd = cmd & dmenu.norm_fg & quote(data.unselected_fg)
|
||||
cmd = cmd & dmenu.sel_bg & quote(data.selected_bg)
|
||||
cmd = cmd & dmenu.sel_fg & quote(data.selected_fg)
|
||||
cmd = cmd & dmenu.font & quote(font)
|
||||
var menu = newMenu()
|
||||
cmd = cmd & menu.command & " "
|
||||
cmd = cmd & menu.extra_cmd & " "
|
||||
cmd = cmd & menu.i_case & " "
|
||||
cmd = cmd & menu.lines_shown & " " & $MAX_LINES & " "
|
||||
cmd = cmd & menu.prompt & quote(data.title)
|
||||
cmd = cmd & menu.norm_bg & quote(data.unselected_bg)
|
||||
cmd = cmd & menu.norm_fg & quote(data.unselected_fg)
|
||||
cmd = cmd & menu.sel_bg & quote(data.selected_bg)
|
||||
cmd = cmd & menu.sel_fg & quote(data.selected_fg)
|
||||
cmd = cmd & menu.font & quote(font)
|
||||
echo cmd
|
||||
return cmd
|
||||
|
||||
|
||||
|
||||
proc runDMenu*(data: Info, opts: varargs[string], rofi: bool = false): string =
|
||||
let cmd = genDmenuCmd(data, opts, rofi)
|
||||
proc runMenu*(data: Info, opts: varargs[string], rofi: bool = false): string =
|
||||
let cmd = genMenuCmd(data, opts, rofi)
|
||||
#echo cmd
|
||||
#
|
||||
# Run command and get output
|
||||
|
@ -188,7 +205,7 @@ proc copyToClipboard*(str: string) =
|
|||
proc outputData*(data: Info, args: varargs[string]): string {.discardable.} =
|
||||
var output = ""
|
||||
if rofi:
|
||||
output = runDmenu(data,args, rofi = true)
|
||||
output = runMenu(data,args, rofi = true)
|
||||
elif loop:
|
||||
# mainly for i3bar/i3blocks compatible output
|
||||
var j_data = data
|
||||
|
@ -197,7 +214,7 @@ proc outputData*(data: Info, args: varargs[string]): string {.discardable.} =
|
|||
echo $$j_data
|
||||
else:
|
||||
# if all else fails, use dmenu (default)
|
||||
output = runDmenu(data,args)
|
||||
output = runMenu(data,args)
|
||||
return output
|
||||
|
||||
|
||||
|
|
|
@ -4,7 +4,7 @@ import std/[strutils,osproc]
|
|||
# Basically just a wrapper to style passmenu nicely
|
||||
proc main() =
|
||||
var info = newInfo(capitalizeAscii(run_command))
|
||||
let cmd = genDmenuCmd(info)
|
||||
let cmd = genMenuCmd(info)
|
||||
discard execCmd(cmd)
|
||||
return
|
||||
|
||||
|
|
9
compile_all.sh
Normal file → Executable file
9
compile_all.sh
Normal file → Executable file
|
@ -2,6 +2,11 @@
|
|||
|
||||
dont_compile="./base.nim"
|
||||
req_ssl=("./translate.nim" "./tides.nim")
|
||||
dependencies=("configparser")
|
||||
for d in "${dependencies[@]}"; do
|
||||
nimble install $d -n
|
||||
done
|
||||
|
||||
for f in ./*.nim; do
|
||||
if [[ $f == $dont_compile ]]; then
|
||||
echo "Not compiling $f"
|
||||
|
@ -12,7 +17,7 @@ for f in ./*.nim; do
|
|||
do
|
||||
if [[ $f == $i ]]; then
|
||||
echo "Compiling $f with SSL"
|
||||
nim c -d:ssl $f
|
||||
nim c -d:ssl -d:release $f
|
||||
compiled=1
|
||||
break
|
||||
fi
|
||||
|
@ -21,6 +26,6 @@ for f in ./*.nim; do
|
|||
continue
|
||||
else
|
||||
echo "Compiling $f"
|
||||
nim c $f
|
||||
nim c -d:release $f
|
||||
fi
|
||||
done
|
||||
|
|
0
fuzzytime.nim
Normal file → Executable file
0
fuzzytime.nim
Normal file → Executable file
6
nic.nim
6
nic.nim
|
@ -51,9 +51,9 @@ proc getNetInfo*(my_nics: seq[string]) =
|
|||
|
||||
proc getNics*(): seq[string] =
|
||||
var my_nics: seq[string] = @[]
|
||||
for nic in nics:
|
||||
if dirExists("/sys/class/net/" & nic):
|
||||
my_nics.add(nic)
|
||||
for nic in os.walkDir("/sys/class/net/"):
|
||||
let n = replace(nic.path, "/sys/class/net/", "")
|
||||
my_nics.add(n)
|
||||
|
||||
if len(my_nics) > 0:
|
||||
return my_nics
|
||||
|
|
|
@ -4,7 +4,7 @@ import std/osproc
|
|||
# Basically just a wrapper to style passmenu nicely
|
||||
proc main() =
|
||||
var info = newInfo("Passmenu")
|
||||
let cmd = genDmenuCmd(info)
|
||||
let cmd = genMenuCmd(info)
|
||||
discard execCmd(cmd)
|
||||
return
|
||||
|
||||
|
|
0
screenshot.nim
Executable file → Normal file
0
screenshot.nim
Executable file → Normal file
0
volume.nim
Normal file → Executable file
0
volume.nim
Normal file → Executable file
Loading…
Reference in a new issue