Debian Codegraph @

obvious/wlan/init.lua

raw symbols SCIP
1 --------------------------------------------
2 -- Author: Gregor Best --
3 -- Copyright 2009, 2010, 2011 Gregor Best --
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 -- Due to historic reasons, this widget defaults to a textbox with
42 -- a "special" format.
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 -- vim:ft=lua:ts=2:sw=2:sts=2:tw=80:et