aboutsummaryrefslogtreecommitdiff
path: root/windows.rb
diff options
context:
space:
mode:
Diffstat (limited to 'windows.rb')
-rw-r--r--windows.rb65
1 files changed, 59 insertions, 6 deletions
diff --git a/windows.rb b/windows.rb
index 5b23579..96a45b9 100644
--- a/windows.rb
+++ b/windows.rb
@@ -1,6 +1,59 @@
1require "time"
2require "open3"
3
4class IO
5 def readline_nonblock
6 buffer = ""
7 buffer << read_nonblock(1) while buffer[-1] != "\n"
8 buffer
9 rescue IO::WaitReadable => blocking
10 if (not buffer.empty?)
11 ungetc(buffer)
12 end
13 raise blocking
14 end
15end
16
17
18class Ncurses::WINDOW
19 def print_line(str, hscroll=0)
20 revert_color = false
21 str[0,5].match(/\033\[3(.)m/) { |c| #Line starts with an escape sequence. We handle that `a la xterm`
22 Ncurses.init_pair(10, c[1].to_i, Ncurses::COLOR_BLACK)
23 self.attron(Ncurses.COLOR_PAIR(10))
24 revert_color = true
25 str = str[5,str.length]
26 }
27 str = str.gsub("\011"," ")
28 #Any other control char is ignored and escaped
29 str = str.gsub(/[[:cntrl:]]/) { |m|
30 "^"+(m.ord + 64).chr
31 }
32 if(hscroll > 0)
33 strcut = str[hscroll,str.length]
34 if(strcut.nil? or strcut.empty?)
35 str = ""
36 else
37 str = "…"+strcut
38 end
39 end
40 strlen = str.length
41 winlen = self.getmaxx-self.getcurx-1
42 if(strlen <= winlen)
43 self.addstr(str + " "*(winlen-strlen))
44 else
45 self.addstr(str[0,winlen-1]+"…")
46 end
47 if(revert_color)
48 self.attroff(Ncurses.COLOR_PAIR(10))
49 end
50 end
51end
52
53
1class List_Win 54class List_Win
2 def initialize(inifile) 55 def initialize(sections)
3 @params = inifile 56 @params = sections
4 @win = Ncurses::WINDOW.new(0, Ncurses.COLS()/4, 0, 0) 57 @win = Ncurses::WINDOW.new(0, Ncurses.COLS()/4, 0, 0)
5 @win.border(*([0]*8)) 58 @win.border(*([0]*8))
6 @win.keypad(true) 59 @win.keypad(true)
@@ -30,17 +83,17 @@ class List_Win
30 @entry = entry 83 @entry = entry
31 end 84 end
32 i = 0 85 i = 0
33 @params.each_section do |section| 86 @params.each { |section_name,section|
34 if(@entry == i) 87 if(@entry == i)
35 @win.attron(Ncurses::A_REVERSE) 88 @win.attron(Ncurses::A_REVERSE)
36 end 89 end
37 @win.move(i+1,1) 90 @win.move(i+1,1)
38 print_line(@win,@params[section]['Name']) 91 @win.print_line(section['Name'])
39 if(@entry == i) 92 if(@entry == i)
40 @win.attroff(Ncurses::A_REVERSE) 93 @win.attroff(Ncurses::A_REVERSE)
41 end 94 end
42 i = i+1 95 i = i+1
43 end 96 }
44 @win.border(*([0]*8)) 97 @win.border(*([0]*8))
45 @win.move(0,3) 98 @win.move(0,3)
46 @win.addstr("Menu") 99 @win.addstr("Menu")
@@ -138,7 +191,7 @@ class Buff_Win
138 @buffer.yield(@win.getmaxy-2,@curr_offset) { |l,type| 191 @buffer.yield(@win.getmaxy-2,@curr_offset) { |l,type|
139 @win.move(j,1) 192 @win.move(j,1)
140 if(type == 1) then @win.attron(Ncurses.COLOR_PAIR(1)) end 193 if(type == 1) then @win.attron(Ncurses.COLOR_PAIR(1)) end
141 print_line(@win,l,hscroll=@hscroll) 194 @win.print_line(l,hscroll=@hscroll)
142 if(type == 1) then @win.attroff(Ncurses.COLOR_PAIR(1)) end 195 if(type == 1) then @win.attroff(Ncurses.COLOR_PAIR(1)) end
143 j = j+1 196 j = j+1
144 } 197 }