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.
- #connected? ⇒ Boolean
- #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
449 450 451 452 453 454 |
# File 'lib/muby/user_methods.rb', line 449 def append_buffer!(c) @buffer = @buffer[0, @cursorPosition] + c.chr + @buffer[@cursorPosition, @buffer.size - @cursorPosition] @cursorPosition = @cursorPosition + 1 update nil end |
#backspace_buffer! ⇒ Object
208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 |
# File 'lib/muby/user_methods.rb', line 208 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
263 264 265 266 267 268 269 270 271 272 273 274 275 276 |
# File 'lib/muby/user_methods.rb', line 263 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
108 109 110 111 112 113 114 115 116 |
# File 'lib/muby/user_methods.rb', line 108 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 |
#connected? ⇒ Boolean
101 102 103 |
# File 'lib/muby/user_methods.rb', line 101 def connected? !!@connection end |
#delete_buffer! ⇒ Object
242 243 244 245 246 247 248 249 250 |
# File 'lib/muby/user_methods.rb', line 242 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
420 421 422 423 424 425 426 427 428 429 430 |
# File 'lib/muby/user_methods.rb', line 420 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)
479 480 481 482 483 484 485 |
# File 'lib/muby/user_methods.rb', line 479 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
410 411 412 413 414 415 416 417 418 |
# File 'lib/muby/user_methods.rb', line 410 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
379 380 381 382 383 384 385 |
# File 'lib/muby/user_methods.rb', line 379 def end_buffer! unless @handle_mode == :history_search! @cursorPosition = @buffer.size update end nil end |
#execute_command!(inwin, outwin, match) ⇒ Object
174 175 176 177 178 |
# File 'lib/muby/user_methods.rb', line 174 def execute_command!(inwin, outwin, match) echo(match[0]) execute(match[1]) nil end |
#fake_connect ⇒ Object
Make a fake connection for debug purposes
134 135 136 137 |
# File 'lib/muby/user_methods.rb', line 134 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
444 445 446 447 |
# File 'lib/muby/user_methods.rb', line 444 def history_search!(c) @search_buffer << c.chr update_history_search! end |
#home_buffer! ⇒ Object
337 338 339 340 341 342 343 |
# File 'lib/muby/user_methods.rb', line 337 def home_buffer! unless @handle_mode == :history_search! @cursorPosition = 0 update end nil end |
#ignore_command!(inwin, outwin, match) ⇒ Object
157 158 159 160 |
# File 'lib/muby/user_methods.rb', line 157 def ignore_command!(inwin, outwin, match) echo(match[0]) nil end |
#next_character_buffer! ⇒ Object
369 370 371 372 373 374 375 376 377 |
# File 'lib/muby/user_methods.rb', line 369 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
306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 |
# File 'lib/muby/user_methods.rb', line 306 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
323 324 325 326 327 328 329 330 331 332 333 334 335 |
# File 'lib/muby/user_methods.rb', line 323 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
359 360 361 362 363 364 365 366 367 |
# File 'lib/muby/user_methods.rb', line 359 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
289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 |
# File 'lib/muby/user_methods.rb', line 289 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
345 346 347 348 349 350 351 352 353 354 355 356 357 |
# File 'lib/muby/user_methods.rb', line 345 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
471 472 473 474 |
# File 'lib/muby/user_methods.rb', line 471 def print(*) oldStyle = Muby::Style.extract(Muby::OutputWindow.get_instance.outputBuffer) Muby::OutputWindow.get_instance.print(*( + [oldStyle])) end |
#process_buffer!(inwin, outwin, c) ⇒ Object
180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 |
# File 'lib/muby/user_methods.rb', line 180 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
153 154 155 |
# File 'lib/muby/user_methods.rb', line 153 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
257 258 259 260 261 |
# File 'lib/muby/user_methods.rb', line 257 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.
121 122 123 124 125 126 127 128 129 |
# File 'lib/muby/user_methods.rb', line 121 def rescue_thread(&block) Thread.new do begin yield rescue Exception => e exception(e) end end end |
#resize_application! ⇒ Object
252 253 254 255 |
# File 'lib/muby/user_methods.rb', line 252 def resize_application! Muby::OutputWindow.get_instance.resize! Muby::InputWindow.get_instance.resize! end |
#scroll_down!(input_window) ⇒ Object
461 462 463 464 |
# File 'lib/muby/user_methods.rb', line 461 def scroll_down!(input_window) Muby::OutputWindow.get_instance.scroll_down(input_window) nil end |
#scroll_up!(input_window) ⇒ Object
456 457 458 459 |
# File 'lib/muby/user_methods.rb', line 456 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
149 150 151 |
# File 'lib/muby/user_methods.rb', line 149 def send(string, echo = true) sendn("#{string}\n", echo) end |
#sendn(string, echo = true) ⇒ Object
Send a message to the server, with no n
142 143 144 145 146 |
# File 'lib/muby/user_methods.rb', line 142 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
162 163 164 165 166 167 168 169 170 171 172 |
# File 'lib/muby/user_methods.rb', line 162 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
401 402 403 404 405 406 407 408 |
# File 'lib/muby/user_methods.rb', line 401 def toggle_history_search! if @handle_mode == :append_buffer! enable_history_search! else disable_history_search! end nil end |
#toggle_verbosity! ⇒ Object
466 467 468 469 |
# File 'lib/muby/user_methods.rb', line 466 def toggle_verbosity! conf.toggle_verbosity! nil end |
#two_step_quit! ⇒ Object
387 388 389 390 391 392 393 394 395 396 397 398 399 |
# File 'lib/muby/user_methods.rb', line 387 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
278 279 280 281 282 283 284 285 286 287 |
# File 'lib/muby/user_methods.rb', line 278 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
432 433 434 435 436 437 438 439 440 441 442 |
# File 'lib/muby/user_methods.rb', line 432 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
225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 |
# File 'lib/muby/user_methods.rb', line 225 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 |