File: init.lua

package info (click to toggle)
awesome-extra 2020122801
  • links: PTS, VCS
  • area: main
  • in suites: bullseye
  • size: 1,328 kB
  • sloc: cpp: 112; sh: 84; makefile: 25; python: 11
file content (51 lines) | stat: -rw-r--r-- 1,257 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
49
50
51
--------------------------------------------
-- Author: Gregor Best                    --
-- Copyright 2009, 2010, 2011 Gregor Best --
--------------------------------------------

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

local function format_percent(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
  if device == "auto" then
    device = lib.wlan.find_first_wlan()
  end
  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_percent)

  return ret
end

return setmetatable({}, { __call = function (_, ...) return get_data_source(...) end })

-- vim:ft=lua:ts=2:sw=2:sts=2:tw=80:et