| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
local string = { |
| 7 |
format = string.format |
| 8 |
} |
| 9 |
local lib = { |
| 10 |
widget = require("obvious.lib.widget"), |
| 11 |
markup = require("obvious.lib.markup"), |
| 12 |
wlan = require("obvious.lib.wlan") |
| 13 |
} |
| 14 |
|
| 15 |
local function format_percent(link) |
| 16 |
local color = "#009000" |
| 17 |
if link < 50 and link > 10 then |
| 18 |
color = "#909000" |
| 19 |
elseif link <= 10 then |
| 20 |
color = "#900000" |
| 21 |
end |
| 22 |
return lib.markup.fg.color(color,"☢") .. string.format(" %03d%%", link) |
| 23 |
end |
| 24 |
|
| 25 |
local function get_data_source(device) |
| 26 |
local device = device |
| 27 |
if device == "auto" then |
| 28 |
device = lib.wlan.find_first_wlan() |
| 29 |
end |
| 30 |
device = device or "wlan0" |
| 31 |
|
| 32 |
local data = {} |
| 33 |
|
| 34 |
data.device = device |
| 35 |
data.max = 100 |
| 36 |
data.get = function (obj) |
| 37 |
return lib.wlan(obj.device) |
| 38 |
end |
| 39 |
|
| 40 |
local ret = lib.widget.from_data_source(data) |
| 41 |
|
| 42 |
|
| 43 |
ret:set_type("textbox") |
| 44 |
ret:set_format(format_percent) |
| 45 |
|
| 46 |
return ret |
| 47 |
end |
| 48 |
|
| 49 |
return setmetatable({}, { __call = function (_, ...) return get_data_source(...) end }) |
| 50 |
|
| 51 |
|