File: init.lua

package info (click to toggle)
awesome-extra 2010071402
  • links: PTS
  • area: main
  • in suites: squeeze
  • size: 488 kB
  • ctags: 319
  • sloc: makefile: 40
file content (48 lines) | stat: -rw-r--r-- 1,262 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
--------------------------------
-- Author: Gregor Best        --
-- Copyright 2009 Gregor Best --
--------------------------------

local string = {
    format = string.format
}
local setmetatable = setmetatable
local lib = {
    widget = require("obvious.lib.widget"),
    markup = require("obvious.lib.markup"),
    wlan   = require("obvious.lib.wlan")
}

module("obvious.wlan")

local function format(link)
    local color = "#009000"
    if link < 50 and link > 10 then
        color = "#909000"
    elseif link <= 10 then
        color = "#900000"
    end
    return lib.markup.fg.color(color,"☢") .. string.format(" %03d%%", link)
end

local function get_data_source(device)
    local device = device or "wlan0"
    local data = {}

    data.device = device
    data.max = 100
    data.get = function (obj)
        return lib.wlan(obj.device)
    end

    local ret = lib.widget.from_data_source(data)
    -- Due to historic reasons, this widget defaults to a textbox with
    -- a "special" format.
    ret:set_type("textbox")
    ret:set_format(format)

    return ret
end

setmetatable(_M, { __call = function (_, ...) return get_data_source(...) end })
-- vim: filetype=lua:expandtab:shiftwidth=4:tabstop=4:softtabstop=4:encoding=utf-8:textwidth=80