From b9c424c7681afb6da72cf357c9584a63612bbf79 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nguy=E1=BB=85n=20Gia=20Phong?= Date: Wed, 16 Oct 2019 14:42:31 +0700 Subject: [PATCH] Fix styling according to CONTRIBUTING.md --- Changes.md | 5 ++++- README.md | 8 ++++++++ headergen | 2 +- helpers.lua | 5 ++--- init.lua | 10 ++++++---- templates/async.lua | 2 +- templates/sync.lua | 2 +- widgets/bat_linux.lua | 10 ++-------- widgets/cpu_linux.lua | 10 ++-------- widgets/cpufreq_linux.lua | 10 ++-------- widgets/cpuinf_linux.lua | 10 ++-------- widgets/date_all.lua | 2 +- widgets/dio_linux.lua | 10 ++-------- widgets/mbox_all.lua | 9 ++------- widgets/mboxc_all.lua | 9 ++------- widgets/mem_linux.lua | 10 ++-------- widgets/net_linux.lua | 10 ++-------- widgets/org_all.lua | 10 ++-------- widgets/os_linux.lua | 10 ++-------- widgets/raid_linux.lua | 10 ++-------- widgets/thermal_linux.lua | 10 ++-------- widgets/uptime_linux.lua | 10 ++-------- 22 files changed, 52 insertions(+), 122 deletions(-) diff --git a/Changes.md b/Changes.md index de920ba..2bc2c67 100644 --- a/Changes.md +++ b/Changes.md @@ -1,4 +1,4 @@ -# Changes in 2.4.0 (WIP) +# Changes in 2.4.0 IMPORTANT: @@ -18,6 +18,9 @@ Added: as a stand-alone library. - `helpers.setcall` for registering functions as widget types. - `headergen` script for automatic generation of copyright notices. +- `templates` for the ease of adding new widget types. +- `CONTRIBUTING.md` which guide contributors through the steps + of filing an issue or submitting a patch. Fixed: diff --git a/README.md b/README.md index 320d584..edca0e3 100644 --- a/README.md +++ b/README.md @@ -864,6 +864,14 @@ mybattery:buttons(awful.util.table.join( * [My first awesome](https://awesomewm.org/doc/api/documentation/07-my-first-awesome.md.html) +## Contributing + +For details, see CONTRIBUTING.md. Vicious is licensed under GNU GPLv2+, +which require all code within the package to be released under +a compatible license. All contributors retain their copyright to their code, +so please make sure you add your name to the header of every file you touch. + + ## Authors Wicked was written by: diff --git a/headergen b/headergen index 8170cf5..fe3dd51 100755 --- a/headergen +++ b/headergen @@ -1,6 +1,6 @@ #!/usr/bin/env lua -- copyright header generator --- Copyright (C) 2019 Nguyễn Gia Phong +-- Copyright (C) 2019 Nguyễn Gia Phong -- -- This file is part of Vicious. -- diff --git a/helpers.lua b/helpers.lua index 9598a12..bbe6da1 100644 --- a/helpers.lua +++ b/helpers.lua @@ -123,9 +123,9 @@ end -- }}} -- {{{ Set widget type's __call metamethod to given worker function -function helpers.setcall(wtype, worker) +function helpers.setcall(worker) return setmetatable( - wtype, { __call = function(_, ...) return worker(...) end }) + {}, { __call = function(_, ...) return worker(...) end }) end -- }}} @@ -285,5 +285,4 @@ end -- }}} return helpers - -- }}} diff --git a/init.lua b/init.lua index 10a5865..e4f7568 100644 --- a/init.lua +++ b/init.lua @@ -35,7 +35,7 @@ local type = type local pairs = pairs local tonumber = tonumber -local timer = (type(timer) == 'table' and timer or require("gears.timer")) +local timer = type(timer) == "table" and timer or require("gears.timer") local os = { time = os.time } local table = { insert = table.insert, @@ -94,20 +94,22 @@ local function update(widget, reg, disablecache) return ret or data end + local function topercent(e) return tonumber(e) and tonumber(e) / 100 end + local function update_value(data) local fmtd_data = format_data(data) if widget.add_value ~= nil then if widget.get_stack ~= nil and widget:get_stack() then for idx, _ in ipairs(widget:get_stack_colors()) do if fmtd_data[idx] then - widget:add_value(tonumber(fmtd_data[idx]) and tonumber(fmtd_data[idx]/100), idx) + widget:add_value(topercent(fmtd_data[idx]), idx) end end else - widget:add_value(tonumber(fmtd_data) and tonumber(fmtd_data)/100) + widget:add_value(topercent(fmtd_data)) end elseif widget.set_value ~= nil then - widget:set_value(tonumber(fmtd_data) and tonumber(fmtd_data)/100) + widget:set_value(topercent(fmtd_data)) elseif widget.set_markup ~= nil then widget:set_markup(fmtd_data) else diff --git a/templates/async.lua b/templates/async.lua index ebc2308..d704071 100644 --- a/templates/async.lua +++ b/templates/async.lua @@ -1,5 +1,5 @@ -- template for asynchronous widet types --- Copyright (C) 2019 Nguyễn Gia Phong +-- Copyright (C) 2019 Nguyễn Gia Phong -- -- This file is part of Vicious. -- diff --git a/templates/sync.lua b/templates/sync.lua index 6b2b15f..4b49059 100644 --- a/templates/sync.lua +++ b/templates/sync.lua @@ -1,5 +1,5 @@ -- template for synchronous widet types --- Copyright (C) 2019 Nguyễn Gia Phong +-- Copyright (C) 2019 Nguyễn Gia Phong -- -- This file is part of Vicious. -- diff --git a/widgets/bat_linux.lua b/widgets/bat_linux.lua index 39352b4..186c6e8 100644 --- a/widgets/bat_linux.lua +++ b/widgets/bat_linux.lua @@ -31,12 +31,8 @@ local math = { local helpers = require"vicious.helpers" -- }}} --- Bat: provides state, charge, remaining time, and wear for a requested battery --- vicious.widgets.bat -local bat_linux = {} - -- {{{ Battery widget type -local function worker(format, warg) +return helpers.setcall(function (format, warg) if not warg then return end local battery = helpers.pathtotable("/sys/class/power_supply/"..warg) @@ -109,7 +105,5 @@ local function worker(format, warg) end return {state, percent, time, wear, curpower} -end +end) -- }}} - -return helpers.setcall(bat_linux, worker) diff --git a/widgets/cpu_linux.lua b/widgets/cpu_linux.lua index 3ac8734..c023400 100644 --- a/widgets/cpu_linux.lua +++ b/widgets/cpu_linux.lua @@ -32,17 +32,13 @@ local string = { local helpers = require"vicious.helpers" -- }}} --- Cpu: provides CPU usage for all available CPUs/cores --- vicious.widgets.cpu -local cpu_linux = {} - -- Initialize function tables local cpu_usage = {} local cpu_total = {} local cpu_active = {} -- {{{ CPU widget type -local function worker(format) +return helpers.setcall(function () local cpu_lines = {} -- Get CPU stats @@ -86,7 +82,5 @@ local function worker(format) end return cpu_usage -end +end) -- }}} - -return helpers.setcall(cpu_linux, worker) diff --git a/widgets/cpufreq_linux.lua b/widgets/cpufreq_linux.lua index b956bf3..f3877e4 100644 --- a/widgets/cpufreq_linux.lua +++ b/widgets/cpufreq_linux.lua @@ -22,10 +22,6 @@ local tonumber = tonumber local helpers = require("vicious.helpers") -- }}} --- Cpufreq: provides freq, voltage and governor info for a requested CPU --- vicious.widgets.cpufreq -local cpufreq_linux = {} - local GOVERNOR_STATE = { ["ondemand\n"] = "↯", ["powersave\n"] = "⌁", @@ -35,7 +31,7 @@ local GOVERNOR_STATE = { } -- {{{ CPU frequency widget type -local function worker(format, warg) +return helpers.setcall(function (format, warg) if not warg then return end local _cpufreq = helpers.pathtotable( @@ -68,7 +64,5 @@ local function worker(format, warg) governor = GOVERNOR_STATE[governor] or governor or "N/A" return {freqv.mhz, freqv.ghz, freqv.mv, freqv.v, governor} -end +end) -- }}} - -return helpers.setcall(cpufreq_linux, worker) diff --git a/widgets/cpuinf_linux.lua b/widgets/cpuinf_linux.lua index afb5ce2..0df845f 100644 --- a/widgets/cpuinf_linux.lua +++ b/widgets/cpuinf_linux.lua @@ -24,12 +24,8 @@ local string = { gmatch = string.gmatch } local helpers = require"vicious.helpers" -- }}} --- Cpuinf: provides speed and cache information for all available CPUs/cores --- vicious.widgets.cpuinf -local cpuinf_linux = {} - -- {{{ CPU Information widget type -local function worker(format) +return helpers.setcall(function () local id = nil local cpu_info = {} -- Get CPU info @@ -50,7 +46,5 @@ local function worker(format) end return cpu_info -end +end) -- }}} - -return helpers.setcall(cpuinf_linux, worker) diff --git a/widgets/date_all.lua b/widgets/date_all.lua index 0c29c80..459d505 100644 --- a/widgets/date_all.lua +++ b/widgets/date_all.lua @@ -24,6 +24,6 @@ local os = { date = os.date, time = os.time } local helpers = require"vicious.helpers" -- }}} -return helpers.setcall({}, function (format, warg) +return helpers.setcall(function (format, warg) return os.date(format or nil, warg and os.time()+warg or nil) end) diff --git a/widgets/dio_linux.lua b/widgets/dio_linux.lua index 25d2578..60c2343 100644 --- a/widgets/dio_linux.lua +++ b/widgets/dio_linux.lua @@ -26,10 +26,6 @@ local os = { time = os.time, difftime = os.difftime } local helpers = require"vicious.helpers" -- }}} --- Disk I/O: provides I/O statistics for requested storage devices --- vicious.widgets.dio -local dio_linux = {} - -- Initialize function tables local disk_usage = {} local disk_stats = {} @@ -39,7 +35,7 @@ local unit = { ["s"] = 1, ["kb"] = 2, ["mb"] = 2048 } local time_unit = { ["ms"] = 1, ["s"] = 1000 } -- {{{ Disk I/O widget type -local function worker(format) +return helpers.setcall(function () local disk_lines = {} for line in io.lines("/proc/diskstats") do @@ -79,7 +75,5 @@ local function worker(format) disk_stats = disk_lines return disk_usage -end +end) -- }}} - -return helpers.setcall(dio_linux, worker) diff --git a/widgets/mbox_all.lua b/widgets/mbox_all.lua index f5f9a6a..d65fac8 100644 --- a/widgets/mbox_all.lua +++ b/widgets/mbox_all.lua @@ -24,14 +24,11 @@ local io = { open = io.open } local helpers = require("vicious.helpers") -- }}} --- vicious.widgets.mbox -local mbox_all = {} - -- Initialize variables local subject = "N/A" -- {{{ Mailbox widget type -local function worker(format, warg) +return helpers.setcall(function (format, warg) if not warg then return end local f = io.open(type(warg) == "table" and warg[1] or warg) @@ -54,7 +51,5 @@ local function worker(format, warg) end return { subject } -end +end) -- }}} - -return helpers.setcall(mbox_all, worker) diff --git a/widgets/mboxc_all.lua b/widgets/mboxc_all.lua index f9e8b6a..ab33a0d 100644 --- a/widgets/mboxc_all.lua +++ b/widgets/mboxc_all.lua @@ -22,11 +22,8 @@ local io = { open = io.open } local helpers = require"vicious.helpers" -- }}} --- vicious.widgets.mboxc -local mboxc_all = {} - -- {{{ Mbox count widget type -local function worker(format, warg) +return helpers.setcall(function (format, warg) if not warg then return end -- Initialize counters @@ -62,7 +59,5 @@ local function worker(format, warg) count.new = count.total - count.old return {count.total, count.old, count.new} -end +end) -- }}} - -return helpers.setcall(mboxc_all, worker) diff --git a/widgets/mem_linux.lua b/widgets/mem_linux.lua index e49c106..318b51f 100644 --- a/widgets/mem_linux.lua +++ b/widgets/mem_linux.lua @@ -26,12 +26,8 @@ local string = { gmatch = string.gmatch } local helpers = require"vicious.helpers" -- }}} --- Mem: provides RAM and Swap usage statistics --- vicious.widgets.mem -local mem_linux = {} - -- {{{ Memory widget type -local function worker(format) +return helpers.setcall(function () local _mem = { buf = {}, swp = {} } -- Get MEM info @@ -60,7 +56,5 @@ local function worker(format) return {_mem.usep, _mem.inuse, _mem.total, _mem.free, _mem.swp.usep, _mem.swp.inuse, _mem.swp.t, _mem.swp.f, _mem.bcuse } -end +end) -- }}} - -return helpers.setcall(mem_linux, worker) diff --git a/widgets/net_linux.lua b/widgets/net_linux.lua index 5ee01d8..612da4d 100644 --- a/widgets/net_linux.lua +++ b/widgets/net_linux.lua @@ -26,10 +26,6 @@ local string = { match = string.match } local helpers = require("vicious.helpers") -- }}} --- Net: provides state and usage statistics of all network interfaces --- vicious.widgets.net -local net_linux = {} - -- Initialize function tables local nets = {} -- Variable definitions @@ -38,7 +34,7 @@ local unit = { ["b"] = 1, ["kb"] = 1024, } -- {{{ Net widget type -local function worker(format) +return helpers.setcall(function () local args = {} -- Get NET stats @@ -85,7 +81,5 @@ local function worker(format) end return args -end +end) -- }}} - -return helpers.setcall(net_linux, worker) diff --git a/widgets/org_all.lua b/widgets/org_all.lua index 44be341..b15fd16 100644 --- a/widgets/org_all.lua +++ b/widgets/org_all.lua @@ -24,12 +24,8 @@ local os = { time = os.time, date = os.date } local helpers = require"vicious.helpers" -- }}} --- Org: provides agenda statistics for Emacs org-mode --- vicious.widgets.org -local org_all = {} - -- {{{ OrgMode widget type -local function worker(format, warg) +return helpers.setcall(function (format, warg) if not warg then return end -- Compute delays @@ -65,7 +61,5 @@ local function worker(format, warg) end return { count.past, count.today, count.soon, count.future } -end +end) -- }}} - -return helpers.setcall(org_all, worker) diff --git a/widgets/os_linux.lua b/widgets/os_linux.lua index 08bba41..a1528e5 100644 --- a/widgets/os_linux.lua +++ b/widgets/os_linux.lua @@ -28,12 +28,8 @@ local string = { gsub = string.gsub } local helpers = require"vicious.helpers" -- }}} --- OS: provides operating system information --- vicious.widgets.os -local os_linux = {} - -- {{{ Operating system widget type -local function worker(format) +return helpers.setcall(function () local system = { ["ostype"] = "N/A", ["hostname"] = "N/A", @@ -66,7 +62,5 @@ local function worker(format) return {system["ostype"], system["osrelease"], system["username"], system["hostname"], system["entropy"], system["entropy_p"]} -end +end) -- }}} - -return helpers.setcall(os_linux, worker) diff --git a/widgets/raid_linux.lua b/widgets/raid_linux.lua index f88f29e..7b4d23f 100644 --- a/widgets/raid_linux.lua +++ b/widgets/raid_linux.lua @@ -29,15 +29,11 @@ local string = { local helpers = require"vicious.helpers" -- }}} --- Raid: provides state information for a requested RAID array --- vicious.widgets.raid -local raid_linux = {} - -- Initialize function tables local mddev = {} -- {{{ RAID widget type -local function worker(format, warg) +return helpers.setcall(function (format, warg) if not warg then return end mddev[warg] = { ["found"] = false, @@ -67,7 +63,5 @@ local function worker(format, warg) f:close() return {mddev[warg]["assigned"], mddev[warg]["active"]} -end +end) -- }}} - -return helpers.setcall(raid_linux, worker) diff --git a/widgets/thermal_linux.lua b/widgets/thermal_linux.lua index fc8ece9..7ac8e69 100644 --- a/widgets/thermal_linux.lua +++ b/widgets/thermal_linux.lua @@ -25,12 +25,8 @@ local math = { floor = math.floor } local helpers = require("vicious.helpers") -- }}} --- Thermal: provides temperature levels of ACPI and coretemp thermal zones --- vicious.widgets.thermal -local thermal_linux = {} - -- {{{ Thermal widget type -local function worker(format, warg) +return helpers.setcall(function (format, warg) if not warg then return end local zone = { -- Known temperature data sources @@ -54,7 +50,5 @@ local function worker(format, warg) end return {0} -end +end) -- }}} - -return helpers.setcall(thermal_linux, worker) diff --git a/widgets/uptime_linux.lua b/widgets/uptime_linux.lua index 1c340a6..7ff3580 100644 --- a/widgets/uptime_linux.lua +++ b/widgets/uptime_linux.lua @@ -24,12 +24,8 @@ local string = { match = string.match } local helpers = require("vicious.helpers") -- }}} --- Uptime: provides system uptime and load information --- vicious.widgets.uptime -local uptime_linux = {} - -- {{{ Uptime widget type -local function worker(format) +return helpers.setcall(function () local proc = helpers.pathtotable("/proc") -- Get system uptime @@ -41,7 +37,5 @@ local function worker(format) local l1, l5, l15 = -- Get load averages for past 1, 5 and 15 minutes string.match(proc.loadavg, "([%d%.]+)[%s]([%d%.]+)[%s]([%d%.]+)") return {up_d, up_h, up_m, l1, l5, l15} -end +end) -- }}} - -return helpers.setcall(uptime_linux, worker)