Class: Twterm::SearchQueryWindow
- Inherits:
-
Object
- Object
- Twterm::SearchQueryWindow
show all
- Includes:
- Curses, Singleton, Subscriber
- Defined in:
- lib/twterm/search_query_window.rb
Defined Under Namespace
Classes: CancelInput
Instance Attribute Summary collapse
Instance Method Summary
collapse
Methods included from Subscriber
included, #subscribe, #unsubscribe
Constructor Details
Returns a new instance of SearchQueryWindow.
14
15
16
17
18
19
20
21
|
# File 'lib/twterm/search_query_window.rb', line 14
def initialize
@window = stdscr.subwin(1, stdscr.maxx, stdscr.maxy - 1, 0)
@searching_down = true
@str = ''
@last_query = ''
subscribe(Event::Screen::Resize, :resize)
end
|
Instance Attribute Details
#last_query ⇒ Object
Returns the value of attribute last_query.
12
13
14
|
# File 'lib/twterm/search_query_window.rb', line 12
def last_query
@last_query
end
|
Instance Method Details
#clear ⇒ Object
74
75
76
77
|
# File 'lib/twterm/search_query_window.rb', line 74
def clear
window.clear
window.refresh
end
|
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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
|
# File 'lib/twterm/search_query_window.rb', line 23
def input
@str = ''
render_current_string
Curses.timeout = 10
chars = []
loop do
char = getch
if char.nil?
case chars.first
when 3, 27 raise CancelInput
when 4 raise CancelInput if @str.empty?
when 10 @str = last_query.to_s if @str.empty?
break
when 127 raise CancelInput if @str.empty?
@str.chop!
render_current_string
when 0..31 else
next if chars.empty?
@str << chars
.map { |x| x.is_a?(String) ? x.ord : x }
.pack('c*')
.force_encoding('utf-8')
render_current_string
end
chars = []
else
chars << char
end
end
@last_query = @str unless @str.empty?
last_query
rescue CancelInput
@str = ''
clear
ensure
Curses.timeout = -1
end
|
#render_last_query ⇒ Object
79
80
81
|
# File 'lib/twterm/search_query_window.rb', line 79
def render_last_query
render(last_query) unless last_query.empty?
end
|
#searching_backward! ⇒ Object
83
84
85
|
# File 'lib/twterm/search_query_window.rb', line 83
def searching_backward!
@searching_forward = false
end
|
#searching_backward? ⇒ Boolean
87
88
89
|
# File 'lib/twterm/search_query_window.rb', line 87
def searching_backward?
!@searching_forward
end
|
#searching_down! ⇒ Object
91
92
93
|
# File 'lib/twterm/search_query_window.rb', line 91
def searching_down!
@searching_down = true
end
|
#searching_down? ⇒ Boolean
95
96
97
|
# File 'lib/twterm/search_query_window.rb', line 95
def searching_down?
@searching_down
end
|
#searching_forward! ⇒ Object
99
100
101
|
# File 'lib/twterm/search_query_window.rb', line 99
def searching_forward!
@searching_forward = true
end
|
#searching_forward? ⇒ Boolean
103
104
105
|
# File 'lib/twterm/search_query_window.rb', line 103
def searching_forward?
@searching_forward
end
|
#searching_up! ⇒ Object
107
108
109
|
# File 'lib/twterm/search_query_window.rb', line 107
def searching_up!
@searching_down = false
end
|
#searching_up? ⇒ Boolean
111
112
113
|
# File 'lib/twterm/search_query_window.rb', line 111
def searching_up?
!@searching_down
end
|