From e6a72669baaa45ede95e63b082830baac891852c Mon Sep 17 00:00:00 2001 From: Paul Wilde Date: Thu, 23 Nov 2023 19:40:20 +0000 Subject: [PATCH] added wirelurrs --- src/dispatcher.nim | 3 +++ src/model/tool.nim | 1 + src/parser.nim | 2 ++ src/util/cmd_wrappurr.nim | 22 ---------------------- src/util/wirelurrs.nim | 35 ++++++++++++++++++++--------------- 5 files changed, 26 insertions(+), 37 deletions(-) delete mode 100644 src/util/cmd_wrappurr.nim diff --git a/src/dispatcher.nim b/src/dispatcher.nim index 530038b..0704026 100644 --- a/src/dispatcher.nim +++ b/src/dispatcher.nim @@ -5,6 +5,7 @@ import util/pingclock import util/batturry import util/volurrme import util/netwurrk +import util/wirelurrs import util/emurrji import util/calendurr import util/remminurr @@ -27,6 +28,8 @@ proc dispatch*(cfg: Config) = volurrme.go() of Netwurrk: netwurrk.go() + of Wirelurrs: + wirelurrs.go() of Emurrji: emurrji.go() of Calendurr: diff --git a/src/model/tool.nim b/src/model/tool.nim index 7cb0002..fb8b2e1 100644 --- a/src/model/tool.nim +++ b/src/model/tool.nim @@ -7,6 +7,7 @@ type Batturry, Volurrme, Netwurrk, + Wirelurrs, Emurrji, Calendurr, Remminurr, diff --git a/src/parser.nim b/src/parser.nim index 6f21bc0..ea5e13e 100644 --- a/src/parser.nim +++ b/src/parser.nim @@ -27,6 +27,8 @@ proc parseArgs*() = myConfig.run = Volurrme of "netwurrk", "network", "net": myConfig.run = Netwurrk + of "wirelurrs", "wireless", "wifi": + myConfig.run = Wirelurrs of "emurrji", "emoji": myConfig.run = Emurrji of "calendurr", "calender", "cal": diff --git a/src/util/cmd_wrappurr.nim b/src/util/cmd_wrappurr.nim deleted file mode 100644 index 15855c1..0000000 --- a/src/util/cmd_wrappurr.nim +++ /dev/null @@ -1,22 +0,0 @@ -import ../../globurrl -import std/[strutils,osproc] - -# Basically just a wrapper to style passmenu nicely -proc main() = - var info = newInfo(capitalizeAscii(run_command)) - let cmd = genMenuCmd(info) - discard execCmd(cmd) - return - -if isMainModule: - globurrl.wrappurr = true - for idx, arg in args: - case arg: - of "-r", "--run": - run_command = args[idx + 1] - break - else: - echo "No command given, please run again with `[-r|--run] __cmd__`" - - if run_command != "": - main() diff --git a/src/util/wirelurrs.nim b/src/util/wirelurrs.nim index b5c748d..0408181 100644 --- a/src/util/wirelurrs.nim +++ b/src/util/wirelurrs.nim @@ -1,9 +1,11 @@ -import ../../globurrl -import std/[os,osproc,strutils,sequtils] +import os +import osproc +import strutils +import sequtils + +import ../common +import ../output -const default_bg = purple -const default_fg = white -const wlan_nics: seq[string] = @["wlan0"] const get_ssid_cmd = "iwgetid -r" const mng_cmd = "alacritty -e nmtui-connect" @@ -28,9 +30,6 @@ proc getWifi(nic: string): (string, string) = proc getObject(): Info = var data = newInfo("Wirelurrs") - data.border = purple - data.selected_bg = default_bg - data.selected_fg = default_fg return data proc getWifiInfo*(nics: seq[string]) = @@ -41,6 +40,8 @@ proc getWifiInfo*(nics: seq[string]) = let data = getObject() let args = concat(lst,@["---", "manage","exit"]) let output = outputData(data, args) + if output in lst: + discard execCmd(mng_cmd) case output: of "manage": discard execCmd(mng_cmd) @@ -49,16 +50,20 @@ proc getWifiInfo*(nics: seq[string]) = of "---": return -proc main() = +proc getWiFiNICs(): seq[string] = var my_nics: seq[string] = @[] - for nic in wlan_nics: - if dirExists("/sys/class/net/" & nic): + for path in walkDir("/sys/class/net/"): + if dirExists(path.path & "/wireless"): + let nic = path.path.replace("/sys/class/net/","") my_nics.add(nic) + return my_nics + +proc go*() = + let my_nics = getWiFiNICs() if len(my_nics) > 0: getWifiInfo(my_nics) else: - switchTwmMode() - echo "No WLAN" + var data = getObject() + data.full_text = "No WLAN" + discard outputData(data) -if isMainModule: - main()