Class: Minder::Frame
- Inherits:
-
Object
show all
- Includes:
- Observable
- Defined in:
- lib/minder/cli/frame.rb
Instance Attribute Summary collapse
Instance Method Summary
collapse
Constructor Details
#initialize(**options) ⇒ Frame
Returns a new instance of Frame.
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
|
# File 'lib/minder/cli/frame.rb', line 18
def initialize(**options)
height = options.fetch(:height, 3)
width = options.fetch(:width, 40)
top = options.fetch(:top, 0)
left = options.fetch(:left, 0)
task_manager = options.fetch(:task_manager)
pomodoro_runner = options.fetch(:pomodoro_runner)
@focused = false
@hidden = false
@has_cursor = false
self.pomodoro_runner = pomodoro_runner
self.task_manager = task_manager
self.min_height = height
self.height = height
self.width = width
self.top = top
self.left = left
self.window = build_window
window.keypad(true)
self.lines = []
end
|
Instance Attribute Details
#height ⇒ Object
Returns the value of attribute height.
8
9
10
|
# File 'lib/minder/cli/frame.rb', line 8
def height
@height
end
|
#left ⇒ Object
Returns the value of attribute left.
8
9
10
|
# File 'lib/minder/cli/frame.rb', line 8
def left
@left
end
|
#lines ⇒ Object
Returns the value of attribute lines.
8
9
10
|
# File 'lib/minder/cli/frame.rb', line 8
def lines
@lines
end
|
#min_height ⇒ Object
Returns the value of attribute min_height.
8
9
10
|
# File 'lib/minder/cli/frame.rb', line 8
def min_height
@min_height
end
|
#pomodoro_runner ⇒ Object
Returns the value of attribute pomodoro_runner.
8
9
10
|
# File 'lib/minder/cli/frame.rb', line 8
def pomodoro_runner
@pomodoro_runner
end
|
#task_manager ⇒ Object
Returns the value of attribute task_manager.
8
9
10
|
# File 'lib/minder/cli/frame.rb', line 8
def task_manager
@task_manager
end
|
#top ⇒ Object
Returns the value of attribute top.
8
9
10
|
# File 'lib/minder/cli/frame.rb', line 8
def top
@top
end
|
#width ⇒ Object
Returns the value of attribute width.
8
9
10
|
# File 'lib/minder/cli/frame.rb', line 8
def width
@width
end
|
#window ⇒ Object
Returns the value of attribute window.
8
9
10
|
# File 'lib/minder/cli/frame.rb', line 8
def window
@window
end
|
Instance Method Details
#build_window ⇒ Object
43
44
45
|
# File 'lib/minder/cli/frame.rb', line 43
def build_window
Curses::Window.new(min_height, width, top, left)
end
|
#erase ⇒ Object
135
136
137
138
139
140
141
|
# File 'lib/minder/cli/frame.rb', line 135
def erase
height.times do |index|
window.setpos(index, 0)
window.addstr(' ' * width )
end
window_refresh
end
|
#focus ⇒ Object
47
48
49
50
|
# File 'lib/minder/cli/frame.rb', line 47
def focus
@focused = true
@has_cursor = true
end
|
#focused? ⇒ Boolean
57
58
59
|
# File 'lib/minder/cli/frame.rb', line 57
def focused?
@focused
end
|
#handle_char_keypress(key) ⇒ Object
171
172
|
# File 'lib/minder/cli/frame.rb', line 171
def handle_char_keypress(key)
end
|
#handle_keypress(key) ⇒ Object
153
154
155
156
157
158
159
160
161
162
163
164
165
166
|
# File 'lib/minder/cli/frame.rb', line 153
def handle_keypress(key)
return unless key
if key.is_a?(Fixnum)
if key == 9 changed
notify_observers(:switch_focus)
else
handle_non_char_keypress(key)
end
else
handle_char_keypress(key)
end
end
|
#handle_non_char_keypress(key) ⇒ Object
168
169
|
# File 'lib/minder/cli/frame.rb', line 168
def handle_non_char_keypress(key)
end
|
#has_cursor? ⇒ Boolean
82
83
84
|
# File 'lib/minder/cli/frame.rb', line 82
def has_cursor?
@has_cursor
end
|
#hidden? ⇒ Boolean
61
62
63
|
# File 'lib/minder/cli/frame.rb', line 61
def hidden?
@hidden
end
|
#hide ⇒ Object
65
66
67
68
|
# File 'lib/minder/cli/frame.rb', line 65
def hide
erase
@hidden = true
end
|
#listen ⇒ Object
86
87
88
89
|
# File 'lib/minder/cli/frame.rb', line 86
def listen
window.timeout = 0
handle_keypress(window.getch)
end
|
#move(top, left) ⇒ Object
78
79
80
|
# File 'lib/minder/cli/frame.rb', line 78
def move(top, left)
window.move(top, left)
end
|
#parse_template ⇒ Object
102
103
104
105
|
# File 'lib/minder/cli/frame.rb', line 102
def parse_template
b = binding
self.lines = ERB.new(template).result(b).split("\n")
end
|
#print_line(text) ⇒ Object
147
148
149
150
151
|
# File 'lib/minder/cli/frame.rb', line 147
def print_line(text)
text = text[0,width - 2]
remainder = width - 2 - text.length
window.addstr(text + ' ' * remainder)
end
|
#refresh ⇒ Object
91
92
93
94
95
96
|
# File 'lib/minder/cli/frame.rb', line 91
def refresh
return if @hidden
parse_template
set_text
window_refresh
end
|
#resize ⇒ Object
107
108
109
110
111
112
113
114
115
116
117
118
119
|
# File 'lib/minder/cli/frame.rb', line 107
def resize
erase
self.width = Curses.cols
if lines.length >= min_height - 2
self.height = lines.length + 2
else
self.height = min_height
end
window.resize(height, width)
window_refresh
end
|
#set_cursor_position ⇒ Object
143
144
145
|
# File 'lib/minder/cli/frame.rb', line 143
def set_cursor_position
window.setpos(1, 0)
end
|
#set_text ⇒ Object
121
122
123
124
125
126
127
128
129
130
131
132
133
|
# File 'lib/minder/cli/frame.rb', line 121
def set_text
window.box(?|, ?-)
height.times do |index|
next if index >= height - 2
window.setpos(index + 1, 1)
line = lines[index]
if line
print_line(line)
else
print_line('')
end
end
end
|
#template ⇒ Object
74
75
76
|
# File 'lib/minder/cli/frame.rb', line 74
def template
raise NotImplementedError
end
|
#unfocus ⇒ Object
52
53
54
55
|
# File 'lib/minder/cli/frame.rb', line 52
def unfocus
@focused = false
@has_cursor = false
end
|
#unhide ⇒ Object
70
71
72
|
# File 'lib/minder/cli/frame.rb', line 70
def unhide
@hidden = false
end
|
#window_refresh ⇒ Object
98
99
100
|
# File 'lib/minder/cli/frame.rb', line 98
def window_refresh
window.refresh
end
|