]> git.immae.eu Git - perso/Immae/Projets/Ruby/Monitor.git/commitdiff
- Added possibility to mark a line in red, using escape sequence `a la xterm`
authorImmae <immae@immae.eu>
Mon, 16 Jun 2014 20:05:26 +0000 (22:05 +0200)
committerImmae <immae@immae.eu>
Mon, 16 Jun 2014 20:05:26 +0000 (22:05 +0200)
- 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

TODO
monitor.rb
monitorrc

diff --git a/TODO b/TODO
index bf802cef65d52c18caad88c82456867ba55f0053..71df334f5fb3ff8fa0f6b31f9873f0f45fb8ae7a 100644 (file)
--- a/TODO
+++ b/TODO
@@ -9,3 +9,15 @@
 - Customization of window size
 - ~Internationalization
 - Some bugs with scrolling
+- Respect colors from command?
+
+bugs:
+monitor.rb:264:in `last': negative array size (ArgumentError)
+        from monitor.rb:264:in `yield'
+        from monitor.rb:157:in `print_buffer'
+        from monitor.rb:95:in `move_resize'
+        from monitor.rb:345:in `block in redraw_all'
+        from monitor.rb:344:in `each'
+        from monitor.rb:344:in `redraw_all'
+        from monitor.rb:389:in `<main>'
+
index 5e32cf28f2d5f83e66e42763f84d50193fc80f87..249e2a3c7d63cfb93f1f66ff0a5ff8a043ad176d 100644 (file)
@@ -152,6 +152,7 @@ class Buff_Win
   end
 
   def print_buffer()
+    #clear()
     win_border()
     j = 1
     @buffer.yield(@win.getmaxy-2,@curr_offset) { |l,type|
@@ -185,12 +186,12 @@ class Buff_Win
     end
   end
 
-  def update()
+  def update(force=false)
     if(@params['Type'] == 'continuous')
       proc_readlines()
     end
     if(@params['Type'] == 'oneshot')
-      if(Time.now - @last_update > @params['Periodic'].to_i)
+      if(force or (Time.now - @last_update > @params['Periodic'].to_i))
         @buffer.clear()
         spawn_proc()
       end
@@ -257,6 +258,7 @@ class Buffer
     end
   end
   def yield(size,offset=0,&block)
+    if(size < 0) then size = 0 end
     range = Range.new(0,@current-1).to_a
     if(@wrap)
       range = Range.new(@current,@size-1).to_a + range
@@ -291,6 +293,18 @@ def read_ini()
 end
 
 def print_line(win, str, hscroll=0)
+  revert_color = false
+  str[0,5].match(/\033\[3(.)m/) { |c| #Line starts with an escape sequence. We handle that `a la xterm`
+    Ncurses.init_pair(10, c[1].to_i,   Ncurses::COLOR_BLACK)
+    win.attron(Ncurses.COLOR_PAIR(10))
+    revert_color = true
+    str = str[5,str.length]
+  }
+  str = str.gsub("\011","    ")
+  #Any other control char is ignored and escaped
+  str = str.gsub(/[[:cntrl:]]/) { |m|
+    "^"+(m.ord + 64).chr
+  }
   if(hscroll > 0)
     strcut = str[hscroll,str.length]
     if(strcut.nil? or strcut.empty?)
@@ -306,6 +320,9 @@ def print_line(win, str, hscroll=0)
   else
     win.addstr(str[0,winlen-1]+"…")
   end
+  if(revert_color)
+    win.attroff(Ncurses.COLOR_PAIR(10))
+  end
 end
 
 def make_bufwins(inifile)
@@ -345,6 +362,7 @@ begin
   #Ncurses.stdscr.intrflush(false) # turn off flush-on-interrupt
   Ncurses.stdscr.keypad(true)     # turn on keypad mode
   Ncurses.init_pair(1, Ncurses::COLOR_RED,   Ncurses::COLOR_BLACK)
+  Ncurses.init_pair(10, Ncurses::COLOR_WHITE,   Ncurses::COLOR_BLACK)
 
 
   inifile = read_ini()
@@ -369,6 +387,8 @@ begin
       list.print_list(entry=entry)
     when 12 #ctrl+L
       redraw_all(list,bufwins,cur_bufwin)
+    when 18 #ctrl+R
+      cur_bufwin.update(force=true)
     when Ncurses::KEY_RESIZE
       redraw_all(list,bufwins,cur_bufwin)
     when Ncurses::KEY_LEFT
index 991714ad7605aee48948a69aef51d0b5c3ebaeb8..8bd4c4bbd01a1a49649091ad00d848e2deaa2bb6 100644 (file)
--- a/monitorrc
+++ b/monitorrc
@@ -20,4 +20,10 @@ Periodic = 600
 Name = Fail2ban
 Command = "fail2ban_check"
 Type = oneshot
-Periodic = 60
+Periodic = 600
+
+[check_all]
+Name = Check all
+Command = "check_all"
+Type = oneshot
+Periodic = 3600