simplified regex in bat_freebsd

This commit is contained in:
mutlusun 2017-01-25 15:34:55 +01:00
parent fe0d762f11
commit 9b5f524176
3 changed files with 7 additions and 6 deletions

View File

@ -6,7 +6,7 @@ local math = { floor = math.floor }
local helpers = require("vicious.helpers") local helpers = require("vicious.helpers")
local string = { local string = {
gmatch = string.gmatch, gmatch = string.gmatch,
gsub = string.gsub, match = string.match,
format = string.format format = string.format
} }
@ -37,7 +37,7 @@ local function worker(format, warg)
end end
-- battery capacity in percent -- battery capacity in percent
local percent = tonumber(string.gsub(bat_info["Remaining capacity"], "[^%d]", ""), 10) local percent = tonumber(string.match(bat_info["Remaining capacity"], "[%d]+"))
-- use remaining (charging or discharging) time calculated by acpiconf -- use remaining (charging or discharging) time calculated by acpiconf
local time = bat_info["Remaining time"] local time = bat_info["Remaining time"]
@ -48,13 +48,13 @@ local function worker(format, warg)
-- calculate wear level from (last full / design) capacity -- calculate wear level from (last full / design) capacity
local wear = "N/A" local wear = "N/A"
if bat_info["Last full capacity"] and bat_info["Design capacity"] then if bat_info["Last full capacity"] and bat_info["Design capacity"] then
local l_full = tonumber(string.gsub(bat_info["Last full capacity"], "[^%d]", ""), 10) local l_full = tonumber(string.match(bat_info["Last full capacity"], "[%d]+"))
local design = tonumber(string.gsub(bat_info["Design capacity"], "[^%d]", ""), 10) local design = tonumber(string.match(bat_info["Design capacity"], "[%d]+"))
wear = math.floor(100 - (l_full / design * 100)) wear = math.floor(100 - (l_full / design * 100))
end end
-- dis-/charging rate as presented by battery -- dis-/charging rate as presented by battery
local rate = string.gsub(string.gsub(bat_info["Present rate"], ".*mA[^%d]+", ""), "[%s]+mW.*", "") local rate = string.match(bat_info["Present rate"], "([%d]+)%smW")
rate = string.format("%2.1f", tonumber(rate / 1000)) rate = string.format("%2.1f", tonumber(rate / 1000))
-- returns -- returns

View File

@ -3,6 +3,8 @@ local tonumber = tonumber
local os = { time = require("os").time } local os = { time = require("os").time }
local setmetatable = setmetatable local setmetatable = setmetatable
local helpers = require("vicious.helpers") local helpers = require("vicious.helpers")
local io = { popen = io.popen }
local string = { match = string.match }
-- }}} -- }}}

View File

@ -2,7 +2,6 @@
local setmetatable = setmetatable local setmetatable = setmetatable
local string = { match = string.match } local string = { match = string.match }
local helpers = require("vicious.helpers") local helpers = require("vicious.helpers")
local tonumber = tonumber
-- }}} -- }}}