made brightnurrs work with freebsd

This commit is contained in:
Paul Wilde 2024-08-03 17:25:32 +01:00
parent bebaaab101
commit 0c59629b17
2 changed files with 21 additions and 15 deletions

View file

@ -2,20 +2,20 @@ import os
import strutils
import osproc
import math
import tables
import ../common
import ../parser
import ../model/brightness
import ../output
#const backlight = "intel_backlight"
const BACKLIGHT_CMD = "xbacklight"
const UP = BACKLIGHT_CMD & " -inc %v" # %v is amount by
const DOWN = BACKLIGHT_CMD & " -dec %v" # %v is amount by
const SET = BACKLIGHT_CMD & " -set %v" # %v is amount by
const UP: Table[string,string] = {"linux": "xbacklight -inc %v", "freebsd": "backlight incr %v"}.toTable # %v is amount by
const DOWN: Table[string,string] = {"linux": "xbacklight -dec %v", "freebsd": "backlight decr %v"}.toTable() # %v is amount by
const SET: Table[string,string] = {"linux": "xbacklight -set %v", "freebsd": "backlight %v"}.toTable() # %v is amount by
const default_value = "5"
proc getBacklight(): string =
if hostOS == "freebsd": return ""
for dir in walkDir("/sys/class/backlight"):
echo dir.path
var bl = dir.path.replace("/sys/class/backlight/","")
@ -50,23 +50,29 @@ proc getDesign(pcnt: float): string =
return text
proc brightnessUp() =
let cmd = replace(UP,"%v",default_value)
let cmd = replace(UP[hostOS],"%v",default_value)
discard execCmd(cmd)
proc brightnessDown() =
let cmd = replace(DOWN,"%v",default_value)
let cmd = replace(DOWN[hostOS],"%v",default_value)
discard execCmd(cmd)
proc getBrightness*(backlight: string) =
var data = newInfo("Brightnurrs")
if backlight == "":
if hostOS == "freebsd":
let bl = execCmdEx("backlight")
let pcnt = bl.output.replace("brightness: ","").strip.parseFloat
let text = getDesign(pcnt)
data.full_text = text
elif backlight == "":
data.full_text = "No Backlight Found"
discard outputData(data)
quit(1)
let limit = getLimit(backlight)
let current = parseInt(strip(readFile("/sys/class/backlight/" & backlight & "/actual_brightness")))
let pcnt = (current/limit)*100
let text = getDesign(pcnt)
data.full_text = text
else:
let limit = getLimit(backlight)
let current = parseInt(strip(readFile("/sys/class/backlight/" & backlight & "/actual_brightness")))
let pcnt = (current/limit)*100
let text = getDesign(pcnt)
data.full_text = text
let args = @["up", "down"]
let option = outputData(data,args)
if option in args:
@ -80,7 +86,7 @@ proc getBrightness*(backlight: string) =
else:
try:
let i = parseInt(option)
let cmd = replace(SET,"%v",$i)
let cmd = replace(SET[hostOS],"%v",$i)
discard execCmd(cmd)
backlight.getBrightness()
except:

View file

@ -1,6 +1,6 @@
# Package
version = "2.0.7"
version = "2.0.8"
author = "Paul Wilde"
description = "A set of informational tools"
license = "AGPL-3.0-or-later"