diff --git a/.luacheckrc b/.luacheckrc index 6c05d07..d98f02c 100644 --- a/.luacheckrc +++ b/.luacheckrc @@ -6,6 +6,12 @@ read_globals = { "timer", -- deprecated, but used in older versions. } +include_files = { + "*.lua", -- libraries + "widgets/*.lua", -- officially supported widget types + "templates/*.lua", -- officially supported widget types +} + -- Warnings to be ignored ignore = { "212", -- Unused argument. diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md new file mode 100644 index 0000000..7d157cf --- /dev/null +++ b/CONTRIBUTING.md @@ -0,0 +1,318 @@ +# How to contribute to Vicious + +## Filing an Issue + +* Ensure the bug was not already reported by searching GitHub Issues. +* If you're unable to find an open issue addressing the problem, + open a new one. Be sure to include a title and clear description, + as much relevant information as possible, such as Awesome errors, + and a config sample or an executable test case + (using Vicious as a stand-alone library) + demonstrating the expected behavior that is not occurring. + +Please re-read your issue once again to avoid a couple of common mistakes +(you can and should use this as a checklist): + +* Is the description of the issue itself sufficient? + Make sure that it's obvious + - What the problem is + - How it could be fixed + - How your proposed solution would look like +* Have you provide the versions of Vicious and related software? + We would like to how you installed Vicious, which OS you're using, + the version of the software or what kind of hardware you are trying + to get information from. +* Is the issue already documented? +* Does the issue involve one problem, and one problem only? + Some people seem to think there is a limit of issues they can or should open. + There is no limit of issues they can or should open. + While it may seem appealing to be able to dump all your issues + into one ticket, that means that someone who solves one of your issues + cannot mark the issue as closed. +* Is anyone going to need the feature? Only post features that you + (or an incapacitated friend you can personally talk to) require. + Do not post features because they seem like a good idea. + If they're really useful, they'll be requested by someone who requires them. + +## Requesting for Merging a Patch + +1. [Fork this repository](https://github.com/vicious-widgets/vicious/fork) +2. Check out the source code with: + + git clone git@github.com:YOUR_GITHUB_USERNAME/vicious.git + cd vicious + +3. Start working on your patch. If you want to add a new widget type, + see the `templates` directory for a more detailed guide. +4. Have a look at `helpers.lua` and `spawn.lua` for possible helper functions. +5. Make sure your code follows the coding conventions below and check the code + with `luacheck`. This *should fail* at first, but you can continually + re-run it until you're done. + + luacheck --config .luacheckrc . + +6. Make sure your code works under all Lua versions claimed supported + by Vicious, namely 5.1, 5.2 and 5.3. +7. Update the copyright notices of the files you modified. Vicious is + collectively licensed under GPLv2+, and to protect the freedom of the users, + copyright holders need to be properly documented. +8. Try to note your changes under `Changes.md`. If you find it is + difficult to phrase the changes, you can leave it for us. +9. [Add](https://git-scm.com/docs/git-add) the changes, + [commit](https://git-scm.com/docs/git-commit) them + and [push](https://git-scm.com/docs/git-push) the result, like this: + + git add widgets/bar_baz.lua README.md + git commit -m '[bar_baz] Add widget type' + git add helpers.lua Changes.md + git commit -m '[helpers] Fix foo' + git push + +10. Finally, [create a pull request](https://help.github.com/articles/creating-a-pull-request). + We'll then review and merge it. + +In any case, thank you very much for your contributions! + +## Coding Conventions + +This section introduces a guideline for writing idiomatic, robust +and future-proof widget type code. + +### Whitespace in Expressions and Statements + +Avoid extraneous whitespace in the following situations: + +* Immediately inside parentheses or brackets. Braces, however, are exceptions + to this rule: + + ```lua + foo(bar[1], { baz = 2 }) -- yes + foo( bar[ 1 ], {baz = 2} ) -- no + ``` + +* Immediately before a comma, semicolon, or colon. +* Immediately before the open parenthesis, braces, quote, etc. + that starts the argument list of a function call; or the open bracket + that starts an indexing. In other words, prefer these: + + ```lua + foo(bar, baz) + foo{ bar, baz } + foo"bar" + foo[[bar]] + foo[bar] + ``` + +* Trailing at the end of line or (newline) at the end of file. + +Always surround these binary operators with a single space on either side: +assignment (`=`), comparisons, Booleans (`and`, `or`, `not`). +If operators with different priorities are used, consider adding whitespace +around the operators with the lowest priorities. Use your own judgment; +however, never use more than one space, and always have +the same amount of whitespace on both sides of a binary operator. + +### Indentation + +Use 4 *spaces* per indentation level. + +Continuation lines should align wrapped elements either vertically +inside parentheses, brackets and braces, or using a hanging indent +(the opening parenthesis of a parenthesized statement is the last +non-whitespace character of the line, with subsequent lines being indented +until the closing parenthesis), e.g. + +```lua +-- Vertically aligned +long_function_call{ foo, bar, + baz } + +-- Hanging indentation +long_function_call( + foo, bar + baz) +``` + +The closing brace or bracket on multi-line constructs may either line up under +the first character of the line that starts the construct, as in: + +```lua +long_function_call{ + foo = 1, bar = 2, + baz = 3, +} +``` + +In this case, and this case only, the trailing comma is acceptable +to avoid diff noises when more values are added, +but since Vicious often deal with system APIs which rarely ever change, +it's occasionally helpful to do so. + +Trailing right parentheses, however, are not allowed. + +### Maximum Line Length + +If possible, try to limit all *code* lines to a maximum +of 80 characters. In case you find some lines in your patch would be +more readable exceeding this limit, feel free to discuss with us. +Comments and long strings need not to follow this restriction however. + +As one might have noticed, the syntactic sugars `f{}` +(for `f({})`) and `f''` (or `f""`/`f[[]]`, +for `f('')`) are especially preferred to squeeze +the line length to this limit. + +### Blank Lines + +Surround function definitions with a single blank line. Extra blank lines +may be used (sparingly) to separate groups of related functions. +Blank lines may be omitted between a bunch of related one-liners +(e.g. a set of dummy implementations). +Use blank lines in functions, sparingly, to indicate logical sections. + +### Requiring Libraries + +All standard libraries should be localized before used +for the matter of performance. + +`require`s should always be put at the top of the source file, +just after the copyright header, and before module globals and constants, +and grouped in the following order: + +1. Standard libraries +2. Related third-party libraries +3. Local libraries + +For example, + +```lua +local type = type +local table = { concat = table.concat, insert = table.insert } + +local awful = require("awful") + +local helpers = require("vicious.helpers") +``` + +### String Quotes + +In Lua, single-quoted strings and double-quoted strings are the same, +so the choice is totally up to you, but please be consistent within a module. +When a string contains single or double quote characters, however, +use the other one to avoid backslashes in the string. It improves readability: + +```lua +'"key": "value"' -- good +"\"key\": \"value\"" -- no good +``` + +It is preferable to add a newline immediately after the opening long bracket: + +```lua +foo = [[ +this is a really, +really, +really long text]] +``` + +### Naming Conventions + +Avoid using the characters `l` (lowercase letter el), `O` (uppercase letter oh), +or `I` (uppercase letter eye) as single character variable names. +In some fonts, these characters are indistinguishable from the 1's and 0's. + +#### Constants + +Constants are usually defined on a module level +and written in all capital letters with underscores separating words. +Examples include `MAX_OVERFLOW` and `TOTAL`. + + +#### Function and Variable Names + +Function names should be lowercase, with words separated by underscores +as necessary to improve readability. + +Variable names follow the same convention as function names. + +When you find it difficult to give descriptive names, +use the functions and variable anonymously. + +### Performance Tips + +Vicious is meant to be run as part of the Awesome window manager, +thus any little overhead may defect the responsiveness of the UI. +While Lua is famous for its performance, there are a few things +one can do to make use of all of its power. + +**Never** use global variables. This includes the standard libraries, +which, again, must be localized before use. Remember, every widget type +is to be called repeatedly every few seconds. + +Use closures when possible: + +* Define constants on the module level. +* Avoid re-fetching the values that are not not meant to change. + +However, declare a variable only when you need it, to avoid declaring it +without an initial value (and therefore you seldom forget to initialize it). +Moreover, you shorten the scope of the variable, which increases readability. + +### Copyright Header + +Vicious is released under the GNU GNU General Public License +version 2 or later and each contributor holds the copyright +on their contributions. To make this collective control effective, +each source file must include a notice of the following format +denoting the name of all authors + +```lua +-- +-- Copyright (C) <> +-- +-- 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 . +``` + +### Comments + +Comments that contradict the code are worse than no comments. +Always make a priority of keeping the comments up-to-date when the code changes! + +You should use two spaces after a sentence-ending period +in multi-sentence comments, except after the final sentence. + +#### Block Comments + +Block comments generally apply to some (or all) code that follows them, +and are indented to the same level as that code. Each line of a block comment +starts with `--` and a single space, unless text inside the comment is indented, +or it is to comment out code. + +Paragraphs inside a block comment are separated by a line containing `--` only. +The best example is the copyright notice in the section above. + +The `--[[...]]` style may only be used for commenting out source code. + +#### Inline Comments + +An inline comment is a comment on the same line as a statement. +Inline comments should be separated by at least two spaces from the statement. +They should start with `-- `. + +## Influences + +These contributing guideline are heavily influenced by that of `youtube-dl`, +PEP 8, Programming in Lua and the performance tips in Lua Programming Gems. diff --git a/Changes.md b/Changes.md index bc453fa..2bc2c67 100644 --- a/Changes.md +++ b/Changes.md @@ -1,4 +1,4 @@ -# Changes in 2.4.0 (WIP) +# Changes in 2.4.0 IMPORTANT: @@ -16,6 +16,11 @@ Added: - `helpers.setasyncall` to avoid writing redundant workers for asynchronous widget types. Note that these workers are only needed in case Vicious is used 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: @@ -26,10 +31,12 @@ Fixed: * bat_openbsd * volume, gmail, mdir, mpd, fs - [mpd] Lua 5.3 compatibility (for real this time); also correct a typo +- [mbox] Update the deprecated `string.gfind` to `string.gmatch` - [pkg,weather,contrib/btc] Allow function call without Awesome - [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 and widget types Removed: diff --git a/README.md b/README.md index 8161783..fd48ee2 100644 --- a/README.md +++ b/README.md @@ -3,9 +3,7 @@ Vicious is a modular widget library for window managers, but mostly catering to users of the *awesome* window manager. It was derived from the old *Wicked* widget library, and has some of the old *Wicked* widget -types, a few of them rewritten, and a good number of new ones: - -* https://github.com/vicious-widgets/vicious +types, a few of them rewritten, and a good number of new ones. Vicious widget types are a framework for creating your own widgets. Vicious contains modules that gather data about your system, @@ -14,12 +12,13 @@ timers, suspend widgets and so on. Vicious doesn't depend on any third party Lua libraries, but may depend on additional system utilities (see widget description). + ## Usage When provided by an operating system package, or installed from source into the Lua library path Vicious can be used as a regular Lua library, to be used stand-alone or to feed widgets of any window -manager (e.g. Ion, WMII). It is compatible with both Lua v5.1 and v5.2. +manager (e.g. Ion, WMII). It is compatible with Lua version 5.1 and above. ```lua > widgets = require("vicious.widgets.init") @@ -27,6 +26,7 @@ manager (e.g. Ion, WMII). It is compatible with both Lua v5.1 and v5.2. 100 ``` + ## Usage within Awesome To use Vicious with Awesome, install the package from your operating @@ -34,6 +34,7 @@ system provider, or download the source code and move it to your awesome configuration directory in `$XDG_CONFIG_HOME` (usually `~/.config`): ```bash +$ git clone https://github.com/vicious-widgets/vicious.git $ mv vicious $XDG_CONFIG_HOME/awesome/ ``` @@ -47,17 +48,19 @@ Then add the following to the top of your `rc.lua`: local vicious = require("vicious") ``` +### Register a widget + Once you create a widget (a textbox, graph or a progressbar) call `vicious.register()` to register it with Vicious: vicious.register(widget, wtype, format, interval, warg) -### widget +#### widget *Awesome* widget created with `widget()` or `awful.widget()` (in case of a graph or a progressbar). -### wtype +#### wtype Type: Vicious widget or `function`: @@ -66,7 +69,7 @@ Type: Vicious widget or `function`: * function: custom function from your own *Awesome* configuration can be registered as widget types (see [Custom widget types](#custom-widget)). -### format +#### format Type: `string` or `function`: @@ -77,17 +80,15 @@ Type: `string` or `function`: * `function (widget, args)` can be used to manipulate data returned by the widget type (see [Format functions](#format-func)). -### interval +#### interval Number of seconds between updates of the widget (default: 2). Read section [Power and Caching](#power) for more information. -### warg +#### warg Some widget types require an argument to be passed, for example the battery ID. -## Other functions - `vicious.register` alone is not much different from [awful.widget.watch](https://awesomewm.org/doc/api/classes/awful.widget.watch.html), which has been added to Awesome since version 4.0. However, Vicious offers more @@ -131,6 +132,7 @@ Enable caching of values returned by a widget type. Fetch data from `wtype` to use it outside from the wibox ([example](#call-example)). + ## Widget types Widget types consist of worker functions that take two arguments `format` and @@ -373,9 +375,11 @@ Supported platforms: platform independent (required tools: `curl`). * Argument: an array including password, hostname and port in that order. `nil` fields will be fallen back to default (`localhost:6600` without password). -* Returns a table with string keys: `${volume}`, `${bitrate}`, `${elapsed}` (in seconds), - `${duration}` (in seconds), `${Elapsed}` (formatted as [hh:]mm:ss), `${Duration}` (formatted as [hh:]mm:ss), - `${Progress}` (in percentage), ${random}`, `${repeat}`, `${state}`, `${Artist}`, `${Title}`, `${Album}`, +* Returns a table with string keys: `${volume}`, `${bitrate}`, + `${elapsed}` (in seconds), `${duration}` (in seconds), + `${Elapsed}` (formatted as [hh:]mm:ss), + `${Duration}` (formatted as [hh:]mm:ss), `${Progress}` (in percentage), + `${random}`, `${repeat}`, `${state}`, `${Artist}`, `${Title}`, `${Album}`, `${Genre}` and optionally `${Name}` and `${file}`. ### vicious.widgets.net @@ -560,6 +564,7 @@ Supported platforms: GNU/Linux. `${rate}` (Mb/s), `${freq}` (MHz), `${linp}` (link quality in percent), `${txpw}` (transmission power, in dBm) and `${sign}` (signal level, in dBm) + ## Custom widget types Use any of the existing widget types as a starting point for your @@ -645,6 +650,7 @@ Users of GnuPG (and its agent) could consider encrypting the netrc file with their GPG key. Trough the GPG Passphrase Agent they could then decrypt the file transparently while their session is active. + ## Usage examples Start with a simple widget, like `date`. Then build your setup from @@ -733,6 +739,7 @@ cpuwidget:set_color{type = "linear", from = {0, 0}, to = {50, 0}, vicious.register(cpuwidget, vicious.widgets.cpu, "$1", 3) ``` + ## Format functions You can use a function instead of a string as the format parameter. @@ -863,6 +870,7 @@ mybattery:buttons(awful.util.table.join( end))) ``` + ## See also * Manual pages: [awesome(1)](https://awesomewm.org/doc/manpages/awesome), @@ -872,6 +880,15 @@ mybattery:buttons(awful.util.table.join( (outdated) * [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: @@ -889,15 +906,63 @@ Current maintainers: * Daniel Hahler (blueyed) \ * Nguyễn Gia Phong (McSinyx) \ -Vicious major contributors: +Contributors, listed in alphabetic order: -* Benedikt Sauer \ -* Greg D. \ -* Henning Glawe \ -* Rémy C. \ -* Hiltjo Posthuma \ -* Hagen Schink \ +* 0x5b \ +* Adam Lee \ +* Alexander Koch \ +* Amir Mohammad Saied \ +* Andrea Scarpino \ +* Andreas Geisenhainer \ +* Andrew Merenbach \ +* Andrzej Bieniek \ +* Arthur Axel 'fREW' Schmidt \ * Arvydas Sidorenko \ +* Benedikt Sauer \ +* Beniamin Kalinowski \ +* Benoît Zugmeyer \ +* blastmaster \ +* Brandon Hartshorn \ +* crondog \ +* David Udelson \ * Dodo The Last \ -* … -* Consult git log for a complete list of contributors +* Elric Milon \ +* Enric Morales \ +* getzze \ +* Greg D. \ +* Hagen Schink \ +* Henning Glawe \ +* Hiltjo Posthuma \ +* [James Reed](https://github.com/supplantr) +* Jay Kamat \ +* Jeremy \ +* jinleileiking \ +* joe di castro \ +* Joerg Jaspert \ +* Jonathan McCrohan \ +* [Juan Carlos Menonita](https://github.com/JuanKman94) +* Juergen Descher \ +* Julian Volodia \ +* Keith Hughitt \ +* Lorenzo Gaggini \ +* Lyderic Lefever \ +* Martin Striz \ +* Martin Ueding \ +* Mellich \ +* Michael Kressibucher \ +* Michael Unterkalmsteiner \ +* niko \ +* Noah Tilton \ +* Normal Ra \ +* Perry Hargrave \ +* Rémy CLOUARD \ +* [Roberto](https://github.com/empijei) +* Sébastien Luttringer \ +* Shadowmourne G \ +* starenka \ +* Suseika \ +* Uli Schlachter \ +* Wtfcoder \ +* Xaver Hellauer \ +* zhrtz \ +* And many others diff --git a/contrib/ac_linux.lua b/contrib/ac_linux.lua index 73afb03..7d13bfe 100644 --- a/contrib/ac_linux.lua +++ b/contrib/ac_linux.lua @@ -1,7 +1,21 @@ ---------------------------------------------------- --- Licensed under the GNU General Public License v2 --- * (c) 2012, jinleileiking ---------------------------------------------------- +-- contrib/ac_linux.lua +-- Copyright (C) 2012 jinleileiking +-- Copyright (C) 2017 Jörg Thalheim +-- +-- 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 diff --git a/contrib/ati_linux.lua b/contrib/ati_linux.lua index 1afe8f9..0dd4100 100644 --- a/contrib/ati_linux.lua +++ b/contrib/ati_linux.lua @@ -1,7 +1,21 @@ ---------------------------------------------------- --- Licensed under the GNU General Public License v2 --- * (c) 2013, NormalRa ---------------------------------------------------- +-- contrib/ati_linux.lua +-- Copyright (C) 2013 NormalRa +-- Copyright (C) 2017 Jörg Thalheim +-- +-- 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 diff --git a/contrib/batpmu_linux.lua b/contrib/batpmu_linux.lua index 0efc863..85b2eba 100644 --- a/contrib/batpmu_linux.lua +++ b/contrib/batpmu_linux.lua @@ -1,7 +1,21 @@ ---------------------------------------------------- --- Licensed under the GNU General Public License v2 --- * (c) 2010, Adrian C. ---------------------------------------------------- +-- contrib/batpmu_linux.lua +-- Copyright (C) 2010 Adrian C. +-- Copyright (C) 2017 Jörg Thalheim +-- +-- 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 diff --git a/contrib/batproc_linux.lua b/contrib/batproc_linux.lua index 0d4dfe7..b6b5e35 100644 --- a/contrib/batproc_linux.lua +++ b/contrib/batproc_linux.lua @@ -1,7 +1,21 @@ ---------------------------------------------------- --- Licensed under the GNU General Public License v2 --- * (c) 2010, Adrian C. ---------------------------------------------------- +-- contrib/batproc_linux.lua +-- Copyright (C) 2010 Adrian C. +-- Copyright (C) 2017 Jörg Thalheim +-- +-- 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 diff --git a/contrib/btc_all.lua b/contrib/btc_all.lua index e28cada..804883b 100644 --- a/contrib/btc_all.lua +++ b/contrib/btc_all.lua @@ -1,7 +1,22 @@ ---------------------------------------------------- --- Licensed under the GNU General Public License v2 --- * (c) 2017, 0x5b ---------------------------------------------------- +-- contrib/btc_all.lua +-- Copyright (C) 2017 0x5b +-- Copyright (C) 2017 Joerg Thalheim +-- 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 pcall = pcall diff --git a/contrib/buildbot_all.lua b/contrib/buildbot_all.lua index a8f1278..41ca126 100644 --- a/contrib/buildbot_all.lua +++ b/contrib/buildbot_all.lua @@ -1,7 +1,21 @@ ---------------------------------------------------- --- Licensed under the GNU General Public License v2 --- * (c) 2012, Andrzje Bieniek ---------------------------------------------------- +-- contrib/buildbot_all.lua +-- Copyright (C) 2012 Andrzje Bieniek +-- Copyright (C) 2017 Jörg Thalheim +-- +-- 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 diff --git a/contrib/countfiles_all.lua b/contrib/countfiles_all.lua index e8f146c..6bfdffc 100644 --- a/contrib/countfiles_all.lua +++ b/contrib/countfiles_all.lua @@ -1,7 +1,20 @@ ---------------------------------------------------- --- Licensed under the GNU General Public License v2 ---------------------------------------------------- --- * (c) 2010, Jörg. T +-- contrib/countfiles_all.lua +-- Copyright (C) 2017 Jörg Thalheim +-- +-- 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 = { popen = io.popen } diff --git a/contrib/dio_linux.lua b/contrib/dio_linux.lua index 3059361..780157d 100644 --- a/contrib/dio_linux.lua +++ b/contrib/dio_linux.lua @@ -1,7 +1,21 @@ ---------------------------------------------------- --- Licensed under the GNU General Public License v2 --- * (c) 2010, Adrian C. ---------------------------------------------------- +-- contrib/dio_linux.lua +-- Copyright (C) 2010, Adrian C. +-- Copyright (C) 2017 Jörg Thalheim +-- +-- 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 ipairs = ipairs diff --git a/contrib/init.lua b/contrib/init.lua index 4328aae..a59179d 100644 --- a/contrib/init.lua +++ b/contrib/init.lua @@ -1,9 +1,22 @@ ---------------------------------------------------- --- Vicious widgets for the awesome window manager ---------------------------------------------------- --- Licensed under the GNU General Public License v2 --- * (c) 2010, Adrian C. ---------------------------------------------------- +-- contrib/init.lua +-- Copyright (C) 2010-2012 Adrian C. (anrxc) +-- Copyright (C) 2011 Joerg T. (Mic92) +-- Copyright (C) 2012 Arvydas Sidorenko +-- +-- 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 . -- {{{ Setup environment local setmetatable = setmetatable diff --git a/contrib/mpc_all.lua b/contrib/mpc_all.lua index 7393e76..4660ffb 100644 --- a/contrib/mpc_all.lua +++ b/contrib/mpc_all.lua @@ -1,8 +1,23 @@ ---------------------------------------------------- --- Licensed under the GNU General Public License v2 --- * (c) 2010, Adrian C. --- * (c) 2009, Lucas de Vries ---------------------------------------------------- +-- contrib/mpc_all.lua +-- Copyright (C) 2009 Lucas de Vries +-- Copyright (C) 2010 Adrian C. +-- Copyright (C) 2017 Jörg Thalheim +-- 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 diff --git a/contrib/net_linux.lua b/contrib/net_linux.lua index ad0b36a..85b9250 100644 --- a/contrib/net_linux.lua +++ b/contrib/net_linux.lua @@ -1,9 +1,24 @@ ---------------------------------------------------- --- Licensed under the GNU General Public License v2 --- * (c) 2010, Adrian C. --- * (c) 2009, Henning Glawe --- * (c) 2009, Lucas de Vries ---------------------------------------------------- +-- contrib/net_linux.lua +-- Copyright (C) 2009 Henning Glawe +-- Copyright (C) 2009 Lucas de Vries +-- Copyright (C) 2010 Adrian C. +-- Copyright (C) 2017 Jörg Thalheim +-- Copyright (C) 2017 Roberto +-- +-- 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 diff --git a/contrib/netcfg.lua b/contrib/netcfg.lua index f2c0d52..672a8f3 100644 --- a/contrib/netcfg.lua +++ b/contrib/netcfg.lua @@ -1,7 +1,22 @@ ---------------------------------------------------- --- Licensed under the GNU General Public License v2 --- * (c) 2010, Radu A. ---------------------------------------------------- +-- contrib/netcfg.lua +-- Copyright (C) 2010 Radu A. +-- Copyright (C) 2010 Adrian C. (anrxc) +-- Copyright (C) 2012 Arvydas Sidorenko +-- +-- 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 = { popen = io.popen } diff --git a/contrib/nvinf_all.lua b/contrib/nvinf_all.lua index 35b1632..c1515cf 100644 --- a/contrib/nvinf_all.lua +++ b/contrib/nvinf_all.lua @@ -1,7 +1,21 @@ ---------------------------------------------------- --- Licensed under the GNU General Public License v2 --- * (c) 2015, Ziyuan Guo ---------------------------------------------------- +-- contrib/nvinf_all.lua +-- Copyright (C) 2015 Ziyuan Guo +-- Copyright (C) 2017 Jörg Thalheim +-- +-- 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 diff --git a/contrib/nvsmi_all.lua b/contrib/nvsmi_all.lua index 317787e..a6c4df8 100644 --- a/contrib/nvsmi_all.lua +++ b/contrib/nvsmi_all.lua @@ -1,7 +1,21 @@ ---------------------------------------------------- --- Licensed under the GNU General Public License v2 --- * (c) 2014, Adrian C. ---------------------------------------------------- +-- contrib/nvsmi_all.lua +-- Copyright (C) 2014 Adrian C. +-- Copyright (C) 2017 Jörg Thalheim +-- +-- 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 diff --git a/contrib/openweather_all.lua b/contrib/openweather_all.lua index dfeabf7..23abe5e 100644 --- a/contrib/openweather_all.lua +++ b/contrib/openweather_all.lua @@ -1,7 +1,21 @@ ---------------------------------------------------- --- Licensed under the GNU General Public License v2 --- * (c) 2013, NormalRa ---------------------------------------------------- +-- contrib/openweather_all.lua +-- Copyright (C) 2013 NormalRa +-- Copyright (C) 2017 Jörg Thalheim +-- +-- 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 diff --git a/contrib/ossvol_linux.lua b/contrib/ossvol_linux.lua index 4f6af7e..6ef6f3b 100644 --- a/contrib/ossvol_linux.lua +++ b/contrib/ossvol_linux.lua @@ -1,7 +1,21 @@ ---------------------------------------------------- --- Licensed under the GNU General Public License v2 --- * (c) 2010, Adrian C. ---------------------------------------------------- +-- contrib/ossvol_linux.lua +-- Copyright (C) 2010 Adrian C. +-- Copyright (C) 2017 Jörg Thalheim +-- +-- 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 diff --git a/contrib/pop_all.lua b/contrib/pop_all.lua index 5b6b2a6..3d24059 100644 --- a/contrib/pop_all.lua +++ b/contrib/pop_all.lua @@ -1,7 +1,23 @@ ---------------------------------------------------- --- Licensed under the GNU General Public License v2 --- * (c) 2010, Boris Bolgradov <> +-- contrib/pop_all.lua +-- Copyright (c) 2010 Boris Bolgradov +-- Copyright (C) 2017 Jörg Thalheim -- +-- 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 . + +--------------------------------------------------- -- This widget type depends on luasocket. -- -- Widget arguments are host, port, username and diff --git a/contrib/pulse_all.lua b/contrib/pulse_all.lua index 98bd22b..1322ae0 100644 --- a/contrib/pulse_all.lua +++ b/contrib/pulse_all.lua @@ -1,8 +1,22 @@ ---------------------------------------------------- --- Licensed under the GNU General Public License v2 --- * (c) 2010, MrMagne --- * (c) 2010, Mic92 ---------------------------------------------------- +-- contrib/pulse_all.lua +-- Copyright (C) 2010 MrMagne +-- Copyright (C) 2010,2017 Jörg Thalheim +-- Copyright (C) 2017 Jonathan McCrohan +-- +-- 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 diff --git a/contrib/rss_all.lua b/contrib/rss_all.lua index 75e9817..f8b3dea 100644 --- a/contrib/rss_all.lua +++ b/contrib/rss_all.lua @@ -1,7 +1,23 @@ ---------------------------------------------------- --- Licensed under the GNU General Public License v2 --- * (c) 2009, olcc +-- contrib/rss_all.lua +-- Copyright (C) 2009 olcc +-- Copyright (C) 2017 Jörg Thalheim -- +-- 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 . + +--------------------------------------------------- -- This is now a standalone RSS reader for awesome: -- * http://github.com/olcc/aware --------------------------------------------------- diff --git a/contrib/sensors_linux.lua b/contrib/sensors_linux.lua index eb0d14c..6d7e87c 100644 --- a/contrib/sensors_linux.lua +++ b/contrib/sensors_linux.lua @@ -1,7 +1,21 @@ ---------------------------------------------------- --- Licensed under the GNU General Public License v2 --- * (c) 2010, Greg D. ---------------------------------------------------- +-- contrib/sensors_linux.lua +-- Copyright (C) 2010 Greg D. +-- Copyright (C) 2017 Jörg Thalheim +-- +-- 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 diff --git a/contrib/wpa_all.lua b/contrib/wpa_all.lua index 462068f..e35125a 100644 --- a/contrib/wpa_all.lua +++ b/contrib/wpa_all.lua @@ -1,7 +1,21 @@ ---------------------------------------------------- --- Licensed under the GNU General Public License v2 --- * (c) 2012, jinleileiking. ---------------------------------------------------- +-- contrib/wpa_all.lua +-- Copyright (C) 2012 jinleileiking +-- Copyright (C) 2017 Jörg Thalheim +-- +-- 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 diff --git a/headergen b/headergen new file mode 100755 index 0000000..fe3dd51 --- /dev/null +++ b/headergen @@ -0,0 +1,100 @@ +#!/usr/bin/env lua +-- copyright header generator +-- 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 . + +local ipairs = ipairs +local pairs = pairs +local tonumber = tonumber +local io = { open = io.open, popen = io.popen } +local os = { exit = os.exit } +local table = { + concat = table.concat, + insert = table.insert, + sort = table.sort +} + +local HEADER = [[-- %s +%s +-- +-- 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 . + +%s]] +local COMMAND = "git log --date=format:%Y --format='%ad %an <%ae>' " + +if #arg == 0 then + print'usage: headergen lua-source-files' + os.exit(1) +end + +for _, filename in ipairs(arg) do + local fi = io.open(filename) + local content = fi:read'*a' + fi:close() + + local holders = {} + local output = io.popen(COMMAND .. filename) + for line in output:lines() do + local year, author = line:match'(%d+)%s+(.+)' + if holders[author] == nil then holders[author] = {} end + holders[author][year] = true + end + output:close() + + local copyrights = {} + for author, years in pairs(holders) do + local time = {} + for year, _ in pairs(years) do table.insert(time, tonumber(year)) end + table.sort(time) + + local copyright = { 'Copyright (C) ' } + for _, current in ipairs(time) do + local prev = tonumber(copyright[#copyright]) + if prev == nil then + table.insert(copyright, current) + elseif current - 1 ~= prev then + table.insert(copyright, ',') + table.insert(copyright, current) + elseif copyright[#copyright - 1] == '-' then + copyright[#copyright] = current + else + table.insert(copyright, '-') + table.insert(copyright, current) + end + end + table.insert(copyrights, + ('-- %s %s'):format(table.concat(copyright), author)) + end + + local fo = io.open(filename, 'w') + table.sort(copyrights) + fo:write(HEADER:format(filename, table.concat(copyrights, '\n'), content)) + fo:close() +end diff --git a/helpers.lua b/helpers.lua index aa11a28..e7807e5 100644 --- a/helpers.lua +++ b/helpers.lua @@ -1,12 +1,34 @@ ---------------------------------------------------- --- Licensed under the GNU General Public License v2 --- * (c) 2019, Enric Morales --- * (c) 2010, Adrian C. --- * (c) 2009, Rémy C. --- * (c) 2009, Benedikt Sauer --- * (c) 2009, Henning Glawe --- * (c) 2009, Lucas de Vries ---------------------------------------------------- +-- helper functions +-- Copyright (C) 2009 Benedikt Sauer +-- Copyright (C) 2009 Henning Glawe +-- Copyright (C) 2009 Lucas de Vries +-- Copyright (C) 2009 Rémy C. +-- Copyright (C) 2009-2012 Adrian C. (anrxc) +-- Copyright (C) 2011 Joerg T. (Mic92) +-- Copyright (C) 2012 Arvydas Sidorenko +-- Copyright (C) 2012 Jörg Thalheim +-- Copyright (C) 2014-2015 Jörg Thalheim +-- Copyright (C) 2017 Joerg Thalheim +-- Copyright (C) 2017,2019 mutlusun +-- Copyright (C) 2017-2018 Jörg Thalheim +-- Copyright (C) 2018-2019 Nguyễn Gia Phong +-- Copyright (C) 2019 Alexander Koch +-- Copyright (C) 2019 Enric Morales +-- +-- 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 ipairs = ipairs @@ -101,6 +123,13 @@ function helpers.wrequire(collection, key) end -- }}} +-- {{{ Set widget type's __call metamethod to given worker function +function helpers.setcall(worker) + return setmetatable( + {}, { __call = function(_, ...) return worker(...) end }) +end +-- }}} + -- {{{ Set __call metamethod to widget type table having async key function helpers.setasyncall(wtype) local function worker(format, warg) @@ -277,5 +306,4 @@ end -- }}} return helpers - -- }}} diff --git a/init.lua b/init.lua index e10d4d6..e4f7568 100644 --- a/init.lua +++ b/init.lua @@ -1,16 +1,41 @@ ---------------------------------------------------- --- Vicious widgets for the awesome window manager ---------------------------------------------------- --- Licensed under the GNU General Public License v2 --- * (c) 2010, Adrian C. --- * (c) 2009, Lucas de Vries ---------------------------------------------------- +-- Vicious module initialization +-- Copyright (C) 2009 Lucas de Vries +-- Copyright (C) 2009-2013 Adrian C. (anrxc) +-- Copyright (C) 2011 Joerg T. (Mic92) +-- Copyright (C) 2012 Arvydas Sidorenko +-- Copyright (C) 2012 Jörg Thalheim +-- Copyright (C) 2013 Dodo +-- Copyright (C) 2013-2014,2017 Jörg Thalheim +-- Copyright (C) 2014 blastmaster +-- Copyright (C) 2015 Daniel Hahler +-- Copyright (C) 2017 James Reed +-- Copyright (C) 2017 Joerg Thalheim +-- Copyright (C) 2017 getzze +-- Copyright (C) 2017 mutlusun +-- Copyright (C) 2018 Beniamin Kalinowski +-- Copyright (C) 2018 Nguyễn Gia Phong +-- Copyright (C) 2019 Daniel Hahler +-- +-- 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 . -- {{{ Setup environment 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, @@ -69,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/spawn.lua b/spawn.lua index 620d563..afe7802 100644 --- a/spawn.lua +++ b/spawn.lua @@ -1,5 +1,5 @@ --- spawn.lua - wrapper around Awesome awful.spawn with fallback --- Copyright (C) 2019 Nguyễn Gia Phong +-- wrapper around Awesome awful.spawn with fallback +-- Copyright (C) 2019 Nguyễn Gia Phong -- -- This file is part of Vicious. -- @@ -11,9 +11,9 @@ -- 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 Affero General Public License for more details. +-- GNU General Public License for more details. -- --- You should have received a copy of the GNU Affero General Public License +-- You should have received a copy of the GNU General Public License -- along with Vicious. If not, see . local status, awful = pcall(require, "awful") diff --git a/templates/README.md b/templates/README.md new file mode 100644 index 0000000..80a9ea9 --- /dev/null +++ b/templates/README.md @@ -0,0 +1,48 @@ +# Widget type templates + +Before writing a new widget type, make sure to ask yourself if anyone is going +to need the feature. Only widget types that you (or an incapacitated friend +you can personally talk to) require would be merged. Do not file PRs because +they seem like a good idea. If they're really useful, they'll be requested +in the issue tracker. + +Additionally, too simple widget types (e.g. an one-liner) and those that +are not modular enough are very unlikely to be merged. By *modular*, we mean + +> constructed with standardized units or dimensions +> allowing flexibility and variety in use + +If all the above conditions are met, you can start from one of the templates +in this directory: + +* `sync.lua`: synchronous widget type that does not fork +* `async.lua`: asynchronous widget type for fetching informations using + a command-line utility. As a rule of thumb, if your widget type uses + `io.popen`, you would need to refactor it to use async facilities. + +Your widget types should be placed in `widgets`: the `contrib` directory +exists only for historical reasons and is barely maintained anymore. +The filenames should be of the form `_.lua`, whereas + +* `` is a single (alphanumeric) word, preferably in lowercase +* `` is the OS that the widget type works on. + At the time of writing these are supported: + - `freebsd`: FreeBSD + - `openbsd`: OpenBSD + - `bsd`: all \*BSDs listed above + - `linux`: GNU/Linux + - `all`: all of the above + +Please be aware of `luacheck`, which may help you during the progress. +From `widgets`, run + + luacheck --config .luacheckrc .. + +After finishing the widget type, you should document its usage in the project's +`README.md`. Try to provide at least + +* A brief description +* The list of supported platforms +* Type and structures of the arguments that the widget type passes + (`format` and `warg`), with unused parameters omitted +* Type and structure of the return value diff --git a/templates/async.lua b/templates/async.lua new file mode 100644 index 0000000..d704071 --- /dev/null +++ b/templates/async.lua @@ -0,0 +1,28 @@ +-- template for asynchronous widet types +-- 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 . + +local helpers = require"vicious.helpers" + +return helpers.setasyncall{ + async = function (format, warg, callback) + -- In here there should be some asynchronous function + -- from vicious.spawn or helpers.sysctl_async + -- that call callback on the result. + end } + +-- vim: filetype=lua:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:textwidth=80 diff --git a/templates/sync.lua b/templates/sync.lua new file mode 100644 index 0000000..4b49059 --- /dev/null +++ b/templates/sync.lua @@ -0,0 +1,25 @@ +-- template for synchronous widet types +-- 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 . + +local helpers = require"vicious.helpers" + +return helpers.setcall(function (format, warg) + -- Do the processing and return a table here. +end) + +-- vim: filetype=lua:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:textwidth=80 diff --git a/widgets/bat_freebsd.lua b/widgets/bat_freebsd.lua index c6e743c..384f643 100644 --- a/widgets/bat_freebsd.lua +++ b/widgets/bat_freebsd.lua @@ -1,3 +1,22 @@ +-- battery 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 } diff --git a/widgets/bat_linux.lua b/widgets/bat_linux.lua index db81961..186c6e8 100644 --- a/widgets/bat_linux.lua +++ b/widgets/bat_linux.lua @@ -1,28 +1,38 @@ ---------------------------------------------------- --- Licensed under the GNU General Public License v2 --- * (c) 2010, Adrian C. --- * (c) 2013, NormalRa ---------------------------------------------------- +-- battery widget type for GNU/Linux +-- Copyright (C) 2010 Adrian C. +-- Copyright (C) 2013 NormalRa +-- Copyright (C) 2017 David Udelson +-- Copyright (C) 2017 Roberto +-- 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 setmetatable = setmetatable local string = { format = string.format } -local helpers = require("vicious.helpers") local math = { min = math.min, floor = math.floor } + +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) @@ -45,11 +55,11 @@ local function worker(format, warg) return {battery_state["Unknown\n"], 0, "N/A", 0, curpower} end - -- Get state information local state = battery_state[battery.status] or battery_state["Unknown\n"] -- Get capacity information + local remaining, capacity, capacity_design if battery.charge_now then remaining, capacity = battery.charge_now, battery.charge_full capacity_design = battery.charge_full_design or capacity @@ -64,8 +74,8 @@ local function worker(format, warg) local percent = math.min(math.floor(remaining / capacity * 100), 100) local wear = math.floor(100 - capacity / capacity_design * 100) - -- Get charge information + local rate if battery.current_now then rate = tonumber(battery.current_now) elseif battery.power_now then @@ -78,8 +88,9 @@ local function worker(format, warg) local time = "N/A" if rate ~= nil and rate ~= 0 then + local timeleft if state == "+" then - timeleft = (tonumber(capacity) - tonumber(remaining)) / tonumber(rate) + timeleft = (tonumber(capacity)-tonumber(remaining)) / tonumber(rate) elseif state == "-" then timeleft = tonumber(remaining) / tonumber(rate) else @@ -94,7 +105,5 @@ local function worker(format, warg) end return {state, percent, time, wear, curpower} -end +end) -- }}} - -return setmetatable(bat_linux, { __call = function(_, ...) return worker(...) end }) diff --git a/widgets/bat_openbsd.lua b/widgets/bat_openbsd.lua index 1c36228..fe7665d 100644 --- a/widgets/bat_openbsd.lua +++ b/widgets/bat_openbsd.lua @@ -1,6 +1,6 @@ --- bat_openbsd.lua - provide battery information on OpenBSD --- Copyright (C) 2019 Enric Morales --- Copyright (C) 2019 Nguyễn Gia Phong +-- battery widget type for OpenBSD +-- Copyright (C) 2019 Enric Morales +-- Copyright (C) 2019 Nguyễn Gia Phong -- -- This file is part of Vicious. -- @@ -12,9 +12,9 @@ -- 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 Affero General Public License for more details. +-- GNU General Public License for more details. -- --- You should have received a copy of the GNU Affero General Public License +-- You should have received a copy of the GNU General Public License -- along with Vicious. If not, see . -- {{{ Grab environment diff --git a/widgets/cmus_all.lua b/widgets/cmus_all.lua index 25c1a9a..e0b046e 100644 --- a/widgets/cmus_all.lua +++ b/widgets/cmus_all.lua @@ -1,7 +1,22 @@ ------------------------------------------------------------ --- Licensed under the GNU General Public License v2 --- * (c) 2017, JuanKman94 ------------------------------------------------------------ +-- cmus music player widget type +-- Copyright (C) 2017 JuanKman94 +-- Copyright (C) 2017 Joerg Thalheim +-- 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 diff --git a/widgets/cpu_freebsd.lua b/widgets/cpu_freebsd.lua index 972eca0..63809e9 100644 --- a/widgets/cpu_freebsd.lua +++ b/widgets/cpu_freebsd.lua @@ -1,3 +1,22 @@ +-- CPU 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 math = { floor = math.floor } local string = { gmatch = string.gmatch } @@ -5,7 +24,6 @@ local string = { gmatch = string.gmatch } local helpers = require("vicious.helpers") -- }}} - -- Cpu: provides CPU usage for all available CPUs/cores -- vicious.widgets.cpu_freebsd local cpu_freebsd = {} diff --git a/widgets/cpu_linux.lua b/widgets/cpu_linux.lua index 99ec1b2..c023400 100644 --- a/widgets/cpu_linux.lua +++ b/widgets/cpu_linux.lua @@ -1,35 +1,44 @@ ---------------------------------------------------- --- Licensed under the GNU General Public License v2 --- * (c) 2011, Adrian C. --- * (c) 2009, Lucas de Vries --- * (c) 2011, Jörg Thalheim ---------------------------------------------------- +-- CPU usage widget type for GNU/Linux +-- Copyright (C) 2009 Lucas de Vries +-- Copyright (C) 2011 Adrian C. +-- Copyright (C) 2011 Jörg Thalheim +-- 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 ipairs = ipairs local io = { open = io.open } -local setmetatable = setmetatable local math = { floor = math.floor } local table = { insert = table.insert } local string = { sub = string.sub, gmatch = string.gmatch } + +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 @@ -52,7 +61,6 @@ local function worker(format) cpu_active[i] = 0 end - for i, v in ipairs(cpu_lines) do -- Calculate totals local total_new = 0 @@ -74,7 +82,5 @@ local function worker(format) end return cpu_usage -end +end) -- }}} - -return setmetatable(cpu_linux, { __call = function(_, ...) return worker(...) end }) diff --git a/widgets/cpufreq_freebsd.lua b/widgets/cpufreq_freebsd.lua index 6acf2f0..ea20663 100644 --- a/widgets/cpufreq_freebsd.lua +++ b/widgets/cpufreq_freebsd.lua @@ -1,14 +1,31 @@ +-- CPU frequency 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 helpers = require("vicious.helpers") -- }}} - -- Cpufreq: provides freq, voltage and governor info for a requested CPU -- vicious.widgets.cpufreq local cpufreq_freebsd = {} - -- {{{ CPU frequency widget type function cpufreq_freebsd.async(format, warg, callback) if not warg then return callback({}) end diff --git a/widgets/cpufreq_linux.lua b/widgets/cpufreq_linux.lua index 4cac998..f3877e4 100644 --- a/widgets/cpufreq_linux.lua +++ b/widgets/cpufreq_linux.lua @@ -1,33 +1,41 @@ ---------------------------------------------------- --- Licensed under the GNU General Public License v2 --- * (c) 2010, Adrian C. ---------------------------------------------------- +-- CPU frequency 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 tonumber = tonumber -local setmetatable = setmetatable -local string = { match = string.match } 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"] = "⌁", + ["userspace\n"] = "¤", + ["performance\n"] = "⚡", + ["conservative\n"] = "⊚" +} -- {{{ 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("/sys/devices/system/cpu/"..warg.."/cpufreq") - local governor_state = { - ["ondemand\n"] = "↯", - ["powersave\n"] = "⌁", - ["userspace\n"] = "¤", - ["performance\n"] = "⚡", - ["conservative\n"] = "⊚" - } + local _cpufreq = helpers.pathtotable( + ("/sys/devices/system/cpu/%s/cpufreq"):format(warg)) -- Default frequency and voltage values local freqv = { ["mhz"] = "N/A", ["ghz"] = "N/A", @@ -43,7 +51,8 @@ local function worker(format, warg) -- Get the current voltage if _cpufreq.scaling_voltages then - freqv.mv = tonumber(string.match(_cpufreq.scaling_voltages, freq.."[%s]([%d]+)")) + freqv.mv = tonumber( + _cpufreq.scaling_voltages:match(freq .. "[%s]([%d]+)")) -- Calculate voltage from mV freqv.v = freqv.mv / 1000 end @@ -52,10 +61,8 @@ local function worker(format, warg) -- Get the current governor local governor = _cpufreq.scaling_governor -- Represent the governor as a symbol - governor = governor_state[governor] or governor or "N/A" + governor = GOVERNOR_STATE[governor] or governor or "N/A" return {freqv.mhz, freqv.ghz, freqv.mv, freqv.v, governor} -end +end) -- }}} - -return setmetatable(cpufreq_linux, { __call = function(_, ...) return worker(...) end }) diff --git a/widgets/cpuinf_linux.lua b/widgets/cpuinf_linux.lua index 11a7012..0df845f 100644 --- a/widgets/cpuinf_linux.lua +++ b/widgets/cpuinf_linux.lua @@ -1,23 +1,31 @@ ---------------------------------------------------- --- Licensed under the GNU General Public License v2 --- * (c) 2010, Adrian C. ---------------------------------------------------- +-- CPU information 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 tonumber = tonumber local io = { lines = io.lines } -local setmetatable = setmetatable 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 @@ -38,7 +46,5 @@ local function worker(format) end return cpu_info -end +end) -- }}} - -return setmetatable(cpuinf_linux, { __call = function(_, ...) return worker(...) end }) diff --git a/widgets/date_all.lua b/widgets/date_all.lua index afcf085..459d505 100644 --- a/widgets/date_all.lua +++ b/widgets/date_all.lua @@ -1,27 +1,29 @@ ---------------------------------------------------- --- Licensed under the GNU General Public License v2 --- * (c) 2010, Adrian C. --- * (c) 2009, Lucas de Vries ---------------------------------------------------- +-- date and time widget type using os.date with optional time formatting +-- Copyright (C) 2009 Lucas de Vries +-- Copyright (C) 2010 Adrian C. +-- 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 setmetatable = setmetatable -local os = { - date = os.date, - time = os.time -} +local os = { date = os.date, time = os.time } +local helpers = require"vicious.helpers" -- }}} - --- Date: provides access to os.date with optional time formatting --- vicious.widgets.date -local date_all = {} - - --- {{{ Date widget type -local function worker(format, warg) +return helpers.setcall(function (format, warg) return os.date(format or nil, warg and os.time()+warg or nil) -end --- }}} - -return setmetatable(date_all, { __call = function(_, ...) return worker(...) end }) +end) diff --git a/widgets/dio_linux.lua b/widgets/dio_linux.lua index 82fa50f..60c2343 100644 --- a/widgets/dio_linux.lua +++ b/widgets/dio_linux.lua @@ -1,26 +1,31 @@ ---------------------------------------------------- --- Licensed under the GNU General Public License v2 --- * (c) 2011, Jörg T. ---------------------------------------------------- +-- disk I/O widget type for GNU/Linux +-- Copyright (C) 2011 Jörg T. +-- Copyright (C) 2017 Elric Milon +-- 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 pairs = pairs local io = { lines = io.lines } -local setmetatable = setmetatable -local string = { match = string.match } -local helpers = require("vicious.helpers") -local os = { - time = os.time, - difftime = os.difftime -} +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 = {} @@ -30,13 +35,13 @@ 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 local device, read, write, iotime = -- Linux kernel documentation: Documentation/iostats.txt - string.match(line, "([^%s]+) %d+ %d+ (%d+) %d+ %d+ %d+ (%d+) %d+ %d+ (%d+)") + line:match"([^%s]+) %d+ %d+ (%d+) %d+ %d+ %d+ (%d+) %d+ %d+ (%d+)" disk_lines[device] = { read, write, iotime } end @@ -50,7 +55,7 @@ local function worker(format) -- Check for overflows and counter resets (> 2^32) if stats[1] < last_stats[1] or stats[2] < last_stats[2] then - last_stats[1], last_stats[2], last_stats[3] = stats[1], stats[2], stats[3] + for i = 1,3 do last_stats[i] = stats[i] end end -- Diskstats are absolute, substract our last reading @@ -70,7 +75,5 @@ local function worker(format) disk_stats = disk_lines return disk_usage -end +end) -- }}} - -return setmetatable(dio_linux, { __call = function(_, ...) return worker(...) end }) diff --git a/widgets/fanspeed_freebsd.lua b/widgets/fanspeed_freebsd.lua index a60b272..818a4ba 100644 --- a/widgets/fanspeed_freebsd.lua +++ b/widgets/fanspeed_freebsd.lua @@ -1,3 +1,22 @@ +-- fan speed 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 type = type @@ -5,7 +24,6 @@ local type = type local helpers = require("vicious.helpers") -- }}} - -- fanspeed: provides speed level of fans -- vicious.widgets.fanspeed -- diff --git a/widgets/fs_all.lua b/widgets/fs_all.lua index 9c4e5d0..e1c672d 100644 --- a/widgets/fs_all.lua +++ b/widgets/fs_all.lua @@ -1,8 +1,24 @@ ---------------------------------------------------- --- Licensed under the GNU General Public License v2 --- * (c) 2010, Adrian C. --- * (c) 2009, Lucas de Vries ---------------------------------------------------- +-- filesystem widget type +-- Copyright (C) 2009 Lucas de Vries +-- Copyright (C) 2010 Adrian C. +-- Copyright (C) 2017 Joerg Thalheim +-- 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 tonumber = tonumber diff --git a/widgets/gmail_all.lua b/widgets/gmail_all.lua index 7e897b8..f885104 100644 --- a/widgets/gmail_all.lua +++ b/widgets/gmail_all.lua @@ -1,7 +1,23 @@ ---------------------------------------------------- --- Licensed under the GNU General Public License v2 --- * (c) 2010, Adrian C. ---------------------------------------------------- +-- new e-mails count and last e-mail subject on Gmail +-- Copyright (C) 2010 Adrian C. +-- Copyright (C) 2017 mutlusun +-- Copyright (C) 2017 starenka +-- 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 +28,6 @@ local helpers = require("vicious.helpers") local spawn = require("vicious.spawn") -- }}} - -- Gmail: provides count of new and subject of last e-mail on Gmail -- vicious.widgets.gmail local gmail_all = {} diff --git a/widgets/hddtemp_linux.lua b/widgets/hddtemp_linux.lua index b381f2f..f3a11df 100644 --- a/widgets/hddtemp_linux.lua +++ b/widgets/hddtemp_linux.lua @@ -1,7 +1,22 @@ ---------------------------------------------------- --- Licensed under the GNU General Public License v2 --- * (c) 2010, Adrian C. ---------------------------------------------------- +-- hard drive temperatures widget type using hddtemp daemon +-- Copyright (C) 2010 Adrian C. +-- 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 tonumber = tonumber @@ -10,7 +25,6 @@ local helpers = require"vicious.helpers" local spawn = require"vicious.spawn" -- }}} - -- Hddtemp: provides hard drive temperatures using the hddtemp daemon -- vicious.widgets.hddtemp return helpers.setasyncall{ diff --git a/widgets/hwmontemp_linux.lua b/widgets/hwmontemp_linux.lua index 9182932..7631dc9 100644 --- a/widgets/hwmontemp_linux.lua +++ b/widgets/hwmontemp_linux.lua @@ -1,7 +1,21 @@ ----------------------------------------------------------------- --- Licensed under the GNU General Public License v2 --- (C) 2019, Alexander Koch ----------------------------------------------------------------- +-- widget type providing name-indexed temperatures from /sys/class/hwmon +-- Copyright (C) 2019 Alexander Koch +-- 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 . -- environment local type = type diff --git a/widgets/init.lua b/widgets/init.lua index 5d3b246..61b8590 100644 --- a/widgets/init.lua +++ b/widgets/init.lua @@ -1,5 +1,24 @@ +-- widget types initialization +-- Copyright (C) 2010 Adrian C. (anrxc) +-- Copyright (C) 2011,2012 Jörg Thalheim +-- Copyright (C) 2012 Arvydas Sidorenko +-- +-- 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 . +local setmetatable = setmetatable local wrequire = require("vicious.helpers").wrequire -widgets = { _NAME = "vicious.widgets" } -return setmetatable(widgets, {__index = wrequire}) +return setmetatable({ _NAME = "vicious.widgets" }, { __index = wrequire }) diff --git a/widgets/mbox_all.lua b/widgets/mbox_all.lua index 23ff475..d65fac8 100644 --- a/widgets/mbox_all.lua +++ b/widgets/mbox_all.lua @@ -1,41 +1,45 @@ ---------------------------------------------------- --- 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" -- {{{ Mailbox widget type -local function worker(format, warg) +return helpers.setcall(function (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 +50,6 @@ local function worker(format, warg) end end - return {subject} -end + return { subject } +end) -- }}} - -return setmetatable(mbox_all, { __call = function(_, ...) return worker(...) end }) diff --git a/widgets/mboxc_all.lua b/widgets/mboxc_all.lua index 8743ebb..ab33a0d 100644 --- a/widgets/mboxc_all.lua +++ b/widgets/mboxc_all.lua @@ -1,22 +1,29 @@ ---------------------------------------------------- --- 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) +return helpers.setcall(function (format, warg) if not warg then return end -- Initialize counters @@ -34,15 +41,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() @@ -52,7 +59,5 @@ local function worker(format, warg) count.new = count.total - count.old return {count.total, count.old, count.new} -end +end) -- }}} - -return setmetatable(mboxc_all, { __call = function(_, ...) return worker(...) end }) 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..318b51f 100644 --- a/widgets/mem_linux.lua +++ b/widgets/mem_linux.lua @@ -1,24 +1,33 @@ ---------------------------------------------------- --- 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) +return helpers.setcall(function () local _mem = { buf = {}, swp = {} } -- Get MEM info @@ -47,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 setmetatable(mem_linux, { __call = function(_, ...) return worker(...) end }) 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..612da4d 100644 --- a/widgets/net_linux.lua +++ b/widgets/net_linux.lua @@ -1,24 +1,31 @@ ---------------------------------------------------- --- 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 @@ -27,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 @@ -74,7 +81,5 @@ local function worker(format) end return args -end +end) -- }}} - -return setmetatable(net_linux, { __call = function(_, ...) return worker(...) end }) diff --git a/widgets/org_all.lua b/widgets/org_all.lua index 2fdbf23..b15fd16 100644 --- a/widgets/org_all.lua +++ b/widgets/org_all.lua @@ -1,62 +1,65 @@ ---------------------------------------------------- --- 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) +return helpers.setcall(function (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} -end + return { count.past, count.today, count.soon, count.future } +end) -- }}} - -return setmetatable(org_all, { __call = function(_, ...) return worker(...) end }) 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..a1528e5 100644 --- a/widgets/os_linux.lua +++ b/widgets/os_linux.lua @@ -1,27 +1,35 @@ ---------------------------------------------------- --- 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) +return helpers.setcall(function () local system = { ["ostype"] = "N/A", ["hostname"] = "N/A", @@ -54,8 +62,5 @@ local function worker(format) return {system["ostype"], system["osrelease"], system["username"], system["hostname"], system["entropy"], system["entropy_p"]} -end +end) -- }}} - -return setmetatable(os_linux, - { __call = function(_, ...) return worker(...) end }) 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..7b4d23f 100644 --- a/widgets/raid_linux.lua +++ b/widgets/raid_linux.lua @@ -1,30 +1,39 @@ ------------------------------------------------------ --- 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 = {} -- {{{ RAID widget type -local function worker(format, warg) +return helpers.setcall(function (format, warg) if not warg then return end mddev[warg] = { ["found"] = false, @@ -38,7 +47,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 +55,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 @@ -54,7 +63,5 @@ local function worker(format, warg) f:close() return {mddev[warg]["assigned"], mddev[warg]["active"]} -end +end) -- }}} - -return setmetatable(raid_linux, { __call = function(_, ...) return worker(...) end }) 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..7ac8e69 100644 --- a/widgets/thermal_linux.lua +++ b/widgets/thermal_linux.lua @@ -1,25 +1,32 @@ ---------------------------------------------------- --- 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) +return helpers.setcall(function (format, warg) if not warg then return end local zone = { -- Known temperature data sources @@ -43,7 +50,5 @@ local function worker(format, warg) end return {0} -end +end) -- }}} - -return setmetatable(thermal_linux, { __call = function(_, ...) return worker(...) end }) 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..7ff3580 100644 --- a/widgets/uptime_linux.lua +++ b/widgets/uptime_linux.lua @@ -1,24 +1,31 @@ ---------------------------------------------------- --- 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) +return helpers.setcall(function () local proc = helpers.pathtotable("/proc") -- Get system uptime @@ -28,9 +35,7 @@ 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 +end) -- }}} - -return setmetatable(uptime_linux, { __call = function(_, ...) return worker(...) end }) 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