Class: Flumtter::Window::Buf::Screen
- Inherits:
-
Dialog
show all
- Includes:
- Util
- Defined in:
- lib/flumtter/app/core/windows/buf_window.rb
Constant Summary
collapse
- EnableKey =
i(left right up down)
Instance Method Summary
collapse
Methods included from Util
#command_value_regexp, #dialog_for_index, #error, #error_handler, #if_tweet, #index_regexp, #index_with_dialog, #logger, #on_event, #parse_index, #parse_time, #sarastire, #sarastire_user, #screen_name_regexp
Methods inherited from Dialog
#command
#add_multiline_str, #addstr, #getstr
Constructor Details
#initialize(buf, title, body = "") ⇒ Screen
91
92
93
94
95
96
|
# File 'lib/flumtter/app/core/windows/buf_window.rb', line 91
def initialize(buf, title, body="")
@title, @body = title, body
@commands = []
@buf = buf
@range = 0...0
end
|
Instance Method Details
#call(str) ⇒ Object
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
|
# File 'lib/flumtter/app/core/windows/buf_window.rb', line 98
def call(str)
if str == "?"
Window::.new("Command List", " \#{Command.list(@commands)}\n EOF\n move(:keep)\n raise Dispel::Recall\n elsif str == :left\n move(:page)\n raise Dispel::Recall\n elsif str == :right\n raise Dispel::Recall\n elsif str == :up || str == :down\n move(str)\n raise Dispel::Recall\n else\n move(:keep)\n @commands.each do |command|\n if m = str.match(command.command)\n command.call(m)\n raise Dispel::Recall\n end\n end\n raise Dispel::NoCommandError\n end\nend\n").show
|
#id2obj(id) ⇒ Object
125
126
127
128
129
|
# File 'lib/flumtter/app/core/windows/buf_window.rb', line 125
def id2obj(id)
obj = @buf[id.to_i]
raise IndexError if obj.nil?
obj.object
end
|
#move(type) ⇒ Object
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
|
# File 'lib/flumtter/app/core/windows/buf_window.rb', line 131
def move(type)
case type
when :up
@buf.cursor = @range.min - 1
when :down
@buf.cursor = @range.min + 1
when :page
i, count = 0, 0
begin
elem = @buf[@range.min-i].element
while (count += elem.size_of_lines + 2) < @lines
i -= 1
elem = @buf[@range.min-i].element
end
@buf.cursor = @range.min+i
rescue Buf::NoMoreData
@buf.cursor = @buf.size - 1
end
when :keep
@buf.cursor = @range.min
end
end
|
#show ⇒ Object
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
|
# File 'lib/flumtter/app/core/windows/buf_window.rb', line 154
def show
Dispel::Screen.open do |screen|
Dispel::Window.open(screen.lines, screen.columns, 0, 0) do |win|
win.box(?|,?-,?*)
win.setpos(win.cury+2, win.curx+1)
win.addstr @title.title
win.setpos(win.cury+1, 1)
win.addstr "¯"*(@title.title.size+2)
add_multiline_str(win, @body)
start = @buf.cursor
begin
loop do
elem = @buf.get.element
if (@lines = screen.lines) > win.cury + elem.size_of_lines + 4
add_multiline_str(win, elem)
win.setpos(win.cury+1,1)
else
@buf.prev
break
end
end
rescue Buf::NoMoreData
end
@range = start...@buf.cursor
win.setpos(win.cury+2, 1)
win.addstr "help: ?".rjust(win.maxx - 2)
win.setpos(win.cury+1, 1)
call getstr(win, EnableKey)
end
end
rescue Dispel::Recall
show
rescue Dispel::NoCommandError => e
Window::::Error.new(e.class.to_s).show
show
end
|