aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--TODO14
-rw-r--r--monitor.rb50
2 files changed, 49 insertions, 15 deletions
diff --git a/TODO b/TODO
index 71df334..767b4e2 100644
--- a/TODO
+++ b/TODO
@@ -1,5 +1,4 @@
1- sudo commands (ask for password) 1- sudo commands (ask for password)
2- config in different places
3- adding/removing entries directly from the program 2- adding/removing entries directly from the program
4- keep previous buffers for oneshot commands 3- keep previous buffers for oneshot commands
5- custom key bindings (and informations in the window) 4- custom key bindings (and informations in the window)
@@ -8,16 +7,9 @@
8- Key to force window update 7- Key to force window update
9- Customization of window size 8- Customization of window size
10- ~Internationalization 9- ~Internationalization
11- Some bugs with scrolling
12- Respect colors from command? 10- Respect colors from command?
13 11
14bugs: 12Bugs:
15monitor.rb:264:in `last': negative array size (ArgumentError) 13- Some bugs with scrolling
16 from monitor.rb:264:in `yield' 14
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 15
diff --git a/monitor.rb b/monitor.rb
index 249e2a3..09f9e59 100644
--- a/monitor.rb
+++ b/monitor.rb
@@ -4,6 +4,8 @@ require "time"
4require "ncurses" 4require "ncurses"
5require "inifile" 5require "inifile"
6require "open3" 6require "open3"
7require 'optparse'
8require 'ostruct'
7 9
8class IO 10class IO
9 def readline_nonblock 11 def readline_nonblock
@@ -18,6 +20,26 @@ class IO
18 end 20 end
19end 21end
20 22
23class OptParse
24 def parse(args)
25
26 options = OpenStruct.new()
27 options.inifile = nil
28
29 opt_parser = OptionParser.new() do |opts|
30
31 opts.banner = "Usage: monitor [options]"
32 opts.separator ""
33
34 opts.on( '-f', "-f ini_file", "chose a different initialization file") do |ini|
35 options.inifile = ini
36 end
37 end
38 opt_parser.parse!(args)
39 return options
40 end
41end
42
21class List_Win 43class List_Win
22 def initialize(inifile) 44 def initialize(inifile)
23 @params = inifile 45 @params = inifile
@@ -194,6 +216,7 @@ class Buff_Win
194 if(force or (Time.now - @last_update > @params['Periodic'].to_i)) 216 if(force or (Time.now - @last_update > @params['Periodic'].to_i))
195 @buffer.clear() 217 @buffer.clear()
196 spawn_proc() 218 spawn_proc()
219 clear()
197 end 220 end
198 end 221 end
199 print_buffer() 222 print_buffer()
@@ -287,8 +310,25 @@ class Buffer
287 end 310 end
288end 311end
289 312
290def read_ini() 313def find_ini(option_inifile)
291 inifile = IniFile.load('monitorrc') 314 if(not option_inifile.nil?)
315 inifile = option_inifile
316 elsif(ENV.has_key?('MONITOR_RC'))
317 inifile = ENV['MONITOR_RC']
318 elsif(Process.uid == 0)
319 inifile = "/etc/monitor.rc"
320 else
321 inifile = ENV['HOME']+"/.monitorrc"
322 end
323 return inifile
324end
325
326def read_ini(ini)
327 inifile = IniFile.load(ini)
328 if(inifile.nil?)
329 puts "Initialization file not found or not readable"
330 exit
331 end
292 return inifile 332 return inifile
293end 333end
294 334
@@ -352,6 +392,10 @@ def redraw_all(list,bufwins,curr_bufwin)
352 list.refresh() 392 list.refresh()
353 curr_bufwin.refresh() 393 curr_bufwin.refresh()
354end 394end
395
396
397options = OptParse.new().parse(ARGV)
398inifile = read_ini(find_ini(options.inifile))
355begin 399begin
356 # initialize ncurses 400 # initialize ncurses
357 Ncurses.initscr 401 Ncurses.initscr
@@ -365,8 +409,6 @@ begin
365 Ncurses.init_pair(10, Ncurses::COLOR_WHITE, Ncurses::COLOR_BLACK) 409 Ncurses.init_pair(10, Ncurses::COLOR_WHITE, Ncurses::COLOR_BLACK)
366 410
367 411
368 inifile = read_ini()
369
370 list = List_Win.new(inifile) 412 list = List_Win.new(inifile)
371 bufwins = make_bufwins(inifile) 413 bufwins = make_bufwins(inifile)
372 entry = 0 414 entry = 0