]>
git.immae.eu Git - perso/Immae/Projets/Ruby/Monitor.git/blob - windows.rb
2 def initialize(inifile
)
4 @win = Ncurses
::WINDOW.new(0, Ncurses
.COLS()/4, 0, 0)
28 def print_list(entry
=nil)
33 @params.each_section
do |section
|
35 @win.attron(Ncurses
::A_REVERSE)
38 print_line(@win,@params[section
]['Name'])
40 @win.attroff(Ncurses
::A_REVERSE)
52 def initialize(winsize
,winpos
,params
)
54 @win = Ncurses
::WINDOW.new(0, winsize
, 0, winpos
)
55 @panel = Ncurses
::Panel::PANEL.new(@win)
56 if(@params['Type'] == 'oneshot')
57 @buffer = Buffer
.new(0)
59 @buffer = Buffer
.new(@params['Buffer'].to_i
)
70 def move_resize(winsize
,winpos
)
71 newwin
= Ncurses
::WINDOW.new(0, winsize
, 0, winpos
)
72 Ncurses
::Panel.replace_panel(@panel, newwin
)
78 @last_update = Time
.now
79 @date = @last_update.strftime("%F %R:%S")
88 @win.addnstr(@params['Name'],@win.getmaxx-
@date.length-10
)
89 @win.move(0,@win.getmaxx-
@date.length-2
)
100 Ncurses
::Panel.top_panel(@panel)
101 Ncurses
::Panel.update_panels
104 def hscroll(scroll
=0)
109 if(@hscroll > @buffer.maxlen()-@win.getmaxx+
3)
110 @hscroll = @buffer.maxlen()-@win.getmaxx+
3
115 def scroll(scroll
=0,goto
=nil,fact
=nil)
117 scroll
= (fact
* @win.getmaxy
.to_f
).to_i
118 elsif (not goto
.nil?)
119 @curr_offset = (goto
* @buffer.size()).to_i
122 #@curr_offset -= @win.getmaxy/2
123 @curr_offset +
= scroll
127 if(@curr_offset > @buffer.size()-@win.getmaxy+
2)
128 @curr_offset = @buffer.size()-@win.getmaxy+
2
138 @buffer.yield(@win.getmaxy-2
,@curr_offset) { |l
,type
|
140 if(type
== 1) then @win.attron(Ncurses
.COLOR_PAIR(1)) end
141 print_line(@win,l
,hscroll
=@hscroll)
142 if(type
== 1) then @win.attroff(Ncurses
.COLOR_PAIR(1)) end
145 if(@buffer.has_before
?)
146 @win.move(2,@win.getmaxx-1
)
147 @win.attron(Ncurses
::A_REVERSE)
149 @win.attroff(Ncurses
::A_REVERSE)
151 if(@buffer.has_after
?)
152 @win.move(@win.getmaxy-2
,@win.getmaxx-1
)
153 @win.attron(Ncurses
::A_REVERSE)
155 @win.attroff(Ncurses
::A_REVERSE)
162 @buffer.push(@proc.readline_nonblock
)
165 rescue IO
::WaitReadable
169 def update(force
=false)
170 if(@params['Type'] == 'continuous')
173 if(@params['Type'] == 'oneshot')
174 if(force
or (Time
.now
- @last_update > @params['Periodic'].to_i
))
184 if(@params['Type'] == 'oneshot')
186 Open3
.popen3(@params["Command"]) { |i
,o
,e
,t
|
187 while ((not o
.eof
?) or (not e
.eof
?))
188 rs
= IO
.select([o
,e
],nil)[0]
189 r
= (rs
[0].eof
?)? rs
[1] : rs
[0]
191 if r
.fileno
== o
.fileno
192 @buffer.push(r
.readline
)
193 elsif r
.fileno
== e
.fileno
194 @buffer.push(r
.readline
,type
=1)
198 elsif(@params['Type'] == 'continuous')
199 @proc = IO
.popen(@params["Command"])