2022-04-28 21:58:40 +02:00
|
|
|
import base
|
2022-05-04 17:17:02 +02:00
|
|
|
import std/[os,osproc,strutils,sequtils]
|
2022-02-12 14:20:21 +01:00
|
|
|
|
2022-05-04 17:17:02 +02:00
|
|
|
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"
|
2022-02-12 14:20:21 +01:00
|
|
|
|
2022-05-04 17:17:02 +02:00
|
|
|
proc getSsid(): string =
|
|
|
|
let ssid = execCmdEx(get_ssid_cmd)
|
|
|
|
return strip(ssid.output)
|
2022-02-12 14:20:21 +01:00
|
|
|
|
2022-05-04 17:17:02 +02:00
|
|
|
proc getSignalQuality(): string =
|
2022-02-12 14:20:21 +01:00
|
|
|
let wl = readFile("/proc/net/wireless")
|
|
|
|
let ln = splitLines(wl)[2]
|
|
|
|
let links = split(ln," ")
|
|
|
|
var qual = strip(links[1])
|
|
|
|
qual = replace(qual,".","")
|
|
|
|
return "[" & qual & "]"
|
|
|
|
|
2022-05-04 17:17:02 +02:00
|
|
|
proc getWifi(nic: string): (string, string) =
|
|
|
|
let ssid = getSsid()
|
|
|
|
if ssid == "":
|
|
|
|
return ("disconnected", "disconnected")
|
|
|
|
let quality = getSignalQuality()
|
|
|
|
return (ssid, quality)
|
|
|
|
|
|
|
|
proc getObject(): Info =
|
|
|
|
var data = newInfo("WiFi")
|
2022-03-21 16:59:52 +01:00
|
|
|
data.border = purple
|
2022-05-04 17:17:02 +02:00
|
|
|
data.selected_bg = default_bg
|
|
|
|
data.selected_fg = default_fg
|
2022-02-12 14:20:21 +01:00
|
|
|
return data
|
|
|
|
|
2022-05-04 17:17:02 +02:00
|
|
|
proc getWifiInfo*(nics: seq[string]) =
|
|
|
|
var lst: seq[string] = @[]
|
|
|
|
for nic in nics:
|
|
|
|
let (essid, quality) = getWifi(nic)
|
|
|
|
lst.add(nic & ":" & quality & " " & essid)
|
|
|
|
let data = getObject()
|
|
|
|
let args = concat(lst,@["---", "manage","exit"])
|
|
|
|
let output = outputData(data, args)
|
|
|
|
case output:
|
|
|
|
of "manage":
|
|
|
|
discard execCmd(mng_cmd)
|
|
|
|
of "exit":
|
|
|
|
return
|
|
|
|
of "---":
|
|
|
|
return
|
2022-02-12 14:20:21 +01:00
|
|
|
|
|
|
|
proc main() =
|
2022-05-04 17:17:02 +02:00
|
|
|
var my_nics: seq[string] = @[]
|
|
|
|
for nic in wlan_nics:
|
|
|
|
if dirExists("/sys/class/net/" & nic):
|
|
|
|
my_nics.add(nic)
|
|
|
|
if len(my_nics) > 0:
|
|
|
|
getWifiInfo(my_nics)
|
2022-03-21 16:59:52 +01:00
|
|
|
else:
|
2022-05-04 17:17:02 +02:00
|
|
|
switchTwmMode()
|
2022-03-21 16:59:52 +01:00
|
|
|
echo "No WLAN"
|
2022-02-12 14:20:21 +01:00
|
|
|
|
2022-04-28 16:52:45 +02:00
|
|
|
if isMainModule:
|
|
|
|
main()
|