From 3f42e7aeb9658bd9f507fcbc6d1639596f4cbd3c Mon Sep 17 00:00:00 2001 From: Enric Morales Date: Tue, 12 Mar 2019 03:21:29 +0100 Subject: [PATCH] [bat_openbsd] Fix compatibility with Lua 5.3 and remaining time display (#78) Also remove duplicated environment --- widgets/bat_openbsd.lua | 17 ++++++----------- 1 file changed, 6 insertions(+), 11 deletions(-) diff --git a/widgets/bat_openbsd.lua b/widgets/bat_openbsd.lua index 15b7598..752a666 100644 --- a/widgets/bat_openbsd.lua +++ b/widgets/bat_openbsd.lua @@ -3,14 +3,9 @@ local setmetatable = setmetatable local tonumber = tonumber local string = { format = string.format, gmatch = string.gmatch } local io = { popen = io.popen } -local math = { floor = math.floor } -local helpers = require("vicious.helpers") -local string = { - gmatch = string.gmatch, - match = string.match, - format = string.format -} +local math = { floor = math.floor, modf = math.modf } -- }}} + local bat_openbsd = {} local function worker(format, warg) @@ -43,10 +38,10 @@ local function worker(format, warg) if tonumber(bat_info.power0) < 1 then time = "∞" else - local raw_time = bat_info.watthour3 / bat_info.power0 - local hours = math.floor(raw_time) - local minutes = raw_time % 1 - time = string.format("%d:%0.2d", hours, minutes) + local raw_time = bat_info.watthour3 / bat_info.power0 + local hours, hour_fraction = math.modf(raw_time) + local minutes = math.floor(60 * hour_fraction) + time = string.format("%d:%0.2d", hours, minutes) end -- calculate wear level from (last full / design) capacity