added batmon usage for battery output
This commit is contained in:
parent
6de0aff1dc
commit
2cff444a6b
2 changed files with 28 additions and 6 deletions
BIN
nimsuggest.core
Normal file
BIN
nimsuggest.core
Normal file
Binary file not shown.
|
@ -1,4 +1,6 @@
|
|||
import strutils
|
||||
import osproc
|
||||
import jsony
|
||||
|
||||
import ../common
|
||||
import ../common/colours
|
||||
|
@ -17,6 +19,14 @@ const alert_bg = yellow
|
|||
const med_fg = green
|
||||
#const med_bg = black
|
||||
|
||||
type
|
||||
Battery = object
|
||||
charge: float
|
||||
status: string
|
||||
charging: bool
|
||||
|
||||
proc postHook(b: var Battery) =
|
||||
b.charging = b.status == "Charging"
|
||||
|
||||
proc batteryExists(): bool =
|
||||
try:
|
||||
|
@ -36,17 +46,17 @@ proc isCharging(): bool =
|
|||
echo "Error getting charging status : " & getCurrentExceptionMsg()
|
||||
return false
|
||||
|
||||
proc getCharge(): int =
|
||||
var charge = 0
|
||||
proc getCharge(): float =
|
||||
var charge = 0.0
|
||||
try:
|
||||
let chg = strip(readFile("/sys/class/power_supply/" & battery & "/capacity"))
|
||||
if chg != "":
|
||||
charge = parseInt(chg)
|
||||
charge = parseFloat(chg)
|
||||
except:
|
||||
echo "Error getting battery level : " & getCurrentExceptionMsg()
|
||||
return charge
|
||||
|
||||
proc getDesign(charge: int, state: bool): string =
|
||||
proc getDesign(charge: float, state: bool): string =
|
||||
var icon = " "
|
||||
var icon_colour = ok_fg
|
||||
var col = default_fg
|
||||
|
@ -87,7 +97,7 @@ proc getDesign(charge: int, state: bool): string =
|
|||
|
||||
return main_text
|
||||
|
||||
proc getOutput(charge: int, state: bool): Info =
|
||||
proc getOutput(charge: float, state: bool): Info =
|
||||
let main_text = get_design(charge, state)
|
||||
var data = newInfo("Batturry")
|
||||
# TODO check if html text works with rofi
|
||||
|
@ -101,8 +111,20 @@ proc getBatteryInfo() =
|
|||
let data = getoutput(charge, state)
|
||||
outputData(data)
|
||||
|
||||
proc getBatteryInfoBSD() =
|
||||
try:
|
||||
let batmon = osproc.execCmdEx("batmon -o")
|
||||
if batmon.exitCode == 0:
|
||||
let bat = batmon.output.fromJson(Battery)
|
||||
let data = getOutput(bat.charge, bat.charging)
|
||||
outputData(data)
|
||||
except:
|
||||
echo getCurrentExceptionMsg()
|
||||
|
||||
proc go*() =
|
||||
if batteryExists():
|
||||
if hostOS == "freebsd":
|
||||
getBatteryInfoBSD();
|
||||
elif batteryExists():
|
||||
getBatteryInfo()
|
||||
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue