batturry now working

This commit is contained in:
Paul Wilde 2023-11-22 21:42:13 +00:00
parent c2b14eb8ef
commit 0c03850eb5
7 changed files with 57 additions and 49 deletions

12
install.sh Executable file
View file

@ -0,0 +1,12 @@
#!/bin/bash
build () {
i="$1"
cd "./$dir" || exit
nimble install -y
if [[ $i == "install" ]]; then
cp -v "wmtools" "$HOME/.local/bin/wmtools"
fi
}
build $1

22
src/common/colours.nim Normal file
View file

@ -0,0 +1,22 @@
const background* = "#000000"
const backgroundalt* = "#bb222222"
const backgroundalt2* = "#bb333333"
const foreground* = "#dfdfdf"
const foregroundalt* = "#777"
const foregroundalt2* = "#ccc"
const black* = "#000000"
const white* = "#FFFFFF"
const yellow* = "#ffb52a"
const red* = "#e60053"
const purple* = "#9f78e1"
const blue* = "#0a6cf5"
const lightblue* = "#7296EF"
const lighterblue* = "#B5DDF7"
const green* = "#4b9901"
const lightgreen* = "#00ff00"
const grey* = "#dfdfdf"
const darkgrey* = "#444"
const primary* = yellow
const secondary* = red
const alert* = "#bd2c40"

View file

@ -2,6 +2,7 @@
import common import common
import util/furrytime import util/furrytime
import util/pingclock import util/pingclock
import util/batturry
proc dispatch*(cfg: Config) = proc dispatch*(cfg: Config) =
case cfg.run case cfg.run
@ -9,5 +10,7 @@ proc dispatch*(cfg: Config) =
furrytime.go() furrytime.go()
of PingClock: of PingClock:
pingclock.go() pingclock.go()
of Batturry:
batturry.go()
else: else:
echo "No valid run command given" echo "No valid run command given"

View file

@ -10,7 +10,8 @@ type
Tool* = enum Tool* = enum
None, None,
FurryTime, FurryTime,
PingClock PingClock,
Batturry
let config_dir* = getHomeDir() & ".config/wm_tools/" let config_dir* = getHomeDir() & ".config/wm_tools/"
let config_file* = config_dir & "config.toml" let config_file* = config_dir & "config.toml"

View file

@ -8,9 +8,7 @@ proc parseArgs*() =
let params = commandLineParams() let params = commandLineParams()
var p = newParser: var p = newParser:
help("WMTools : a set of tools to output option to your program of choice i.e. Rofi") help("WMTools : a set of tools to output option to your program of choice i.e. Rofi")
arg("input") arg("input",help="the tool to run, i.e. furrytime, pingclock, volurrme, etc.")
flag("-l","--loop")
option("-r","--run")
try: try:
var opts = p.parse(params) var opts = p.parse(params)
case opts.input case opts.input
@ -18,6 +16,8 @@ proc parseArgs*() =
myConfig.run = FurryTime myConfig.run = FurryTime
of "pingclock", "pingclurrk", "ping": of "pingclock", "pingclurrk", "ping":
myConfig.run = PingClock myConfig.run = PingClock
of "batturry", "battery", "bat":
myConfig.run = Batturry
else: else:
echo p.help echo p.help
quit(1) quit(1)

View file

@ -1,5 +1,9 @@
import ../../globurrl import strutils
import std/[strutils,os] import os
import ../common
import ../common/colours
import ../output
const battery = "BAT0" const battery = "BAT0"
const ok_fg = lightgreen const ok_fg = lightgreen
@ -43,7 +47,7 @@ proc getCharge(): int =
echo "Error getting battery level : " & getCurrentExceptionMsg() echo "Error getting battery level : " & getCurrentExceptionMsg()
return charge return charge
proc getDesign(charge: int, state: bool): (string, string, string, string, string) = proc getDesign(charge: int, state: bool): string =
var icon = "" var icon = ""
var icon_colour = ok_fg var icon_colour = ok_fg
var col = default_fg var col = default_fg
@ -81,46 +85,25 @@ proc getDesign(charge: int, state: bool): (string, string, string, string, strin
icon = "x " icon = "x "
let main_text = icon & " " & $charge & "%" let main_text = icon & " " & $charge & "%"
# This next line is here for i3bar purposes
let html_text = "<span foreground=\"" & icon_colour & "\">" & icon & "</span>" & $charge & "%"
return (html_text,main_text, col, bg, border) return main_text
proc getOutput(charge: int, state: bool): Info = proc getOutput(charge: int, state: bool): Info =
let (html_text,main_text,col,bg_col,highlight_col) = get_design(charge, state) let main_text = get_design(charge, state)
var data = newInfo("Batturry") var data = newInfo("Batturry")
# TODO check if html text works with rofi
data.full_text = main_text data.full_text = main_text
data.selected_bg = highlight_col
data.selected_fg = col # may just want `black` here
# i3bar stuff
data.html_text = html_text
data.color = col
data.border = highlight_col
data.background = bg_col
return data return data
proc getBatteryInfo() = proc getBatteryInfo() =
var last_charge = -1 let charge = getCharge()
var last_state = false let state = isCharging()
while true: let data = getoutput(charge, state)
let charge = getCharge() outputData(data)
let state = isCharging()
if charge != last_charge or state != last_state:
let data = getoutput(charge, state)
outputData(data)
last_charge = charge
last_state = state
if stoploop:
break
sleep(1000)
proc main() = proc go*() =
if batteryExists(): if batteryExists():
getBatteryInfo() getBatteryInfo()
else:
switchTwmMode()
if isMainModule:
main()

View file

@ -1,13 +0,0 @@
# Package
version = "0.1.0"
author = "Paul Wilde"
description = "Shows battery percentage using dmenu"
license = "MIT"
srcDir = "src"
bin = @["batturry"]
# Dependencies
requires "nim >= 1.6.6"