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 (59 lines) | stat: -rw-r--r-- 1,390 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
52
53
54
55
56
57
58
59
-----------------------------------
-- Author: Eligio Becerra        --
-- Copyright 2009 Eligio Becerra --
-----------------------------------

local awful = require("awful")
local setmetatable = setmetatable
local tonumber = tonumber
local table = {
   insert = table.insert
}
local capi = {
   widget = widget
}
local lib = {
   markup = require("obvious.lib.markup"),
   hooks = require("obvious.lib.hooks")
}

module("obvious.temp_info")

local widget = capi.widget({ type = "textbox" })

local colors = {
   ["normal"] = "#009000",
   ["warm"] = "#909000",
   ["hot"] = "#900000"
}

local function update()
   local d = awful.util.pread("acpi -t")
   local temp = { }
   for t in d:gmatch("Thermal %d+: %w+, (%d+.?%d*) degrees") do
      table.insert(temp, t)
   end

   local color = colors["hot"]
   if not temp[1] then
      widget.text = "no data"
      return
   end
   if tonumber(temp[1]) < 50 then
      color = colors["normal"]
   elseif tonumber(temp[1]) >= 50 and tonumber(temp[1]) < 60 then
      color = colors["warm"]
   end
   widget.text = temp[1] .. " " .. lib.markup.fg.color(color, "C")
end
update()

lib.hooks.timer.register(5, 30, update)
lib.hooks.timer.stop(update)

setmetatable(_M, { __call = function ()
   lib.hooks.timer.start(update)
   return widget
end })

-- vim: filetype=lua:expandtab:shiftwidth=3:tabstop=3:softtabstop=3:encoding=utf-8:textwidth=80