Fix styling according to CONTRIBUTING.md

This commit is contained in:
Nguyễn Gia Phong 2019-10-16 14:42:31 +07:00
parent ac86ebdb38
commit b9c424c768
22 changed files with 52 additions and 122 deletions

View File

@ -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:

View File

@ -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:

View File

@ -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 <vn.mcsinyx@gmail.com>
--
-- This file is part of Vicious.
--

View File

@ -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
-- }}}

View File

@ -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

View File

@ -1,5 +1,5 @@
-- template for asynchronous widet types
-- Copyright (C) 2019 Nguyễn Gia Phong
-- Copyright (C) 2019 Nguyễn Gia Phong <vn.mcsinyx@gmail.com>
--
-- This file is part of Vicious.
--

View File

@ -1,5 +1,5 @@
-- template for synchronous widet types
-- Copyright (C) 2019 Nguyễn Gia Phong
-- Copyright (C) 2019 Nguyễn Gia Phong <vn.mcsinyx@gmail.com>
--
-- This file is part of Vicious.
--

View File

@ -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)

View File

@ -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)

View File

@ -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)

View File

@ -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)

View File

@ -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)

View File

@ -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)

View File

@ -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)

View File

@ -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)

View File

@ -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)

View File

@ -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)

View File

@ -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)

View File

@ -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)

View File

@ -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)

View File

@ -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)

View File

@ -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)