Module: Muby::UserMethods
- Included in:
- InputWindow
- Defined in:
- lib/muby/user_methods.rb
Overview
This is the UserMethod module.
It is supposed to contain all the muby kernel methods that are supposed to be used by the user or the key_commands.
Instance Method Summary collapse
- #append_buffer!(c) ⇒ Object
- #backspace_buffer! ⇒ Object
- #complete! ⇒ Object
-
#connect(host, port) ⇒ Object
Connect to a host.
- #delete_buffer! ⇒ Object
- #disable_history_search! ⇒ Object
- #disconnect ⇒ Object
-
#echo(*message) ⇒ Object
Echoes a message, if we want to (conf.echo).
- #enable_history_search! ⇒ Object
- #end_buffer! ⇒ Object
- #execute_command!(inwin, outwin, match) ⇒ Object
-
#fake_connect ⇒ Object
Make a fake connection for debug purposes.
-
#get_message_line ⇒ Object
Get the current text in the top border of the input box.
-
#get_status_line ⇒ Object
Get the current text in the top border of the input box.
- #help ⇒ Object
- #history_search!(c) ⇒ Object
- #home_buffer! ⇒ Object
- #ignore_command!(inwin, outwin, match) ⇒ Object
- #next_character_buffer! ⇒ Object
- #next_history_buffer! ⇒ Object
- #next_word_buffer! ⇒ Object
- #previous_character_buffer! ⇒ Object
- #previous_history_buffer! ⇒ Object
- #previous_word_buffer! ⇒ Object
- #print(*message) ⇒ Object
- #process_buffer!(inwin, outwin, c) ⇒ Object
- #quit ⇒ Object
- #receive(string) ⇒ Object
-
#reconnect ⇒ Object
Reconnect to last connected host.
- #reload_application! ⇒ Object
-
#rescue_thread(&block) ⇒ Object
Do block in a thread that displays errors that happen.
- #resize_application! ⇒ Object
- #scroll_down!(input_window) ⇒ Object
- #scroll_up!(input_window) ⇒ Object
-
#send(string, echo = true) ⇒ Object
Send a message to the server, with a n.
-
#sendn(string, echo = true) ⇒ Object
Send a message to the server, with no n.
-
#set_message_line(message) ⇒ Object
Set the text to display in the bottom border of the input box.
-
#set_status_line(message) ⇒ Object
Set the text to display in the top border of the input box.
- #shell_command!(inwin, outwin, match) ⇒ Object
- #toggle_history_search! ⇒ Object
- #toggle_verbosity! ⇒ Object
- #two_step_quit! ⇒ Object
- #update_history_buffer! ⇒ Object
- #update_history_search! ⇒ Object
- #word_backspace_buffer! ⇒ Object
Instance Method Details
#append_buffer!(c) ⇒ Object
445 446 447 448 449 450 |
# File 'lib/muby/user_methods.rb', line 445 def append_buffer!(c) @buffer = @buffer[0, @cursorPosition] + c.chr + @buffer[@cursorPosition, @buffer.size - @cursorPosition] @cursorPosition = @cursorPosition + 1 update nil end |
#backspace_buffer! ⇒ Object
204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 |
# File 'lib/muby/user_methods.rb', line 204 def backspace_buffer! if @handle_mode == :history_search! if @cursorPosition > 1 @search_buffer = @search_buffer[0...-1] @cursorPosition -= 1 update_history_search! end else if @cursorPosition > 0 @buffer = @buffer[0, @cursorPosition - 1] + @buffer[@cursorPosition, @buffer.size - @cursorPosition] @cursorPosition -= 1 update end end nil end |
#complete! ⇒ Object
259 260 261 262 263 264 265 266 267 268 269 270 271 272 |
# File 'lib/muby/user_methods.rb', line 259 def complete! unless @handle_mode == :history_search! last_word = @buffer.match(/(\w*)$/)[1] completions = Muby::Completer.get_instance.complete(last_word) if completions.size == 1 @buffer.gsub!(last_word, completions[0]) @cursorPosition = @buffer.size update else info(completions.inspect) end end nil end |
#connect(host, port) ⇒ Object
Connect to a host
104 105 106 107 108 109 110 111 112 |
# File 'lib/muby/user_methods.rb', line 104 def connect(host, port) disconnect @last_host = host @last_port = port rescue_thread do @connection = Muby::Connection.new(self, Muby::OutputWindow.get_instance, host, port) end "Connecting" end |
#delete_buffer! ⇒ Object
238 239 240 241 242 243 244 245 246 |
# File 'lib/muby/user_methods.rb', line 238 def delete_buffer! unless @handle_mode == :history_search! if @cursorPosition < @buffer.size @buffer = @buffer[0, @cursorPosition] + @buffer[@cursorPosition + 1, @buffer.size - @cursorPosition - 1] update end end nil end |
#disable_history_search! ⇒ Object
416 417 418 419 420 421 422 423 424 425 426 |
# File 'lib/muby/user_methods.rb', line 416 def disable_history_search! unless @handle_mode == :append_buffer! @historyPointer = nil @handle_mode = :append_buffer! @buffer = @found_history || "" @cursorPosition = @buffer.size @search_buffer = "" update end nil end |
#disconnect ⇒ Object
79 80 81 82 83 |
# File 'lib/muby/user_methods.rb', line 79 def disconnect c = @connection @connection = nil c.close if c end |
#echo(*message) ⇒ Object
Echoes a message, if we want to (conf.echo)
475 476 477 478 479 480 481 |
# File 'lib/muby/user_methods.rb', line 475 def echo(*) if conf.echo style = Muby::Style.new(conf.echo_attributes, conf.echo_colors[0], conf.echo_colors[1]) oldStyle = Muby::Style.extract(Muby::OutputWindow.get_instance.outputBuffer) Muby::OutputWindow.get_instance.print_on_newline(*([style] + + [oldStyle])) end end |
#enable_history_search! ⇒ Object
406 407 408 409 410 411 412 413 414 |
# File 'lib/muby/user_methods.rb', line 406 def enable_history_search! if @handle_mode == :append_buffer! @historyPointer = 0 @handle_mode = :history_search! @search_buffer = @buffer update_history_search! end nil end |
#end_buffer! ⇒ Object
375 376 377 378 379 380 381 |
# File 'lib/muby/user_methods.rb', line 375 def end_buffer! unless @handle_mode == :history_search! @cursorPosition = @buffer.size update end nil end |
#execute_command!(inwin, outwin, match) ⇒ Object
170 171 172 173 174 |
# File 'lib/muby/user_methods.rb', line 170 def execute_command!(inwin, outwin, match) echo(match[0]) execute(match[1]) nil end |
#fake_connect ⇒ Object
Make a fake connection for debug purposes
130 131 132 133 |
# File 'lib/muby/user_methods.rb', line 130 def fake_connect @connection = Muby::Connection.new(self, Muby::OutputWindow.get_instance, nil, nil) nil end |
#get_message_line ⇒ Object
Get the current text in the top border of the input box.
75 76 77 |
# File 'lib/muby/user_methods.rb', line 75 def @messageLine end |
#get_status_line ⇒ Object
Get the current text in the top border of the input box.
60 61 62 |
# File 'lib/muby/user_methods.rb', line 60 def get_status_line @statusLine end |
#help ⇒ Object
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 |
# File 'lib/muby/user_methods.rb', line 12 def help help = <<ENDTEXT ################## # muby help text # ################## http://jrandomhacker.info/Muby http://rubyforge.org/projects/muby = Common Issues = Typing commands within muby: Begin your command with the / character. Connecting to Aardwolf: /connect "aardmud.org", 4010 == Keyboard Settings == Check your backspace and left/right keys! -------------------------------------------------------------- You can scroll up to view earlier text with the 'Page Up' key. -------------------------------------------------------------- This help text will no longer be automatically displayed once you have edited the user_edited_config_file property of your configuration file. (Then, you could type /help or press F1 to get the help text again) The configuration file the system has tried to create for you is at #{File.(conf.loaded_rc_file)}. ENDTEXT info help end |
#history_search!(c) ⇒ Object
440 441 442 443 |
# File 'lib/muby/user_methods.rb', line 440 def history_search!(c) @search_buffer << c.chr update_history_search! end |
#home_buffer! ⇒ Object
333 334 335 336 337 338 339 |
# File 'lib/muby/user_methods.rb', line 333 def home_buffer! unless @handle_mode == :history_search! @cursorPosition = 0 update end nil end |
#ignore_command!(inwin, outwin, match) ⇒ Object
153 154 155 156 |
# File 'lib/muby/user_methods.rb', line 153 def ignore_command!(inwin, outwin, match) echo(match[0]) nil end |
#next_character_buffer! ⇒ Object
365 366 367 368 369 370 371 372 373 |
# File 'lib/muby/user_methods.rb', line 365 def next_character_buffer! unless @handle_mode == :history_search! if @buffer.size > 0 @cursorPosition = (@cursorPosition + 1) % (@buffer.size + 1) update end end nil end |
#next_history_buffer! ⇒ Object
302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 |
# File 'lib/muby/user_methods.rb', line 302 def next_history_buffer! if @handle_mode == :append_buffer! if @history.size > 0 && @historyPointer if @historyPointer < @history.size - 1 @historyPointer += 1 else @historyPointer = nil end update_history_buffer! end else @historyPointer -= 1 update_history_search! end nil end |
#next_word_buffer! ⇒ Object
319 320 321 322 323 324 325 326 327 328 329 330 331 |
# File 'lib/muby/user_methods.rb', line 319 def next_word_buffer! unless @handle_mode == :history_search! if @buffer.size > 0 start = @cursorPosition @cursorPosition = (@cursorPosition + 1) % (@buffer.size) while @cursorPosition != 0 && @cursorPosition != @buffer.size && @cursorPosition != start && @buffer[@cursorPosition].chr.match("\\w") @cursorPosition = (@cursorPosition + 1) % (@buffer.size + 1) end update end end nil end |
#previous_character_buffer! ⇒ Object
355 356 357 358 359 360 361 362 363 |
# File 'lib/muby/user_methods.rb', line 355 def previous_character_buffer! unless @handle_mode == :history_search! if @buffer.size > 0 @cursorPosition = (@cursorPosition - 1) % (@buffer.size + 1) update end end nil end |
#previous_history_buffer! ⇒ Object
285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 |
# File 'lib/muby/user_methods.rb', line 285 def previous_history_buffer! if @handle_mode == :append_buffer! if @history.size > 0 if @historyPointer && @historyPointer > 0 @historyPointer -= 1 elsif @historyPointer.nil? @historyPointer = @history.size - 1 end update_history_buffer! end else @historyPointer += 1 update_history_search! end nil end |
#previous_word_buffer! ⇒ Object
341 342 343 344 345 346 347 348 349 350 351 352 353 |
# File 'lib/muby/user_methods.rb', line 341 def previous_word_buffer! unless @handle_mode == :history_search! if @buffer.size > 0 start = @cursorPosition @cursorPosition = (@cursorPosition - 1) % (@buffer.size) while @cursorPosition != 0 && @cursorPosition != @buffer.size && @cursorPosition != start && @buffer[@cursorPosition].chr.match("\\w") @cursorPosition = (@cursorPosition - 1) % (@buffer.size + 1) end update end end nil end |
#print(*message) ⇒ Object
467 468 469 470 |
# File 'lib/muby/user_methods.rb', line 467 def print(*) oldStyle = Muby::Style.extract(Muby::OutputWindow.get_instance.outputBuffer) Muby::OutputWindow.get_instance.print(*( + [oldStyle])) end |
#process_buffer!(inwin, outwin, c) ⇒ Object
176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 |
# File 'lib/muby/user_methods.rb', line 176 def process_buffer!(inwin, outwin, c) toggle_history_search! if @handle_mode == :history_search! Muby::Completer.get_instance.store(@buffer) if conf.feed_completer_with_history @historyPointer = nil if @history[-1] != @buffer @history.push(@buffer.strip) end if @history.size > conf.max_history @history.shift end @buffer << c.chr conf.local_triggers.each do |regexp, command| begin if match = @buffer.match(regexp) @buffer = "" unless execute(command, self, Muby::OutputWindow.get_instance, match) end rescue RegexpError => error conf.local_triggers.delete(key) exception(error) end end sendn(@buffer) unless @buffer.empty? @buffer = "" @cursorPosition = 0 update nil end |
#quit ⇒ Object
85 86 87 88 |
# File 'lib/muby/user_methods.rb', line 85 def quit disconnect exit end |
#receive(string) ⇒ Object
149 150 151 |
# File 'lib/muby/user_methods.rb', line 149 def receive(string) @connection.feed(string) if @connection end |
#reconnect ⇒ Object
Reconnect to last connected host
93 94 95 96 97 98 99 |
# File 'lib/muby/user_methods.rb', line 93 def reconnect if @last_host && @last_port connect(@last_host, @last_port) else echo("No last connection known") end end |
#reload_application! ⇒ Object
253 254 255 256 257 |
# File 'lib/muby/user_methods.rb', line 253 def reload_application! resize_application! conf.reload_application! Muby::InputWindow.get_instance.reload! end |
#rescue_thread(&block) ⇒ Object
Do block in a thread that displays errors that happen.
117 118 119 120 121 122 123 124 125 |
# File 'lib/muby/user_methods.rb', line 117 def rescue_thread(&block) Thread.new do begin yield rescue Exception => e exception(e) end end end |
#resize_application! ⇒ Object
248 249 250 251 |
# File 'lib/muby/user_methods.rb', line 248 def resize_application! Muby::OutputWindow.get_instance.resize! Muby::InputWindow.get_instance.resize! end |
#scroll_down!(input_window) ⇒ Object
457 458 459 460 |
# File 'lib/muby/user_methods.rb', line 457 def scroll_down!(input_window) Muby::OutputWindow.get_instance.scroll_down(input_window) nil end |
#scroll_up!(input_window) ⇒ Object
452 453 454 455 |
# File 'lib/muby/user_methods.rb', line 452 def scroll_up!(input_window) Muby::OutputWindow.get_instance.scroll_up(input_window) nil end |
#send(string, echo = true) ⇒ Object
Send a message to the server, with a n
145 146 147 |
# File 'lib/muby/user_methods.rb', line 145 def send(string, echo = true) sendn("#{string}\n", echo) end |
#sendn(string, echo = true) ⇒ Object
Send a message to the server, with no n
138 139 140 141 142 |
# File 'lib/muby/user_methods.rb', line 138 def sendn(string, echo = true) echo(string) if echo @connection.send(string) if @connection log_output(string) end |
#set_message_line(message) ⇒ Object
Set the text to display in the bottom border of the input box.
67 68 69 70 |
# File 'lib/muby/user_methods.rb', line 67 def () @messageLine = update end |
#set_status_line(message) ⇒ Object
Set the text to display in the top border of the input box.
52 53 54 55 |
# File 'lib/muby/user_methods.rb', line 52 def set_status_line() @statusLine = update end |
#shell_command!(inwin, outwin, match) ⇒ Object
158 159 160 161 162 163 164 165 166 167 168 |
# File 'lib/muby/user_methods.rb', line 158 def shell_command!(inwin, outwin, match) echo(match[0]) if match[1] == "cd.." Dir.chdir("..") elsif subMatch = match[1].match(/^cd\s+(\S+.*)$/) Dir.chdir(subMatch[1]) else execute_with_verbosity(:info, "`#{match[1]}`") end nil end |
#toggle_history_search! ⇒ Object
397 398 399 400 401 402 403 404 |
# File 'lib/muby/user_methods.rb', line 397 def toggle_history_search! if @handle_mode == :append_buffer! enable_history_search! else disable_history_search! end nil end |
#toggle_verbosity! ⇒ Object
462 463 464 465 |
# File 'lib/muby/user_methods.rb', line 462 def toggle_verbosity! conf.toggle_verbosity! nil end |
#two_step_quit! ⇒ Object
383 384 385 386 387 388 389 390 391 392 393 394 395 |
# File 'lib/muby/user_methods.rb', line 383 def two_step_quit! if @user_quit then quit else @user_quit = true info "Press <key> again within 5 seconds to quit." Thread.new do sleep(5) @user_quit = false end end nil end |
#update_history_buffer! ⇒ Object
274 275 276 277 278 279 280 281 282 283 |
# File 'lib/muby/user_methods.rb', line 274 def update_history_buffer! if @historyPointer && @history.size > 0 @buffer = @history[@historyPointer].clone else @buffer = "" end @cursorPosition = @buffer.size update nil end |
#update_history_search! ⇒ Object
428 429 430 431 432 433 434 435 436 437 438 |
# File 'lib/muby/user_methods.rb', line 428 def update_history_search! @search_buffer ||= "" @found_history_array = @history.reverse.select do |line| line.match(Regexp.new(@search_buffer)) end @found_history_array << "" if @found_history_array.empty? @found_history = @found_history_array[@historyPointer % @found_history_array.size] @buffer = "(#{@search_buffer}): `#{@found_history}`" @cursorPosition = @search_buffer.size + 1 update end |
#word_backspace_buffer! ⇒ Object
221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 |
# File 'lib/muby/user_methods.rb', line 221 def word_backspace_buffer! unless @handle_mode == :history_search! if @cursorPosition > 0 while @cursorPosition != 0 && @buffer[@cursorPosition - 1].chr.match("\\W") @buffer = @buffer[0, @cursorPosition - 1] + @buffer[@cursorPosition, @buffer.size - @cursorPosition] @cursorPosition = @cursorPosition - 1 end while @cursorPosition != 0 && @buffer[@cursorPosition - 1].chr.match("\\w") @buffer = @buffer[0, @cursorPosition - 1] + @buffer[@cursorPosition, @buffer.size - @cursorPosition] @cursorPosition = @cursorPosition - 1 end update end end nil end |