batturry now working
This commit is contained in:
parent
c2b14eb8ef
commit
0c03850eb5
7 changed files with 57 additions and 49 deletions
12
install.sh
Executable file
12
install.sh
Executable 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
22
src/common/colours.nim
Normal 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"
|
|
@ -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"
|
||||
|
|
|
@ -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"
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -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 = "<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 =
|
||||
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()
|
||||
|
|
@ -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"
|
Loading…
Reference in a new issue