From 31d11931d1dbde78afbdc67ba2405f3e8e78369d Mon Sep 17 00:00:00 2001 From: Immae Date: Sun, 29 Jun 2014 23:34:44 +0200 Subject: [PATCH] Customization of window size --- .gitignore | 1 + TODO | 2 -- ini_read.rb | 15 ++++++++++++++- monitor.rb | 20 ++++++++++---------- monitorrc | 3 +++ windows.rb | 4 ++-- 6 files changed, 30 insertions(+), 15 deletions(-) create mode 100644 .gitignore diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..1377554 --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +*.swp diff --git a/TODO b/TODO index 2bb819c..923f280 100644 --- 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? diff --git a/ini_read.rb b/ini_read.rb index 9ae3f1b..41259d8 100644 --- a/ini_read.rb +++ b/ini_read.rb @@ -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 diff --git a/monitor.rb b/monitor.rb index 65df79f..c2a57f8 100644 --- a/monitor.rb +++ b/monitor.rb @@ -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 diff --git a/monitorrc b/monitorrc index 8bd4c4b..b4db9bc 100644 --- a/monitorrc +++ b/monitorrc @@ -1,3 +1,6 @@ +[global] +list_size = 50 + [journalctl_err] Name = Journalctl errors Command = "journalctl --full -f -p4" diff --git a/windows.rb b/windows.rb index 96a45b9..5d195dd 100644 --- a/windows.rb +++ b/windows.rb @@ -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) -- 2.41.0