From bea390a75eaea04a61f8962c6bac07b42ac0b22f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nguy=E1=BB=85n=20Gia=20Phong?= Date: Sat, 14 Sep 2019 10:33:40 +0700 Subject: [PATCH] Correct the copyright headers of the rest widget type --- Changes.md | 2 +- widgets/mbox_all.lua | 43 ++++++++++-------- widgets/mboxc_all.lua | 36 +++++++++------ widgets/mdir_all.lua | 28 ++++++++---- widgets/mem_freebsd.lua | 20 +++++++++ widgets/mem_linux.lua | 31 +++++++++---- widgets/mpd_all.lua | 27 +++++++++--- widgets/net_freebsd.lua | 19 ++++++++ widgets/net_linux.lua | 29 ++++++++---- widgets/org_all.lua | 81 +++++++++++++++++++--------------- widgets/os_bsd.lua | 23 +++++++--- widgets/os_linux.lua | 29 ++++++++---- widgets/pkg_all.lua | 26 ++++++++--- widgets/raid_linux.lua | 33 +++++++++----- widgets/thermal_freebsd.lua | 20 ++++++++- widgets/thermal_linux.lua | 29 ++++++++---- widgets/uptime_freebsd.lua | 21 ++++++++- widgets/uptime_linux.lua | 31 ++++++++----- widgets/volume_freebsd.lua | 21 ++++++++- widgets/volume_linux.lua | 25 ++++++++--- widgets/weather_all.lua | 88 +++++++++++++++++++++++-------------- widgets/wifi_linux.lua | 24 +++++++--- widgets/wifiiw_linux.lua | 25 ++++++++--- 23 files changed, 509 insertions(+), 202 deletions(-) diff --git a/Changes.md b/Changes.md index a027dd4..eef1e78 100644 --- a/Changes.md +++ b/Changes.md @@ -32,7 +32,7 @@ Fixed: - [pkg] Use more updated front-ends for Debian/Ubuntu (apt) and Fedora (dnf) - [os] Splitted os_all into os_linux and os_bsd (and refactored to async) - Tweak `.luacheckrc` to suit functional style and soft-limit text width to 80 -- Update copyright headers for libraries +- Update copyright headers for libraries and official widget types Removed: diff --git a/widgets/mbox_all.lua b/widgets/mbox_all.lua index 23ff475..f5f9a6a 100644 --- a/widgets/mbox_all.lua +++ b/widgets/mbox_all.lua @@ -1,22 +1,32 @@ ---------------------------------------------------- --- Licensed under the GNU General Public License v2 --- * (c) 2010, Adrian C. ---------------------------------------------------- +-- widget type providing the subject of last e-mail in a mbox file +-- Copyright (C) 2010 Adrian C. +-- Copyright (C) 2017 mutlusun +-- Copyright (C) 2018 Nguyễn Gia Phong +-- +-- This file is part of Vicious. +-- +-- Vicious is free software: you can redistribute it and/or modify +-- it under the terms of the GNU General Public License as +-- published by the Free Software Foundation, either version 2 of the +-- License, or (at your option) any later version. +-- +-- Vicious is distributed in the hope that it will be useful, +-- but WITHOUT ANY WARRANTY; without even the implied warranty of +-- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +-- GNU General Public License for more details. +-- +-- You should have received a copy of the GNU General Public License +-- along with Vicious. If not, see . -- {{{ Grab environment local type = type local io = { open = io.open } -local setmetatable = setmetatable -local string = { gfind = string.gfind } local helpers = require("vicious.helpers") -- }}} - --- Mbox: provides the subject of last e-mail in a mbox file -- vicious.widgets.mbox local mbox_all = {} - -- Initialize variables local subject = "N/A" @@ -24,18 +34,15 @@ local subject = "N/A" local function worker(format, warg) if not warg then return end - -- mbox could be huge, get a 30kb chunk from EOF - if type(warg) ~= "table" then _mbox = warg end - -- * attachment could be much bigger than 30kb - local f = io.open(_mbox or warg[1]) + local f = io.open(type(warg) == "table" and warg[1] or warg) f:seek("end", -30720) + -- mbox could be huge, get a 30kb chunk from EOF + -- * attachment could be much bigger than 30kb local txt = f:read("*all") f:close() -- Find all Subject lines - for i in string.gfind(txt, "Subject: ([^\n]*)") do - subject = i - end + for i in txt:gmatch"Subject: ([^\n]*)" do subject = i end -- Check if we should scroll, or maybe truncate if type(warg) == "table" then @@ -46,8 +53,8 @@ local function worker(format, warg) end end - return {subject} + return { subject } end -- }}} -return setmetatable(mbox_all, { __call = function(_, ...) return worker(...) end }) +return helpers.setcall(mbox_all, worker) diff --git a/widgets/mboxc_all.lua b/widgets/mboxc_all.lua index 8743ebb..f9e8b6a 100644 --- a/widgets/mboxc_all.lua +++ b/widgets/mboxc_all.lua @@ -1,20 +1,30 @@ ---------------------------------------------------- --- Licensed under the GNU General Public License v2 --- * (c) 2010, Adrian C. ---------------------------------------------------- +-- widget type providing the count of total, old and new messages in mbox files +-- Copyright (C) 2010 Adrian C. +-- Copyright (C) 2017 mutlusun +-- +-- This file is part of Vicious. +-- +-- Vicious is free software: you can redistribute it and/or modify +-- it under the terms of the GNU General Public License as +-- published by the Free Software Foundation, either version 2 of the +-- License, or (at your option) any later version. +-- +-- Vicious is distributed in the hope that it will be useful, +-- but WITHOUT ANY WARRANTY; without even the implied warranty of +-- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +-- GNU General Public License for more details. +-- +-- You should have received a copy of the GNU General Public License +-- along with Vicious. If not, see . -- {{{ Grab environment local io = { open = io.open } -local setmetatable = setmetatable -local string = { find = string.find } +local helpers = require"vicious.helpers" -- }}} - --- Mboxc: provides the count of total, old and new messages in mbox files -- vicious.widgets.mboxc local mboxc_all = {} - -- {{{ Mbox count widget type local function worker(format, warg) if not warg then return end @@ -34,15 +44,15 @@ local function worker(format, warg) -- Find all messages -- * http://www.jwz.org/doc/content-length.html - local _, from = string.find(lines, "^From[%s]") + local _, from = lines:find"^From[%s]" if from ~= nil then count.total = count.total + 1 end -- Read messages have the Status header - local _, status = string.find(lines, "^Status:[%s]RO$") + local _, status = lines:find"^Status:[%s]RO$" if status ~= nil then count.old = count.old + 1 end -- Skip the folder internal data - local _, int = string.find(lines, "^Subject:[%s].*FOLDER[%s]INTERNAL[%s]DATA") + local _, int = lines:find"^Subject:[%s].*FOLDER[%s]INTERNAL[%s]DATA" if int ~= nil then count.total = count.total - 1 end end f:close() @@ -55,4 +65,4 @@ local function worker(format, warg) end -- }}} -return setmetatable(mboxc_all, { __call = function(_, ...) return worker(...) end }) +return helpers.setcall(mboxc_all, worker) diff --git a/widgets/mdir_all.lua b/widgets/mdir_all.lua index 7853d54..cc4d035 100644 --- a/widgets/mdir_all.lua +++ b/widgets/mdir_all.lua @@ -1,8 +1,23 @@ ---------------------------------------------------- --- Licensed under the GNU General Public License v2 --- * (c) 2010, Adrian C. --- * (c) Maildir Biff Widget, Fredrik Ax ---------------------------------------------------- +-- widget type providing number of new and unread Maildir messages +-- Copyright (C) 2010 Adrian C. +-- Copyright (C) 2010 Fredrik Ax +-- Copyright (C) 2017 mutlusun +-- Copyright (C) 2019 Nguyễn Gia Phong +-- +-- This file is part of Vicious. +-- +-- Vicious is free software: you can redistribute it and/or modify +-- it under the terms of the GNU General Public License as +-- published by the Free Software Foundation, either version 2 of the +-- License, or (at your option) any later version. +-- +-- Vicious is distributed in the hope that it will be useful, +-- but WITHOUT ANY WARRANTY; without even the implied warranty of +-- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +-- GNU General Public License for more details. +-- +-- You should have received a copy of the GNU General Public License +-- along with Vicious. If not, see . -- {{{ Grab environment local type = type @@ -11,12 +26,9 @@ local helpers = require"vicious.helpers" local spawn = require"vicious.spawn" -- }}} - --- Mdir: provides the number of new and unread messages in Maildir structures/dirs -- vicious.widgets.mdir local mdir_all = {} - -- {{{ Maildir widget type function mdir_all.async(format, warg, callback) if type(warg) ~= "table" then return callback{} end diff --git a/widgets/mem_freebsd.lua b/widgets/mem_freebsd.lua index 369039e..805e9a0 100644 --- a/widgets/mem_freebsd.lua +++ b/widgets/mem_freebsd.lua @@ -1,3 +1,23 @@ +-- RAM and swap usage widget type for FreeBSD +-- Copyright (C) 2017-2019 mutlusun +-- Copyright (C) 2018 Andreas Geisenhainer +-- Copyright (C) 2019 Nguyễn Gia Phong +-- +-- This file is part of Vicious. +-- +-- Vicious is free software: you can redistribute it and/or modify +-- it under the terms of the GNU General Public License as +-- published by the Free Software Foundation, either version 2 of the +-- License, or (at your option) any later version. +-- +-- Vicious is distributed in the hope that it will be useful, +-- but WITHOUT ANY WARRANTY; without even the implied warranty of +-- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +-- GNU General Public License for more details. +-- +-- You should have received a copy of the GNU General Public License +-- along with Vicious. If not, see . + -- {{{ Grab environment local tonumber = tonumber local math = { floor = math.floor } diff --git a/widgets/mem_linux.lua b/widgets/mem_linux.lua index f167381..e49c106 100644 --- a/widgets/mem_linux.lua +++ b/widgets/mem_linux.lua @@ -1,22 +1,35 @@ ---------------------------------------------------- --- Licensed under the GNU General Public License v2 --- * (c) 2010, Adrian C. --- * (c) 2009, Lucas de Vries ---------------------------------------------------- +-- RAM and swap usage widget type for GNU/Linux +-- Copyright (C) 2010 Adrian C. +-- Copyright (C) 2009 Lucas de Vries +-- Copyright (C) 2017 mutlusun +-- Copyright (C) 2018 Jay Kamat +-- +-- This file is part of Vicious. +-- +-- Vicious is free software: you can redistribute it and/or modify +-- it under the terms of the GNU General Public License as +-- published by the Free Software Foundation, either version 2 of the +-- License, or (at your option) any later version. +-- +-- Vicious is distributed in the hope that it will be useful, +-- but WITHOUT ANY WARRANTY; without even the implied warranty of +-- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +-- GNU General Public License for more details. +-- +-- You should have received a copy of the GNU General Public License +-- along with Vicious. If not, see . -- {{{ Grab environment local io = { lines = io.lines } -local setmetatable = setmetatable local math = { floor = math.floor } 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) local _mem = { buf = {}, swp = {} } @@ -50,4 +63,4 @@ local function worker(format) end -- }}} -return setmetatable(mem_linux, { __call = function(_, ...) return worker(...) end }) +return helpers.setcall(mem_linux, worker) diff --git a/widgets/mpd_all.lua b/widgets/mpd_all.lua index b54a1e2..6ca43d1 100644 --- a/widgets/mpd_all.lua +++ b/widgets/mpd_all.lua @@ -1,7 +1,25 @@ ---------------------------------------------------- --- Licensed under the GNU General Public License v2 --- * (c) 2010, Adrian C. ---------------------------------------------------- +-- Music Player Daemon widget type +-- Copyright (C) 2010 Adrian C. +-- Copyright (C) 2017,2019 mutlusun +-- Copyright (C) 2018 Jörg Thalheim +-- Copyright (C) 2018-2019 Nguyễn Gia Phong +-- Copyright (C) 2019 Juan Carlos Menonita +-- Copyright (C) 2019 Lorenzo Gaggini +-- +-- This file is part of Vicious. +-- +-- Vicious is free software: you can redistribute it and/or modify +-- it under the terms of the GNU General Public License as +-- published by the Free Software Foundation, either version 2 of the +-- License, or (at your option) any later version. +-- +-- Vicious is distributed in the hope that it will be useful, +-- but WITHOUT ANY WARRANTY; without even the implied warranty of +-- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +-- GNU General Public License for more details. +-- +-- You should have received a copy of the GNU General Public License +-- along with Vicious. If not, see . -- {{{ Grab environment local tonumber = tonumber @@ -12,7 +30,6 @@ local helpers = require"vicious.helpers" local spawn = require"vicious.spawn" -- }}} - -- Mpd: provides Music Player Daemon information -- vicious.widgets.mpd local mpd_all = {} diff --git a/widgets/net_freebsd.lua b/widgets/net_freebsd.lua index 41a2eb7..42dbf57 100644 --- a/widgets/net_freebsd.lua +++ b/widgets/net_freebsd.lua @@ -1,3 +1,22 @@ +-- network status and usage widget type for FreeBSD +-- Copyright (C) 2017,2019 mutlusun +-- Copyright (C) 2019 Nguyễn Gia Phong +-- +-- This file is part of Vicious. +-- +-- Vicious is free software: you can redistribute it and/or modify +-- it under the terms of the GNU General Public License as +-- published by the Free Software Foundation, either version 2 of the +-- License, or (at your option) any later version. +-- +-- Vicious is distributed in the hope that it will be useful, +-- but WITHOUT ANY WARRANTY; without even the implied warranty of +-- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +-- GNU General Public License for more details. +-- +-- You should have received a copy of the GNU General Public License +-- along with Vicious. If not, see . + -- {{{ Grab environment local tonumber = tonumber local os = { time = os.time } diff --git a/widgets/net_linux.lua b/widgets/net_linux.lua index 6636f62..5ee01d8 100644 --- a/widgets/net_linux.lua +++ b/widgets/net_linux.lua @@ -1,24 +1,35 @@ ---------------------------------------------------- --- Licensed under the GNU General Public License v2 --- * (c) 2010, Adrian C. --- * (c) 2009, Lucas de Vries ---------------------------------------------------- +-- network status and usage widget type for GNU/Linux +-- Copyright (C) 2009 Lucas de Vries +-- Copyright (C) 2010 Adrian C. +-- Copyright (C) 2017 mutlusun +-- +-- This file is part of Vicious. +-- +-- Vicious is free software: you can redistribute it and/or modify +-- it under the terms of the GNU General Public License as +-- published by the Free Software Foundation, either version 2 of the +-- License, or (at your option) any later version. +-- +-- Vicious is distributed in the hope that it will be useful, +-- but WITHOUT ANY WARRANTY; without even the implied warranty of +-- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +-- GNU General Public License for more details. +-- +-- You should have received a copy of the GNU General Public License +-- along with Vicious. If not, see . -- {{{ Grab environment local tonumber = tonumber local os = { time = os.time } local io = { lines = io.lines } -local setmetatable = setmetatable 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 @@ -77,4 +88,4 @@ local function worker(format) end -- }}} -return setmetatable(net_linux, { __call = function(_, ...) return worker(...) end }) +return helpers.setcall(net_linux, worker) diff --git a/widgets/org_all.lua b/widgets/org_all.lua index 2fdbf23..44be341 100644 --- a/widgets/org_all.lua +++ b/widgets/org_all.lua @@ -1,62 +1,71 @@ ---------------------------------------------------- --- Licensed under the GNU General Public License v2 --- * (c) 2010, Adrian C. --- * (c) org-awesome, Damien Leone ---------------------------------------------------- +-- widget type providing agenda from Emacs org-mode +-- Copyright (C) 2010 Adrian C. +-- Copyright (C) 2010 org-awesome, Damien Leone +-- Copyright (C) 2017 mutlusun +-- +-- This file is part of Vicious. +-- +-- Vicious is free software: you can redistribute it and/or modify +-- it under the terms of the GNU General Public License as +-- published by the Free Software Foundation, either version 2 of the +-- License, or (at your option) any later version. +-- +-- Vicious is distributed in the hope that it will be useful, +-- but WITHOUT ANY WARRANTY; without even the implied warranty of +-- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +-- GNU General Public License for more details. +-- +-- You should have received a copy of the GNU General Public License +-- along with Vicious. If not, see . -- {{{ Grab environment local io = { lines = io.lines } -local setmetatable = setmetatable -local string = { find = string.find } -local os = { - time = os.time, - date = os.date -} +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) if not warg then return end -- Compute delays - local today = os.time{ year=os.date("%Y"), month=os.date("%m"), day=os.date("%d") } - local soon = today + 24 * 3600 * 3 -- 3 days ahead is close - local future = today + 24 * 3600 * 7 -- 7 days ahead is maximum + local today = os.time{ year = os.date("%Y"), month = os.date("%m"), + day = os.date("%d") } + local soon = today + 24*3600*3 -- 3 days ahead is close + local future = today + 24*3600*7 -- 7 days ahead is maximum -- Initialize counters local count = { past = 0, today = 0, soon = 0, future = 0 } -- Get data from agenda files - for i=1, #warg do - for line in io.lines(warg[i]) do - local scheduled = string.find(line, "SCHEDULED:") - local closed = string.find(line, "CLOSED:") - local deadline = string.find(line, "DEADLINE:") + for i = 1,#warg do + for line in io.lines(warg[i]) do + local scheduled = line:find"SCHEDULED:" + local deadline = line:find"DEADLINE:" + local closed = line:find"CLOSED:" + local b, _, y, m, d = line:find"(%d%d%d%d)-(%d%d)-(%d%d)" - if (scheduled and not closed) or (deadline and not closed) then - local b, e, y, m, d = string.find(line, "(%d%d%d%d)-(%d%d)-(%d%d)") - - if b then - local t = os.time{ year = y, month = m, day = d } - - if t < today then count.past = count.past + 1 - elseif t == today then count.today = count.today + 1 - elseif t <= soon then count.soon = count.soon + 1 - elseif t <= future then count.future = count.future + 1 + if (scheduled or deadline) and not closed and b then + local t = os.time{ year = y, month = m, day = d } + if t < today then + count.past = count.past + 1 + elseif t == today then + count.today = count.today + 1 + elseif t <= soon then + count.soon = count.soon + 1 + elseif t <= future then + count.future = count.future + 1 end - end - end - end + end + end end - return {count.past, count.today, count.soon, count.future} + return { count.past, count.today, count.soon, count.future } end -- }}} -return setmetatable(org_all, { __call = function(_, ...) return worker(...) end }) +return helpers.setcall(org_all, worker) diff --git a/widgets/os_bsd.lua b/widgets/os_bsd.lua index cfe2170..0ec0bac 100644 --- a/widgets/os_bsd.lua +++ b/widgets/os_bsd.lua @@ -1,7 +1,20 @@ ---------------------------------------------------- --- Licensed under the GNU General Public License v2 --- * (c) 2010, Adrian C. ---------------------------------------------------- +-- operating system widget type for *BSD +-- Copyright (C) 2019 mutlusun +-- +-- This file is part of Vicious. +-- +-- Vicious is free software: you can redistribute it and/or modify +-- it under the terms of the GNU General Public License as +-- published by the Free Software Foundation, either version 2 of the +-- License, or (at your option) any later version. +-- +-- Vicious is distributed in the hope that it will be useful, +-- but WITHOUT ANY WARRANTY; without even the implied warranty of +-- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +-- GNU General Public License for more details. +-- +-- You should have received a copy of the GNU General Public License +-- along with Vicious. If not, see . -- {{{ Grab environment local los = { getenv = os.getenv } @@ -10,12 +23,10 @@ local helpers = require("vicious.helpers") local spawn = require("vicious.spawn") -- }}} - -- OS: provides operating system information -- vicious.widgets.os local os_bsd = {} - -- {{{ Operating system widget type local function parse(stdout, stderr, exitreason, exitcode) local system = { diff --git a/widgets/os_linux.lua b/widgets/os_linux.lua index 4f1b516..08bba41 100644 --- a/widgets/os_linux.lua +++ b/widgets/os_linux.lua @@ -1,25 +1,37 @@ ---------------------------------------------------- --- Licensed under the GNU General Public License v2 --- * (c) 2010, Adrian C. ---------------------------------------------------- +-- operating system widget type for GNU/Linux +-- Copyright (C) 2010 Adrian C. +-- Copyright (C) 2019 Nguyễn Gia Phong +-- Copyright (C) 2019 mutlusun +-- +-- This file is part of Vicious. +-- +-- Vicious is free software: you can redistribute it and/or modify +-- it under the terms of the GNU General Public License as +-- published by the Free Software Foundation, either version 2 of the +-- License, or (at your option) any later version. +-- +-- Vicious is distributed in the hope that it will be useful, +-- but WITHOUT ANY WARRANTY; without even the implied warranty of +-- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +-- GNU General Public License for more details. +-- +-- You should have received a copy of the GNU General Public License +-- along with Vicious. If not, see . -- {{{ Grab environment local pairs = pairs local tonumber = tonumber local math = { ceil = math.ceil } local los = { getenv = os.getenv } -local setmetatable = setmetatable 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) local system = { @@ -57,5 +69,4 @@ local function worker(format) end -- }}} -return setmetatable(os_linux, - { __call = function(_, ...) return worker(...) end }) +return helpers.setcall(os_linux, worker) diff --git a/widgets/pkg_all.lua b/widgets/pkg_all.lua index 639ba4e..ca77e91 100644 --- a/widgets/pkg_all.lua +++ b/widgets/pkg_all.lua @@ -1,14 +1,30 @@ ---------------------------------------------------- --- Licensed under the GNU General Public License v2 --- * (c) 2010, Adrian C. ---------------------------------------------------- +-- widget type providing number of pending updates +-- Copyright (C) 2010 Adrian C. +-- Copyright (C) 2017 Joerg Thalheim +-- Copyright (C) 2017 getzze +-- Copyright (C) 2017 mutlusun +-- Copyright (C) 2019 Nguyễn Gia Phong +-- +-- This file is part of Vicious. +-- +-- Vicious is free software: you can redistribute it and/or modify +-- it under the terms of the GNU General Public License as +-- published by the Free Software Foundation, either version 2 of the +-- License, or (at your option) any later version. +-- +-- Vicious is distributed in the hope that it will be useful, +-- but WITHOUT ANY WARRANTY; without even the implied warranty of +-- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +-- GNU General Public License for more details. +-- +-- You should have received a copy of the GNU General Public License +-- along with Vicious. If not, see . -- {{{ Grab environment local spawn = require("vicious.spawn") local helpers = require("vicious.helpers") -- }}} - -- Pkg: provides number of pending updates on UNIX systems -- vicious.widgets.pkg local pkg_all = {} diff --git a/widgets/raid_linux.lua b/widgets/raid_linux.lua index c48b63a..f88f29e 100644 --- a/widgets/raid_linux.lua +++ b/widgets/raid_linux.lua @@ -1,25 +1,38 @@ ------------------------------------------------------ --- Licensed under the GNU General Public License v2 --- * (c) 2010, Hagen Schink ------------------------------------------------------ +-- widget type providing RAID array information on GNU/Linux +-- Copyright (C) 2010 Hagen Schink +-- Copyright (C) 2017 mutlusun +-- +-- This file is part of Vicious. +-- +-- Vicious is free software: you can redistribute it and/or modify +-- it under the terms of the GNU General Public License as +-- published by the Free Software Foundation, either version 2 of the +-- License, or (at your option) any later version. +-- +-- Vicious is distributed in the hope that it will be useful, +-- but WITHOUT ANY WARRANTY; without even the implied warranty of +-- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +-- GNU General Public License for more details. +-- +-- You should have received a copy of the GNU General Public License +-- along with Vicious. If not, see . -- {{{ Grab environment local io = { open = io.open } -local setmetatable = setmetatable local string = { len = string.len, sub = string.sub, match = string.match, gmatch = string.gmatch } --- }}} +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 = {} @@ -38,7 +51,7 @@ local function worker(format, warg) if mddev[warg]["found"] then local updev = string.match(line, "%[[_U]+%]") - for i in string.gmatch(updev, "U") do + for _ in string.gmatch(updev, "U") do mddev[warg]["active"] = mddev[warg]["active"] + 1 end @@ -46,7 +59,7 @@ local function worker(format, warg) elseif string.sub(line, 1, string.len(warg)) == warg then mddev[warg]["found"] = true - for i in string.gmatch(line, "%[[%d]%]") do + for _ in string.gmatch(line, "%[[%d]%]") do mddev[warg]["assigned"] = mddev[warg]["assigned"] + 1 end end @@ -57,4 +70,4 @@ local function worker(format, warg) end -- }}} -return setmetatable(raid_linux, { __call = function(_, ...) return worker(...) end }) +return helpers.setcall(raid_linux, worker) diff --git a/widgets/thermal_freebsd.lua b/widgets/thermal_freebsd.lua index bd3fc4d..1bb346d 100644 --- a/widgets/thermal_freebsd.lua +++ b/widgets/thermal_freebsd.lua @@ -1,3 +1,22 @@ +-- temperature widget type for FreeBSD +-- Copyright (C) 2017,2019 mutlusun +-- Copyright (C) 2019 Nguyễn Gia Phong +-- +-- This file is part of Vicious. +-- +-- Vicious is free software: you can redistribute it and/or modify +-- it under the terms of the GNU General Public License as +-- published by the Free Software Foundation, either version 2 of the +-- License, or (at your option) any later version. +-- +-- Vicious is distributed in the hope that it will be useful, +-- but WITHOUT ANY WARRANTY; without even the implied warranty of +-- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +-- GNU General Public License for more details. +-- +-- You should have received a copy of the GNU General Public License +-- along with Vicious. If not, see . + -- {{{ Grab environment local string = { match = string.match } local type = type @@ -5,7 +24,6 @@ local type = type local helpers = require("vicious.helpers") -- }}} - -- Thermal: provides temperature levels of ACPI and coretemp thermal zones -- vicious.widgets.thermal local thermal_freebsd = {} diff --git a/widgets/thermal_linux.lua b/widgets/thermal_linux.lua index 513d7de..fc8ece9 100644 --- a/widgets/thermal_linux.lua +++ b/widgets/thermal_linux.lua @@ -1,23 +1,34 @@ ---------------------------------------------------- --- Licensed under the GNU General Public License v2 --- * (c) 2010, Adrian C. ---------------------------------------------------- +-- temperature widget type for GNU/Linux +-- Copyright (C) 2010 Adrian C. +-- Copyright (C) 2017 mutlusun +-- +-- This file is part of Vicious. +-- +-- Vicious is free software: you can redistribute it and/or modify +-- it under the terms of the GNU General Public License as +-- published by the Free Software Foundation, either version 2 of the +-- License, or (at your option) any later version. +-- +-- Vicious is distributed in the hope that it will be useful, +-- but WITHOUT ANY WARRANTY; without even the implied warranty of +-- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +-- GNU General Public License for more details. +-- +-- You should have received a copy of the GNU General Public License +-- along with Vicious. If not, see . -- {{{ Grab environment local type = type local tonumber = tonumber -local setmetatable = setmetatable local string = { match = string.match } -local helpers = require("vicious.helpers") 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) if not warg then return end @@ -46,4 +57,4 @@ local function worker(format, warg) end -- }}} -return setmetatable(thermal_linux, { __call = function(_, ...) return worker(...) end }) +return helpers.setcall(thermal_linux, worker) diff --git a/widgets/uptime_freebsd.lua b/widgets/uptime_freebsd.lua index cbe6edb..42b816d 100644 --- a/widgets/uptime_freebsd.lua +++ b/widgets/uptime_freebsd.lua @@ -1,3 +1,22 @@ +-- uptime widget type for FreeBSD +-- Copyright (C) 2017,2019 mutlusun +-- Copyright (C) 2019 Nguyễn Gia Phong +-- +-- This file is part of Vicious. +-- +-- Vicious is free software: you can redistribute it and/or modify +-- it under the terms of the GNU General Public License as +-- published by the Free Software Foundation, either version 2 of the +-- License, or (at your option) any later version. +-- +-- Vicious is distributed in the hope that it will be useful, +-- but WITHOUT ANY WARRANTY; without even the implied warranty of +-- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +-- GNU General Public License for more details. +-- +-- You should have received a copy of the GNU General Public License +-- along with Vicious. If not, see . + -- {{{ Grab environment local tonumber = tonumber local math = { floor = math.floor } @@ -6,12 +25,10 @@ local os = { time = os.time } local helpers = require("vicious.helpers") -- }}} - -- Uptime: provides system uptime and load information -- vicious.widgets.uptime local uptime_freebsd = {} - -- {{{ Uptime widget type function uptime_freebsd.async(format, warg, callback) helpers.sysctl_async( diff --git a/widgets/uptime_linux.lua b/widgets/uptime_linux.lua index a6976b8..1c340a6 100644 --- a/widgets/uptime_linux.lua +++ b/widgets/uptime_linux.lua @@ -1,22 +1,33 @@ ---------------------------------------------------- --- Licensed under the GNU General Public License v2 --- * (c) 2010, Adrian C. --- * (c) 2009, Lucas de Vries ---------------------------------------------------- +-- uptime widget type for GNU/Linux +-- Copyright (C) 2009 Lucas de Vries +-- Copyright (C) 2010 Adrian C. +-- Copyright (C) 2017 mutlusun +-- +-- This file is part of Vicious. +-- +-- Vicious is free software: you can redistribute it and/or modify +-- it under the terms of the GNU General Public License as +-- published by the Free Software Foundation, either version 2 of the +-- License, or (at your option) any later version. +-- +-- Vicious is distributed in the hope that it will be useful, +-- but WITHOUT ANY WARRANTY; without even the implied warranty of +-- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +-- GNU General Public License for more details. +-- +-- You should have received a copy of the GNU General Public License +-- along with Vicious. If not, see . -- {{{ Grab environment -local setmetatable = setmetatable local math = { floor = math.floor } 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) local proc = helpers.pathtotable("/proc") @@ -28,9 +39,9 @@ local function worker(format) local up_m = math.floor(((up_t % (3600 * 24)) % 3600) / 60) local l1, l5, l15 = -- Get load averages for past 1, 5 and 15 minutes - string.match(proc.loadavg, "([%d%.]+)[%s]([%d%.]+)[%s]([%d%.]+)") + string.match(proc.loadavg, "([%d%.]+)[%s]([%d%.]+)[%s]([%d%.]+)") return {up_d, up_h, up_m, l1, l5, l15} end -- }}} -return setmetatable(uptime_linux, { __call = function(_, ...) return worker(...) end }) +return helpers.setcall(uptime_linux, worker) diff --git a/widgets/volume_freebsd.lua b/widgets/volume_freebsd.lua index d86957a..e370917 100644 --- a/widgets/volume_freebsd.lua +++ b/widgets/volume_freebsd.lua @@ -1,3 +1,22 @@ +-- volume widget type for FreeBSD +-- Copyright (C) 2017,2019 mutlusun +-- Copyright (C) 2019 Nguyễn Gia Phong +-- +-- This file is part of Vicious. +-- +-- Vicious is free software: you can redistribute it and/or modify +-- it under the terms of the GNU General Public License as +-- published by the Free Software Foundation, either version 2 of the +-- License, or (at your option) any later version. +-- +-- Vicious is distributed in the hope that it will be useful, +-- but WITHOUT ANY WARRANTY; without even the implied warranty of +-- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +-- GNU General Public License for more details. +-- +-- You should have received a copy of the GNU General Public License +-- along with Vicious. If not, see . + -- {{{ Grab environment local tonumber = tonumber local string = { match = string.match } @@ -5,12 +24,10 @@ local helpers = require("vicious.helpers") local spawn = require("vicious.spawn") -- }}} - -- Volume: provides volume levels and state of requested mixer -- vicious.widgets.volume_freebsd local volume_freebsd = {} - -- {{{ Volume widget type local STATE = { on = '🔉', off = '🔈' } diff --git a/widgets/volume_linux.lua b/widgets/volume_linux.lua index 3c281af..3d26fa3 100644 --- a/widgets/volume_linux.lua +++ b/widgets/volume_linux.lua @@ -1,7 +1,23 @@ ---------------------------------------------------- --- Licensed under the GNU General Public License v2 --- * (c) 2010, Adrian C. ---------------------------------------------------- +-- volume widget type for GNU/Linux +-- Copyright (C) 2010 Adrian C. +-- Copyright (C) 2017 Brandon Hartshorn +-- Copyright (C) 2017 mutlusun +-- Copyright (C) 2019 Nguyễn Gia Phong +-- +-- This file is part of Vicious. +-- +-- Vicious is free software: you can redistribute it and/or modify +-- it under the terms of the GNU General Public License as +-- published by the Free Software Foundation, either version 2 of the +-- License, or (at your option) any later version. +-- +-- Vicious is distributed in the hope that it will be useful, +-- but WITHOUT ANY WARRANTY; without even the implied warranty of +-- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +-- GNU General Public License for more details. +-- +-- You should have received a copy of the GNU General Public License +-- along with Vicious. If not, see . -- {{{ Grab environment local type = type @@ -13,7 +29,6 @@ local helpers = require("vicious.helpers") local spawn = require("vicious.spawn") -- }}} - -- Volume: provides volume levels and state of requested ALSA mixers -- vicious.widgets.volume local volume_linux = {} diff --git a/widgets/weather_all.lua b/widgets/weather_all.lua index 23502c4..051ecfe 100644 --- a/widgets/weather_all.lua +++ b/widgets/weather_all.lua @@ -1,19 +1,34 @@ ---------------------------------------------------- --- Licensed under the GNU General Public License v2 --- * (c) 2010, Adrian C. ---------------------------------------------------- +-- weather widget type fetching from from US NOAA +-- Copyright (C) 2010 Adrian C. +-- Copyright (C) 2017 mutlusun +-- Copyright (C) 2019 Arthur Axel 'fREW' Schmidt +-- Copyright (C) 2019 Nguyễn Gia Phong +-- +-- This file is part of Vicious. +-- +-- Vicious is free software: you can redistribute it and/or modify +-- it under the terms of the GNU General Public License as +-- published by the Free Software Foundation, either version 2 of the +-- License, or (at your option) any later version. +-- +-- Vicious is distributed in the hope that it will be useful, +-- but WITHOUT ANY WARRANTY; without even the implied warranty of +-- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +-- GNU General Public License for more details. +-- +-- You should have received a copy of the GNU General Public License +-- along with Vicious. If not, see . -- {{{ Grab environment local tonumber = tonumber local math = { ceil = math.ceil } local os = { date = os.date, difftime = os.difftime, time = os.time } -local string = { match = string.match } +local string = { format = string.format } local spawn = require"vicious.spawn" local helpers = require"vicious.helpers" -- }}} - -- Weather: provides weather information for a requested station -- vicious.widgets.weather local weather_all = {} @@ -27,7 +42,6 @@ local function get_timezone_offset() return os.difftime(os.time(localdate), os.time(utcdate)) end - -- {{{ Weather widget type local function parse(stdout, stderr, exitreason, exitcode) -- Initialize function tables @@ -51,55 +65,59 @@ local function parse(stdout, stderr, exitreason, exitcode) if stdout == '' then return _weather end _weather["{city}"] = -- City and/or area - string.match(stdout, "^(.+)%,.*%([%u]+%)") or _weather["{city}"] + stdout:match"^(.+)%,.*%([%u]+%)" + or _weather["{city}"] _weather["{wind}"] = -- Wind direction and degrees if available - string.match(stdout, "Wind:[%s][%a]+[%s][%a]+[%s](.+)[%s]at.+$") or _weather["{wind}"] + stdout:match"Wind:[%s][%a]+[%s][%a]+[%s](.+)[%s]at.+$" + or _weather["{wind}"] _weather["{windmph}"] = -- Wind speed in MPH if available - string.match(stdout, "Wind:[%s].+[%s]at[%s]([%d]+)[%s]MPH") or _weather["{windmph}"] + stdout:match"Wind:[%s].+[%s]at[%s]([%d]+)[%s]MPH" + or _weather["{windmph}"] _weather["{sky}"] = -- Sky conditions if available - string.match(stdout, "Sky[%s]conditions:[%s](.-)[%c]") or _weather["{sky}"] + stdout:match"Sky[%s]conditions:[%s](.-)[%c]" + or _weather["{sky}"] _weather["{weather}"] = -- Weather conditions if available - string.match(stdout, "Weather:[%s](.-)[%c]") or _weather["{weather}"] + stdout:match"Weather:[%s](.-)[%c]" + or _weather["{weather}"] _weather["{tempf}"] = -- Temperature in fahrenheit - string.match(stdout, "Temperature:[%s]([%-]?[%d%.]+).*[%c]") or _weather["{tempf}"] + stdout:match"Temperature:[%s]([%-]?[%d%.]+).*[%c]" + or _weather["{tempf}"] _weather["{dewf}"] = -- Dew Point in fahrenheit - string.match(stdout, "Dew[%s]Point:[%s]([%-]?[%d%.]+).*[%c]") or _weather["{dewf}"] + stdout:match"Dew[%s]Point:[%s]([%-]?[%d%.]+).*[%c]" + or _weather["{dewf}"] _weather["{humid}"] = -- Relative humidity in percent - string.match(stdout, "Relative[%s]Humidity:[%s]([%d]+)%%") or _weather["{humid}"] + stdout:match"Relative[%s]Humidity:[%s]([%d]+)%%" + or _weather["{humid}"] _weather["{press}"] = -- Pressure in hPa - string.match(stdout, "Pressure[%s].+%((.+)[%s]hPa%)") or _weather["{press}"] + stdout:match"Pressure[%s].+%((.+)[%s]hPa%)" + or _weather["{press}"] local year, month, day, hour, min = - string.match(stdout, "(%d%d%d%d).(%d%d).(%d%d) (%d%d)(%d%d) UTC") + stdout:match"(%d%d%d%d).(%d%d).(%d%d) (%d%d)(%d%d) UTC" if year ~= nil then - local utctable = { - year = year, - month = month, - day = day, - hour = hour, - min = min, - } - _weather["{when}"] = os.time(utctable) + get_timezone_offset() + local utctable = { year = year, month = month, day = day, + hour = hour, min = min } + _weather["{when}"] = os.time(utctable) + get_timezone_offset() end -- Wind speed in km/h if MPH was available if _weather["{windmph}"] ~= "N/A" then - _weather["{windmph}"] = tonumber(_weather["{windmph}"]) - _weather["{windkmh}"] = math.ceil(_weather["{windmph}"] * 1.6) + _weather["{windmph}"] = tonumber(_weather["{windmph}"]) + _weather["{windkmh}"] = math.ceil(_weather["{windmph}"] * 1.6) end -- Temperature in °C if °F was available if _weather["{tempf}"] ~= "N/A" then - _weather["{tempf}"] = tonumber(_weather["{tempf}"]) - _weather["{tempc}"] = math.ceil((_weather["{tempf}"] - 32) * 5/9) + _weather["{tempf}"] = tonumber(_weather["{tempf}"]) + _weather["{tempc}"] = math.ceil((_weather["{tempf}"] - 32) * 5/9) end -- Dew Point in °C if °F was available if _weather["{dewf}"] ~= "N/A" then - _weather["{dewf}"] = tonumber(_weather["{dewf}"]) - _weather["{dewc}"] = math.ceil((_weather["{dewf}"] - 32) * 5/9) + _weather["{dewf}"] = tonumber(_weather["{dewf}"]) + _weather["{dewc}"] = math.ceil((_weather["{dewf}"] - 32) * 5/9) end -- Capitalize some stats so they don't look so out of place if _weather["{sky}"] ~= "N/A" then - _weather["{sky}"] = helpers.capitalize(_weather["{sky}"]) + _weather["{sky}"] = helpers.capitalize(_weather["{sky}"]) end if _weather["{weather}"] ~= "N/A" then - _weather["{weather}"] = helpers.capitalize(_weather["{weather}"]) + _weather["{weather}"] = helpers.capitalize(_weather["{weather}"]) end return _weather @@ -110,7 +128,9 @@ function weather_all.async(format, warg, callback) -- Get weather forceast by the station ICAO code, from: -- * US National Oceanic and Atmospheric Administration - local url = ("https://tgftp.nws.noaa.gov/data/observations/metar/decoded/%s.TXT"):format(warg) + local url = string.format( + "https://tgftp.nws.noaa.gov/data/observations/metar/decoded/%s.TXT", + warg) spawn.easy_async("curl -fs " .. url, function (...) callback(parse(...)) end) end diff --git a/widgets/wifi_linux.lua b/widgets/wifi_linux.lua index b7a3fd8..7299fec 100644 --- a/widgets/wifi_linux.lua +++ b/widgets/wifi_linux.lua @@ -1,7 +1,22 @@ ---------------------------------------------------- --- Licensed under the GNU General Public License v2 --- * (c) 2010, Adrian C. ---------------------------------------------------- +-- Wi-Fi widget type for GNU/Linux using iwconfig +-- Copyright (C) 2010 Adrian C. +-- Copyright (C) 2017 mutlusun +-- Copyright (C) 2018-2019 Nguyễn Gia Phong +-- +-- This file is part of Vicious. +-- +-- Vicious is free software: you can redistribute it and/or modify +-- it under the terms of the GNU General Public License as +-- published by the Free Software Foundation, either version 2 of the +-- License, or (at your option) any later version. +-- +-- Vicious is distributed in the hope that it will be useful, +-- but WITHOUT ANY WARRANTY; without even the implied warranty of +-- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +-- GNU General Public License for more details. +-- +-- You should have received a copy of the GNU General Public License +-- along with Vicious. If not, see . -- {{{ Grab environment local type = type @@ -12,7 +27,6 @@ local helpers = require"vicious.helpers" local spawn = require"vicious.spawn" -- }}} - -- Wifi: provides wireless information for a requested interface using iwconfig -- vicious.widgets.wifi local wifi_linux = {} diff --git a/widgets/wifiiw_linux.lua b/widgets/wifiiw_linux.lua index e67ee33..45783d5 100644 --- a/widgets/wifiiw_linux.lua +++ b/widgets/wifiiw_linux.lua @@ -1,7 +1,23 @@ ---------------------------------------------------- --- Licensed under the GNU General Public License v2 --- * (c) 2016, Marius M. ---------------------------------------------------- +-- Wi-Fi widget type for GNU/Linux using iw +-- Copyright (C) 2016 Marius M. +-- Copyright (C) 2017 mutlusun +-- Copyright (C) 2019 Nguyễn Gia Phong +-- Copyright (C) 2019 Xaver Hellauer +-- +-- This file is part of Vicious. +-- +-- Vicious is free software: you can redistribute it and/or modify +-- it under the terms of the GNU General Public License as +-- published by the Free Software Foundation, either version 2 of the +-- License, or (at your option) any later version. +-- +-- Vicious is distributed in the hope that it will be useful, +-- but WITHOUT ANY WARRANTY; without even the implied warranty of +-- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +-- GNU General Public License for more details. +-- +-- You should have received a copy of the GNU General Public License +-- along with Vicious. If not, see . -- {{{ Grab environment local type = type @@ -11,7 +27,6 @@ local helpers = require("vicious.helpers") local spawn = require("vicious.spawn") -- }}} - -- Wifiiw: provides wireless information for a requested interface -- using iw instead of deprecated iwconfig -- vicious.widgets.wifiiw