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

View file

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