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 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,23 +50,29 @@ 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)
|
||||||
let limit = getLimit(backlight)
|
else:
|
||||||
let current = parseInt(strip(readFile("/sys/class/backlight/" & backlight & "/actual_brightness")))
|
let limit = getLimit(backlight)
|
||||||
let pcnt = (current/limit)*100
|
let current = parseInt(strip(readFile("/sys/class/backlight/" & backlight & "/actual_brightness")))
|
||||||
let text = getDesign(pcnt)
|
let pcnt = (current/limit)*100
|
||||||
data.full_text = text
|
let text = getDesign(pcnt)
|
||||||
|
data.full_text = text
|
||||||
let args = @["up", "down"]
|
let args = @["up", "down"]
|
||||||
let option = outputData(data,args)
|
let option = outputData(data,args)
|
||||||
if option in args:
|
if option in args:
|
||||||
|
@ -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:
|
||||||
|
|
|
@ -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"
|
||||||
|
|
Loading…
Reference in a new issue