made brightnurrs work with freebsd
This commit is contained in:
parent
bebaaab101
commit
0c59629b17
2 changed files with 21 additions and 15 deletions
|
@ -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,18 +50,24 @@ 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)
|
||||
else:
|
||||
let limit = getLimit(backlight)
|
||||
let current = parseInt(strip(readFile("/sys/class/backlight/" & backlight & "/actual_brightness")))
|
||||
let pcnt = (current/limit)*100
|
||||
|
@ -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:
|
||||
|
|
|
@ -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"
|
||||
|
|
Loading…
Reference in a new issue