-
Notifications
You must be signed in to change notification settings - Fork 0
/
top_win.rb
54 lines (46 loc) · 1.02 KB
/
top_win.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
require 'window'
class TopWin < Window
attr_accessor :search_str, :selected_tag
def initialize(h, w, y)
super(h, w, y, 0, {:box => true})
@show_search = false
@search_str = ""
@selected_tag = nil
end
def show_search(str)
self.search_str = str
@show_search = true
end
def hide_search
@show_search = false
end
def show_search?
@show_search
end
def header
header = []
header << " CB version 0.1 "
header << " file: #{selected_tag.file} " unless selected_tag.nil?
header.join("|")
end
def render
super {|win|
if self.show_search?
win.fixed_text_at(1, 1, "Search> #{self.search_str}", cols - 2)
Ncurses.move(1, 9 + self.search_str.length)
else
win.fixed_text_at(1, 1, header, cols - 2, Ncurses::A_REVERSE)
end
}
end
def handle_key(c)
case c
when 127, 330 # Backspace or delete
delete_chr
when Ncurses::KEY_ENTER, 10
:search_string
else
add_chr(c)
end
end
end