diff options
author | Immae <immae@immae.eu> | 2014-06-16 22:05:26 +0200 |
---|---|---|
committer | Immae <immae@immae.eu> | 2014-06-16 22:05:26 +0200 |
commit | 9b96f7cb7a37e00044b068cbeb3027d559a4d9f7 (patch) | |
tree | fe47a8d2c70e232344d71648ae66ac835f6781ab | |
parent | 671fb38b7f0ee4168e2854fef26c02104dbc0153 (diff) | |
download | Monitor-9b96f7cb7a37e00044b068cbeb3027d559a4d9f7.tar.gz Monitor-9b96f7cb7a37e00044b068cbeb3027d559a4d9f7.tar.zst Monitor-9b96f7cb7a37e00044b068cbeb3027d559a4d9f7.zip |
- Added possibility to mark a line in red, using escape sequence `a la xterm`
- Possibility to force redraw of "oneshot" processes
- Bug correction: when the window size is too small (< 3), we asked for a
negative amount of lines from the buffer
-rw-r--r-- | TODO | 12 | ||||
-rw-r--r-- | monitor.rb | 24 | ||||
-rw-r--r-- | monitorrc | 8 |
3 files changed, 41 insertions, 3 deletions
@@ -9,3 +9,15 @@ | |||
9 | - Customization of window size | 9 | - Customization of window size |
10 | - ~Internationalization | 10 | - ~Internationalization |
11 | - Some bugs with scrolling | 11 | - Some bugs with scrolling |
12 | - Respect colors from command? | ||
13 | |||
14 | bugs: | ||
15 | monitor.rb:264:in `last': negative array size (ArgumentError) | ||
16 | from monitor.rb:264:in `yield' | ||
17 | from monitor.rb:157:in `print_buffer' | ||
18 | from monitor.rb:95:in `move_resize' | ||
19 | from monitor.rb:345:in `block in redraw_all' | ||
20 | from monitor.rb:344:in `each' | ||
21 | from monitor.rb:344:in `redraw_all' | ||
22 | from monitor.rb:389:in `<main>' | ||
23 | |||
@@ -152,6 +152,7 @@ class Buff_Win | |||
152 | end | 152 | end |
153 | 153 | ||
154 | def print_buffer() | 154 | def print_buffer() |
155 | #clear() | ||
155 | win_border() | 156 | win_border() |
156 | j = 1 | 157 | j = 1 |
157 | @buffer.yield(@win.getmaxy-2,@curr_offset) { |l,type| | 158 | @buffer.yield(@win.getmaxy-2,@curr_offset) { |l,type| |
@@ -185,12 +186,12 @@ class Buff_Win | |||
185 | end | 186 | end |
186 | end | 187 | end |
187 | 188 | ||
188 | def update() | 189 | def update(force=false) |
189 | if(@params['Type'] == 'continuous') | 190 | if(@params['Type'] == 'continuous') |
190 | proc_readlines() | 191 | proc_readlines() |
191 | end | 192 | end |
192 | if(@params['Type'] == 'oneshot') | 193 | if(@params['Type'] == 'oneshot') |
193 | if(Time.now - @last_update > @params['Periodic'].to_i) | 194 | if(force or (Time.now - @last_update > @params['Periodic'].to_i)) |
194 | @buffer.clear() | 195 | @buffer.clear() |
195 | spawn_proc() | 196 | spawn_proc() |
196 | end | 197 | end |
@@ -257,6 +258,7 @@ class Buffer | |||
257 | end | 258 | end |
258 | end | 259 | end |
259 | def yield(size,offset=0,&block) | 260 | def yield(size,offset=0,&block) |
261 | if(size < 0) then size = 0 end | ||
260 | range = Range.new(0,@current-1).to_a | 262 | range = Range.new(0,@current-1).to_a |
261 | if(@wrap) | 263 | if(@wrap) |
262 | range = Range.new(@current,@size-1).to_a + range | 264 | range = Range.new(@current,@size-1).to_a + range |
@@ -291,6 +293,18 @@ def read_ini() | |||
291 | end | 293 | end |
292 | 294 | ||
293 | def print_line(win, str, hscroll=0) | 295 | def print_line(win, str, hscroll=0) |
296 | revert_color = false | ||
297 | str[0,5].match(/\033\[3(.)m/) { |c| #Line starts with an escape sequence. We handle that `a la xterm` | ||
298 | Ncurses.init_pair(10, c[1].to_i, Ncurses::COLOR_BLACK) | ||
299 | win.attron(Ncurses.COLOR_PAIR(10)) | ||
300 | revert_color = true | ||
301 | str = str[5,str.length] | ||
302 | } | ||
303 | str = str.gsub("\011"," ") | ||
304 | #Any other control char is ignored and escaped | ||
305 | str = str.gsub(/[[:cntrl:]]/) { |m| | ||
306 | "^"+(m.ord + 64).chr | ||
307 | } | ||
294 | if(hscroll > 0) | 308 | if(hscroll > 0) |
295 | strcut = str[hscroll,str.length] | 309 | strcut = str[hscroll,str.length] |
296 | if(strcut.nil? or strcut.empty?) | 310 | if(strcut.nil? or strcut.empty?) |
@@ -306,6 +320,9 @@ def print_line(win, str, hscroll=0) | |||
306 | else | 320 | else |
307 | win.addstr(str[0,winlen-1]+"…") | 321 | win.addstr(str[0,winlen-1]+"…") |
308 | end | 322 | end |
323 | if(revert_color) | ||
324 | win.attroff(Ncurses.COLOR_PAIR(10)) | ||
325 | end | ||
309 | end | 326 | end |
310 | 327 | ||
311 | def make_bufwins(inifile) | 328 | def make_bufwins(inifile) |
@@ -345,6 +362,7 @@ begin | |||
345 | #Ncurses.stdscr.intrflush(false) # turn off flush-on-interrupt | 362 | #Ncurses.stdscr.intrflush(false) # turn off flush-on-interrupt |
346 | Ncurses.stdscr.keypad(true) # turn on keypad mode | 363 | Ncurses.stdscr.keypad(true) # turn on keypad mode |
347 | Ncurses.init_pair(1, Ncurses::COLOR_RED, Ncurses::COLOR_BLACK) | 364 | Ncurses.init_pair(1, Ncurses::COLOR_RED, Ncurses::COLOR_BLACK) |
365 | Ncurses.init_pair(10, Ncurses::COLOR_WHITE, Ncurses::COLOR_BLACK) | ||
348 | 366 | ||
349 | 367 | ||
350 | inifile = read_ini() | 368 | inifile = read_ini() |
@@ -369,6 +387,8 @@ begin | |||
369 | list.print_list(entry=entry) | 387 | list.print_list(entry=entry) |
370 | when 12 #ctrl+L | 388 | when 12 #ctrl+L |
371 | redraw_all(list,bufwins,cur_bufwin) | 389 | redraw_all(list,bufwins,cur_bufwin) |
390 | when 18 #ctrl+R | ||
391 | cur_bufwin.update(force=true) | ||
372 | when Ncurses::KEY_RESIZE | 392 | when Ncurses::KEY_RESIZE |
373 | redraw_all(list,bufwins,cur_bufwin) | 393 | redraw_all(list,bufwins,cur_bufwin) |
374 | when Ncurses::KEY_LEFT | 394 | when Ncurses::KEY_LEFT |
@@ -20,4 +20,10 @@ Periodic = 600 | |||
20 | Name = Fail2ban | 20 | Name = Fail2ban |
21 | Command = "fail2ban_check" | 21 | Command = "fail2ban_check" |
22 | Type = oneshot | 22 | Type = oneshot |
23 | Periodic = 60 | 23 | Periodic = 600 |
24 | |||
25 | [check_all] | ||
26 | Name = Check all | ||
27 | Command = "check_all" | ||
28 | Type = oneshot | ||
29 | Periodic = 3600 | ||