]> git.immae.eu Git - perso/Immae/Projets/Ruby/Monitor.git/commitdiff
Customization of window size master
authorImmae <ismael.bouya@normalesup.org>
Sun, 29 Jun 2014 21:34:44 +0000 (23:34 +0200)
committerImmae <ismael.bouya@normalesup.org>
Sun, 29 Jun 2014 21:34:44 +0000 (23:34 +0200)
.gitignore [new file with mode: 0644]
TODO
ini_read.rb
monitor.rb
monitorrc
windows.rb

diff --git a/.gitignore b/.gitignore
new file mode 100644 (file)
index 0000000..1377554
--- /dev/null
@@ -0,0 +1 @@
+*.swp
diff --git a/TODO b/TODO
index 2bb819c3003aa64fadee115b8326281731a340b0..923f280a0e172f7236497f9651d2aaa91d405f26 100644 (file)
--- a/TODO
+++ b/TODO
@@ -3,8 +3,6 @@
 - keep previous buffers for oneshot commands
 - custom key bindings (and informations in the window)
 - Man file
-- Check correctness of entries in config file (and capitalization)
-- Customization of window size
 - ~Internationalization
 - Respect colors from command?
 
index 9ae3f1ba2a70a47bbd5bb291b272e6781325b42d..41259d88117b3e0879b2beec79ffaeeb025b0efe 100644 (file)
@@ -32,6 +32,7 @@ class Ini_read
     find_ini(options.inifile)
     read_ini()
     parse_config()
+    parse_global()
   end
 
   def find_ini(option_inifile)
@@ -47,7 +48,7 @@ class Ini_read
   end
 
   def read_ini()
-    @config = IniFile.load(@inifile, :default=>'global')
+    @config = IniFile.load(@inifile, :default => 'global')
     if(@config.nil?)
       puts "Initialization file not found or not readable"
       exit
@@ -65,6 +66,7 @@ class Ini_read
       sec = @config[section]
       if(section == "global")
         @global = sec
+        next
       end
       if(not sec.has_key?('Type'))
         puts "Section incomplete, ignored: "+ section
@@ -87,5 +89,16 @@ class Ini_read
     end
   end
 
+  def parse_global()
+    if(@global.has_key?('list_size'))
+      @global['list_size'] = @global['list_size'].to_i
+      if(@global['list_size'] == 0)
+        @global['list_size'] = 25
+      end
+    else
+      @global['list_size'] = 25
+    end
+  end
+
 end
 
index 65df79f7028deab8de7201daed4f88405acd4967..c2a57f899ff6066cd7a2b8322112ab8a7c09a092 100644 (file)
@@ -5,11 +5,11 @@ require_relative 'ini_read'
 require_relative 'windows'
 require_relative 'buffer'
 
-def make_bufwins(sections)
+def make_bufwins(sections,size)
   bufwins = []
   sections.each { |section_name,section|
-    bufwin = Buff_Win.new(Ncurses.COLS()-Ncurses.COLS()/4,
-                           Ncurses.COLS()/4,
+    bufwin = Buff_Win.new(Ncurses.COLS()-size*Ncurses.COLS()/100,
+                           size*Ncurses.COLS()/100,
                            section)
     bufwins.push(bufwin)
   }
@@ -22,11 +22,11 @@ def update_buffers(bufwins)
   end
 end
 
-def redraw_all(list,bufwins,curr_bufwin)
+def redraw_all(list,bufwins,curr_bufwin, size)
   bufwins.each do |bufwin|
-    bufwin.move_resize(Ncurses.COLS()-Ncurses.COLS()/4,Ncurses.COLS()/4)
+    bufwin.move_resize(Ncurses.COLS()-size*Ncurses.COLS()/100,size*Ncurses.COLS()/100)
   end
-  list.resize(Ncurses.LINES(), Ncurses.COLS()/4)
+  list.resize(Ncurses.LINES(), size*Ncurses.COLS()/100)
   list.clear()
   list.print_list()
   list.refresh()
@@ -48,8 +48,8 @@ begin
   Ncurses.init_pair(10, Ncurses::COLOR_WHITE,   Ncurses::COLOR_BLACK)
 
 
-  list = List_Win.new(inistruct.sections)
-  bufwins = make_bufwins(inistruct.sections)
+  list = List_Win.new(inistruct.sections, inistruct.global['list_size'])
+  bufwins = make_bufwins(inistruct.sections, inistruct.global['list_size'])
   entry = 0
   cur_bufwin = bufwins[entry]
   cur_bufwin.show_win()
@@ -67,11 +67,11 @@ begin
       cur_bufwin.show_win()
       list.print_list(entry=entry)
     when 12 #ctrl+L
-      redraw_all(list,bufwins,cur_bufwin)
+      redraw_all(list,bufwins,cur_bufwin, inistruct.global['list_size'])
     when 18 #ctrl+R
       cur_bufwin.update(force=true)
     when Ncurses::KEY_RESIZE
-      redraw_all(list,bufwins,cur_bufwin)
+      redraw_all(list,bufwins,cur_bufwin, inistruct.global['list_size'])
     when Ncurses::KEY_LEFT
       cur_bufwin.hscroll(scroll=-1)
     when Ncurses::KEY_RIGHT
index 8bd4c4bbd01a1a49649091ad00d848e2deaa2bb6..b4db9bcb027002ce2ce23562e28d70c23c8d4ea1 100644 (file)
--- a/monitorrc
+++ b/monitorrc
@@ -1,3 +1,6 @@
+[global]
+list_size = 50
+
 [journalctl_err]
 Name = Journalctl errors
 Command = "journalctl --full -f -p4"
index 96a45b94d6c81a3adaf8d6944ce36a45e7b669dc..5d195dd3edaa49be7d62d6ef5f7b6939a899ca3a 100644 (file)
@@ -52,9 +52,9 @@ end
 
 
 class List_Win
-  def initialize(sections)
+  def initialize(sections, size)
     @params = sections
-    @win = Ncurses::WINDOW.new(0, Ncurses.COLS()/4, 0, 0)
+    @win = Ncurses::WINDOW.new(0, size*Ncurses.COLS()/100, 0, 0)
     @win.border(*([0]*8))
     @win.keypad(true)
     @win.timeout(1000)