52 lines
1.1 KiB
Nim
52 lines
1.1 KiB
Nim
import std/os
|
|
import strutils
|
|
import std/osproc
|
|
import std/math
|
|
import i3bar_base
|
|
|
|
proc getLimit(): int
|
|
|
|
let limit = getLimit()
|
|
let args = getArguments()
|
|
|
|
proc getLimit(): int =
|
|
let limit = parseInt(strip(readFile("/sys/class/backlight/intel_backlight/max_brightness")))
|
|
return limit
|
|
|
|
proc getDesign(pcnt: float): string =
|
|
var icon = "🌑"
|
|
case pcnt:
|
|
of 85..100:
|
|
icon = "🌕"
|
|
of 75..85:
|
|
icon = "🌖"
|
|
of 50..75:
|
|
icon = "🌗"
|
|
of 35..50:
|
|
icon = "🌘"
|
|
else:
|
|
icon = "🌑"
|
|
let percent = toInt(round(pcnt,0))
|
|
let text = icon & " " & $percent & "%"
|
|
return text
|
|
|
|
proc getBrightness() =
|
|
let current = parseInt(strip(readFile("/sys/class/backlight/intel_backlight/actual_brightness")))
|
|
let pcnt = (current/limit)*100
|
|
let text = getDesign(pcnt)
|
|
let data = i3barData(
|
|
full_text: text,
|
|
color: foreground,
|
|
border: yellow
|
|
)
|
|
outputJSON(data)
|
|
|
|
proc main() =
|
|
if len(args) > 0:
|
|
if args[0] == "4":
|
|
discard execCmd("xbacklight -inc 5")
|
|
elif args[0] == "5":
|
|
discard execCmd("xbacklight -dec 5")
|
|
getBrightness()
|
|
|
|
main()
|