Class: JsClient::TabComplete
- Inherits:
-
Object
- Object
- JsClient::TabComplete
- Defined in:
- lib/jschat/client.rb
Instance Attribute Summary collapse
-
#index ⇒ Object
Returns the value of attribute index.
-
#matched ⇒ Object
Returns the value of attribute matched.
Instance Method Summary collapse
-
#initialize ⇒ TabComplete
constructor
A new instance of TabComplete.
- #match(input) ⇒ Object
- #reset ⇒ Object
- #run(names, field, form, cursor_x) ⇒ Object
Constructor Details
#initialize ⇒ TabComplete
Returns a new instance of TabComplete.
197 198 |
# File 'lib/jschat/client.rb', line 197 def initialize end |
Instance Attribute Details
#index ⇒ Object
Returns the value of attribute index.
195 196 197 |
# File 'lib/jschat/client.rb', line 195 def index @index end |
#matched ⇒ Object
Returns the value of attribute matched.
195 196 197 |
# File 'lib/jschat/client.rb', line 195 def matched @matched end |
Instance Method Details
#match(input) ⇒ Object
230 231 |
# File 'lib/jschat/client.rb', line 230 def match(input) end |
#reset ⇒ Object
233 234 235 236 |
# File 'lib/jschat/client.rb', line 233 def reset @matched = nil @index = 0 end |
#run(names, field, form, cursor_x) ⇒ Object
200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 |
# File 'lib/jschat/client.rb', line 200 def run(names, field, form, cursor_x) form.form_driver Ncurses::Form::REQ_BEG_LINE text = field.field_buffer(0).dup.strip if text.size > 0 and cursor_x > 0 if @matched.nil? source = text.slice(0, cursor_x) source = text.split(' ').last if text.match(' ') @index = 0 else source = @matched @index += 1 end names = names.sort.find_all { |name| name.match /^#{source}/i } @index = 0 if @index >= names.size name = names[@index] if name and (@matched or source.size == text.size) @matched = source field.set_field_buffer(0, "#{name}: ") form.form_driver Ncurses::Form::REQ_END_LINE form.form_driver Ncurses::Form::REQ_NEXT_CHAR else @matched = nil @index = 0 (0..cursor_x - 1).each do form.form_driver Ncurses::Form::REQ_NEXT_CHAR end end end end |