From 0c03850eb5a2d0d3237b64df4ebd141119c7b88e Mon Sep 17 00:00:00 2001 From: Paul Wilde Date: Wed, 22 Nov 2023 21:42:13 +0000 Subject: [PATCH] batturry now working --- install.sh | 12 ++++++ src/common/colours.nim | 22 +++++++++++ src/dispatcher.nim | 3 ++ src/model/config.nim | 3 +- src/parser.nim | 6 +-- src/util/{batturry/src => }/batturry.nim | 47 ++++++++---------------- src/util/batturry/batturry.nimble | 13 ------- 7 files changed, 57 insertions(+), 49 deletions(-) create mode 100755 install.sh create mode 100644 src/common/colours.nim rename src/util/{batturry/src => }/batturry.nim (67%) delete mode 100644 src/util/batturry/batturry.nimble diff --git a/install.sh b/install.sh new file mode 100755 index 0000000..1948923 --- /dev/null +++ b/install.sh @@ -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 diff --git a/src/common/colours.nim b/src/common/colours.nim new file mode 100644 index 0000000..4ec5cda --- /dev/null +++ b/src/common/colours.nim @@ -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" diff --git a/src/dispatcher.nim b/src/dispatcher.nim index 1b2f2d5..c2e516d 100644 --- a/src/dispatcher.nim +++ b/src/dispatcher.nim @@ -2,6 +2,7 @@ import common import util/furrytime import util/pingclock +import util/batturry proc dispatch*(cfg: Config) = case cfg.run @@ -9,5 +10,7 @@ proc dispatch*(cfg: Config) = furrytime.go() of PingClock: pingclock.go() + of Batturry: + batturry.go() else: echo "No valid run command given" diff --git a/src/model/config.nim b/src/model/config.nim index 2cac241..00bbc91 100644 --- a/src/model/config.nim +++ b/src/model/config.nim @@ -10,7 +10,8 @@ type Tool* = enum None, FurryTime, - PingClock + PingClock, + Batturry let config_dir* = getHomeDir() & ".config/wm_tools/" let config_file* = config_dir & "config.toml" diff --git a/src/parser.nim b/src/parser.nim index ed2602e..2a70e43 100644 --- a/src/parser.nim +++ b/src/parser.nim @@ -8,9 +8,7 @@ proc parseArgs*() = let params = commandLineParams() var p = newParser: help("WMTools : a set of tools to output option to your program of choice i.e. Rofi") - arg("input") - flag("-l","--loop") - option("-r","--run") + arg("input",help="the tool to run, i.e. furrytime, pingclock, volurrme, etc.") try: var opts = p.parse(params) case opts.input @@ -18,6 +16,8 @@ proc parseArgs*() = myConfig.run = FurryTime of "pingclock", "pingclurrk", "ping": myConfig.run = PingClock + of "batturry", "battery", "bat": + myConfig.run = Batturry else: echo p.help quit(1) diff --git a/src/util/batturry/src/batturry.nim b/src/util/batturry.nim similarity index 67% rename from src/util/batturry/src/batturry.nim rename to src/util/batturry.nim index b9c0840..3962f76 100644 --- a/src/util/batturry/src/batturry.nim +++ b/src/util/batturry.nim @@ -1,5 +1,9 @@ -import ../../globurrl -import std/[strutils,os] +import strutils +import os + +import ../common +import ../common/colours +import ../output const battery = "BAT0" const ok_fg = lightgreen @@ -43,7 +47,7 @@ proc getCharge(): int = echo "Error getting battery level : " & getCurrentExceptionMsg() return charge -proc getDesign(charge: int, state: bool): (string, string, string, string, string) = +proc getDesign(charge: int, state: bool): string = var icon = " " var icon_colour = ok_fg var col = default_fg @@ -81,46 +85,25 @@ proc getDesign(charge: int, state: bool): (string, string, string, string, strin icon = "x " let main_text = icon & " " & $charge & "%" - # This next line is here for i3bar purposes - let html_text = "" & icon & "" & $charge & "%" - return (html_text,main_text, col, bg, border) + return main_text 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") + # TODO check if html text works with rofi 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 proc getBatteryInfo() = - var last_charge = -1 - var last_state = false - while true: - let charge = getCharge() - 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) + let charge = getCharge() + let state = isCharging() + let data = getoutput(charge, state) + outputData(data) -proc main() = +proc go*() = if batteryExists(): getBatteryInfo() - else: - switchTwmMode() -if isMainModule: - main() diff --git a/src/util/batturry/batturry.nimble b/src/util/batturry/batturry.nimble deleted file mode 100644 index ab08cdb..0000000 --- a/src/util/batturry/batturry.nimble +++ /dev/null @@ -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"