Include notionflux in the main repo instead of its own submodule
[notion/jeffpc.git] / contrib / statusd / statusd_binclock.lua
bloba972618801be86edcbc18ccc4f4d291e4ed2eb16
1 -- Authors: Mario García H. <drosophila@nmental.com>
2 -- License: GPL, version 2
3 -- Last Changed: 2006-12-15
4 --
5 --------------------------------------------------------------------------------------
6 --
7 -- PURPOSE:
8 -- Binary clock for Ion3 in two posible formats:
9 --
10 --> Space waste: [0001:000111] and Alien Code: [ ..:" . ..]
11 -- (You can modify the characters of 'alien' template to get a good looking clock)
12 --
13 --> This is an example template (could be better): - -===^--- - I will explain it.
14 --
15 -- HOW TO READ:
16 -- In the "mono-character" Ion display, you need to read characters as : and =,
17 -- like two different characters: one at the top, one at the bottom.
19 -- In the example, equals are actually two different bars, one at the top and other
20 -- at the bottom. The little triangle (a square or some weird symbol if your font
21 -- doesn't support that character) represents a separator between hours and seconds so:
22 --
23 -- - Upper-left represents hours: 2^4 .. 2^0 in 12 hours format.
24 -- (4 characters from 'right to left' after separator)
25 -- - Bottom-left represents minutes: 2^6 ... 2^0
26 -- (6 characters from 'right to left' after separator)
27 -- - Right side, after separator, represents seconds: 2^6 ... 2^0
29 -- Every character on dots code (AKA: alien) can be replaced:
30 -- - Bottom character or symbol ["_"]
31 -- - Upper character
32 -- - Both characters [Example: "=" or ":" ]
33 -- - Separator character [Example: "^", "|"]
35 --
36 ------ USAGE: ----------------------------------------------------------------------
38 -- Put [%binclock_10] on $HOME/.ion3/cfg_statusbar.lua to get a beauty
39 -- [0110:101100] or [%binclock] to get an ugly [. .:' ].
40 -- By my side, I preffer the ugly dots and numbers character display.
41 --
42 -- It is relaxing for me to see the dots dancing so I added extra space to
43 -- show seconds. If you like that, don't forget to put this in settings:
44 -- binclock = { show_seconds = true } * See other options at the beggining
45 -- of the code.
46 --------------------------------------------------------------------------------------
47 --
48 -- LICENSE:
49 -- GPL2 Copyright(C)2006 Mario García H.
50 -- (See http://www.gnu.org/licenses/gpl.html to read complete license)
52 -- T.STAMP: Fri Dec 15 13:37:54 2006
54 -- VERSION: 0.1.c
56 -- DEPENDS: No dependencies.
58 -- INSECTS:
59 -- * On non UTF-8 environments, default values for separator symbol and
60 -- upper symbol are prone to not work. So, change them in settings please.
61 -- ** If you put the clock on the left corner the left black spaces will disapear,
62 -- use l_border (left border) or r_border characters in settings to avoid that.
64 -- LAST CHANGES:
65 -- 0.1 -> 0.1.c
66 -- [ Changed 'while' for 'repeat' (It is almost 5X faster)]
67 -- [ Removed 2 useless tables ]
68 -- [ Changed if then else statements for logical statements:
69 -- is more clean and goes a little faster]
70 -- [ Simplified some string concatenations (A real slow down on Lua code). ]
71 -- [ Some cleaning on this help text ]
73 -- CONTACT:
74 -- drosophila (at) nmental (dot) com
76 ----- SEE MORE DETAILED SETTINGS HERE: ---------------------------------------------
78 local defaults = {
79 update_interval = 2000,
80 show_seconds = true, -- EXAMPLES:
81 separator = "°" or string.char(176), -- "|", or "^",
82 r_border = "", -- "|", or ">"
83 l_border = "", -- "|", or "<"
84 top_sym = "¯" or string.char(175), -- string.char(183), if your locals are not UTF-8
85 low_sym = "-" or "_", -- ".",
86 both_sym = "=", -- ":",
87 empty_sym = [[ ]] or string.char(32), -- string.char(168) --> 164, 168, 176, 179 ??
88 color = "normal" -- "critical", "important", ...(white, red, green, etc.)
89 -- It is not color, just and alias for alarm-types.
91 local settings = table.join(statusd.get_config("binclock"), defaults)
92 -------------------------------------------------------------------------------------
94 local binary_timer
95 local pattern = {}
98 local function convert_time() --> Six cycles to get binary
99 pattern = {}
100 local hours, minutes, seconds =--
101 tonumber(os.date("%I")), tonumber(os.date("%M")), tonumber(os.date("%S"))
102 local i, j = 32, 1
104 repeat
105 pattern[j] = hours >=i and 1 or 0
106 pattern[j + 7] = minutes >=i and 1 or 0
107 pattern[j + 14] = seconds >=i and 1 or 0
108 hours = hours >= i and hours - i or hours
109 minutes = minutes >= i and minutes - i or minutes
110 seconds = seconds >= i and seconds - i or seconds
111 i, j = i/2, j + 1
112 until j == 7
114 pattern[7], pattern[14] = settings.separator, settings.separator
118 local function inform_dots() --> Six extra cycles to get alien chars aligned
119 local dots, dots_s = "", ""
121 for i = 1, 6, 1 do
122 dots = pattern[i] == 1 and pattern[i+7] == 1 and dots..settings.both_sym or
123 pattern[i] == 1 and pattern[i+7] == 0 and dots..settings.top_sym or
124 pattern[i] == 0 and pattern[i+7] == 1 and dots..settings.low_sym or
125 dots..settings.empty_sym
127 dots_s = pattern[i+14] == 1 and dots_s..settings.low_sym or
128 dots_s..settings.empty_sym
131 if not settings.show_seconds then
132 statusd.inform("binclock", dots)
133 statusd.inform("binclock_hint", settings.color)
134 else
135 statusd.inform("binclock", settings.l_border..dots..settings.separator..--
136 dots_s..settings.r_border)
137 statusd.inform("binclock_hint", settings.color)
142 local function inform_ceros()
143 if not settings.show_seconds then
144 statusd.inform("binclock_10", table.concat(pattern, "", 3, 14))
145 statusd.inform("binclock_10_hint", settings.color)
146 else
147 statusd.inform("binclock_10", table.concat(pattern, "", 3))
148 statusd.inform("binclock_10_hint", settings.color)
153 local function update_binary()
154 convert_time()
155 inform_ceros()
156 inform_dots()
157 binary_timer:set(settings.update_interval, update_binary)
160 binary_timer = statusd.create_timer()
161 update_binary()