Clean up spawn and widget types using it
This commit is contained in:
parent
5a0573ebef
commit
1d96075f6c
13
Changes.md
13
Changes.md
|
@ -1,3 +1,16 @@
|
|||
Feature:
|
||||
|
||||
- Add `spawn.lua` as a fallback for `awful.spawn` in case Vicious is used as
|
||||
a stand-alone library. This wrapper, however, does NOT provide the facilities
|
||||
to asynchronously spawn new processes. It also lacks a few features such as
|
||||
parsing `stderr` and returning PID.
|
||||
|
||||
Fixes:
|
||||
|
||||
- [mpd] Lua 5.3 compatibility (for real this time); also correct a typo
|
||||
- [pkg,weather,contrib/btc] Allow function call without Awesome
|
||||
- [pkg] Use more updated front-ends for Debian/Ubuntu (apt) and Fedora (dnf)
|
||||
|
||||
# Changes in 2.3.3
|
||||
|
||||
Feature: Add battery widget type for OpenBSD
|
||||
|
|
|
@ -52,7 +52,9 @@ local spawn = {}
|
|||
-- @treturn boolean|nil true if cmd terminated successfully, or nil otherwise
|
||||
function spawn.with_line_callback_with_shell(cmd, callbacks)
|
||||
local stdout_callback, stdout = callbacks.stdout, io.popen(cmd)
|
||||
for line in stdout:lines() do stdout_callback(line) end
|
||||
if stdout_callback then
|
||||
for line in stdout:lines() do stdout_callback(line) end
|
||||
end
|
||||
if callbacks.output_done then callbacks.output_done() end
|
||||
|
||||
local success, reason, code = stdout:close() -- this requires Lua 5.2
|
||||
|
|
|
@ -4,8 +4,6 @@
|
|||
---------------------------------------------------
|
||||
|
||||
-- {{{ Grab environment
|
||||
local io = { popen = io.popen }
|
||||
local math = { max = math.max }
|
||||
local setmetatable = setmetatable
|
||||
local spawn = require("vicious.spawn")
|
||||
-- }}}
|
||||
|
|
|
@ -5,15 +5,12 @@
|
|||
|
||||
-- {{{ Grab environment
|
||||
local tonumber = tonumber
|
||||
local io = { popen = io.popen }
|
||||
local setmetatable = setmetatable
|
||||
local math = { ceil = math.ceil }
|
||||
local string = { match = string.match }
|
||||
|
||||
-- Awesome library for spawning programs
|
||||
local spawn = require"vicious.spawn"
|
||||
|
||||
local helpers = require("vicious.helpers")
|
||||
local helpers = require"vicious.helpers"
|
||||
-- }}}
|
||||
|
||||
|
||||
|
@ -23,7 +20,7 @@ local weather_all = {}
|
|||
|
||||
|
||||
-- {{{ Weather widget type
|
||||
local function parse(ws)
|
||||
local function parse(stdout, stderr, exitreason, exitcode)
|
||||
-- Initialize function tables
|
||||
local _weather = {
|
||||
["{city}"] = "N/A",
|
||||
|
@ -41,26 +38,26 @@ local function parse(ws)
|
|||
}
|
||||
|
||||
-- Check if there was a timeout or a problem with the station
|
||||
if ws == '' then return _weather end
|
||||
if stdout == '' then return _weather end
|
||||
|
||||
_weather["{city}"] = -- City and/or area
|
||||
string.match(ws, "^(.+)%,.*%([%u]+%)") or _weather["{city}"]
|
||||
string.match(stdout, "^(.+)%,.*%([%u]+%)") or _weather["{city}"]
|
||||
_weather["{wind}"] = -- Wind direction and degrees if available
|
||||
string.match(ws, "Wind:[%s][%a]+[%s][%a]+[%s](.+)[%s]at.+$") or _weather["{wind}"]
|
||||
string.match(stdout, "Wind:[%s][%a]+[%s][%a]+[%s](.+)[%s]at.+$") or _weather["{wind}"]
|
||||
_weather["{windmph}"] = -- Wind speed in MPH if available
|
||||
string.match(ws, "Wind:[%s].+[%s]at[%s]([%d]+)[%s]MPH") or _weather["{windmph}"]
|
||||
string.match(stdout, "Wind:[%s].+[%s]at[%s]([%d]+)[%s]MPH") or _weather["{windmph}"]
|
||||
_weather["{sky}"] = -- Sky conditions if available
|
||||
string.match(ws, "Sky[%s]conditions:[%s](.-)[%c]") or _weather["{sky}"]
|
||||
string.match(stdout, "Sky[%s]conditions:[%s](.-)[%c]") or _weather["{sky}"]
|
||||
_weather["{weather}"] = -- Weather conditions if available
|
||||
string.match(ws, "Weather:[%s](.-)[%c]") or _weather["{weather}"]
|
||||
string.match(stdout, "Weather:[%s](.-)[%c]") or _weather["{weather}"]
|
||||
_weather["{tempf}"] = -- Temperature in fahrenheit
|
||||
string.match(ws, "Temperature:[%s]([%-]?[%d%.]+).*[%c]") or _weather["{tempf}"]
|
||||
string.match(stdout, "Temperature:[%s]([%-]?[%d%.]+).*[%c]") or _weather["{tempf}"]
|
||||
_weather["{dewf}"] = -- Dew Point in fahrenheit
|
||||
string.match(ws, "Dew[%s]Point:[%s]([%-]?[%d%.]+).*[%c]") or _weather["{dewf}"]
|
||||
string.match(stdout, "Dew[%s]Point:[%s]([%-]?[%d%.]+).*[%c]") or _weather["{dewf}"]
|
||||
_weather["{humid}"] = -- Relative humidity in percent
|
||||
string.match(ws, "Relative[%s]Humidity:[%s]([%d]+)%%") or _weather["{humid}"]
|
||||
string.match(stdout, "Relative[%s]Humidity:[%s]([%d]+)%%") or _weather["{humid}"]
|
||||
_weather["{press}"] = -- Pressure in hPa
|
||||
string.match(ws, "Pressure[%s].+%((.+)[%s]hPa%)") or _weather["{press}"]
|
||||
string.match(stdout, "Pressure[%s].+%((.+)[%s]hPa%)") or _weather["{press}"]
|
||||
|
||||
-- Wind speed in km/h if MPH was available
|
||||
if _weather["{windmph}"] ~= "N/A" then
|
||||
|
@ -91,8 +88,8 @@ 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 cmd = "curl -fs " .. url
|
||||
spawn.easy_async(cmd, function (stdout) callback(parse(stdout)) end)
|
||||
spawn.easy_async("curl -fs " .. url,
|
||||
function (...) callback(parse(...)) end)
|
||||
end
|
||||
|
||||
local function worker(format, warg)
|
||||
|
|
Loading…
Reference in New Issue