diff options
-rw-r--r-- | TODO | 14 | ||||
-rw-r--r-- | monitor.rb | 50 |
2 files changed, 49 insertions, 15 deletions
@@ -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 | ||
14 | bugs: | 12 | Bugs: |
15 | monitor.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 | ||
@@ -4,6 +4,8 @@ require "time" | |||
4 | require "ncurses" | 4 | require "ncurses" |
5 | require "inifile" | 5 | require "inifile" |
6 | require "open3" | 6 | require "open3" |
7 | require 'optparse' | ||
8 | require 'ostruct' | ||
7 | 9 | ||
8 | class IO | 10 | class IO |
9 | def readline_nonblock | 11 | def readline_nonblock |
@@ -18,6 +20,26 @@ class IO | |||
18 | end | 20 | end |
19 | end | 21 | end |
20 | 22 | ||
23 | class 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 | ||
41 | end | ||
42 | |||
21 | class List_Win | 43 | class 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 |
288 | end | 311 | end |
289 | 312 | ||
290 | def read_ini() | 313 | def 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 | ||
324 | end | ||
325 | |||
326 | def 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 |
293 | end | 333 | end |
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() |
354 | end | 394 | end |
395 | |||
396 | |||
397 | options = OptParse.new().parse(ARGV) | ||
398 | inifile = read_ini(find_ini(options.inifile)) | ||
355 | begin | 399 | begin |
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 |