muby 0.6.6
Sign up to get free protection for your applications and to get access to all the features.
- data/LICENSE +339 -0
- data/bin/muby +37 -0
- data/contrib/aardmud.org_4000/README.txt +39 -0
- data/contrib/aardmud.org_4000/aard-config.rb +234 -0
- data/contrib/aardmud.org_4000/aard-helpers.rb +464 -0
- data/contrib/aardmud.org_4000/aliases/aard-aliases.rb +205 -0
- data/contrib/aardmud.org_4000/gags/aard-gags.rb +182 -0
- data/contrib/aardmud.org_4000/misc/aard-affects.rb +252 -0
- data/contrib/aardmud.org_4000/misc/aard-know.rb +147 -0
- data/contrib/aardmud.org_4000/misc/aard-poznai_sebia.rb +191 -0
- data/contrib/aardmud.org_4000/misc/aard-prompts.rb +65 -0
- data/contrib/aardmud.org_4000/misc/aard-status_toggling.rb +156 -0
- data/contrib/aardmud.org_4000/misc/aard_consider_substitutions.rb +319 -0
- data/contrib/aardmud.org_4000/speedwalks/aard-sw-areas-hero.rb +86 -0
- data/contrib/aardmud.org_4000/speedwalks/aard-sw-areas-newbie.rb +98 -0
- data/contrib/aardmud.org_4000/speedwalks/aard-sw-areas-noble.rb +170 -0
- data/contrib/aardmud.org_4000/speedwalks/aard-sw-areas-vidblain.rb +88 -0
- data/contrib/aardmud.org_4000/speedwalks/aard-sw-areas.rb +850 -0
- data/contrib/aardmud.org_4000/speedwalks/aard-sw-clans.rb +43 -0
- data/contrib/aardmud.org_4000/speedwalks/aard-sw-guilds.rb +13 -0
- data/contrib/aardmud.org_4000/speedwalks/aard-sw.rb +45 -0
- data/contrib/aardmud.org_4000/triggers/aard-triggers-items.rb +254 -0
- data/contrib/aardmud.org_4000/triggers/aard-triggers.rb +227 -0
- data/contrib/sy/cce.rb +120 -0
- data/lib/muby.rb +15 -0
- data/lib/muby/application.rb +66 -0
- data/lib/muby/completer.rb +62 -0
- data/lib/muby/configuration.rb +379 -0
- data/lib/muby/connection.rb +332 -0
- data/lib/muby/displayer.rb +60 -0
- data/lib/muby/help.rb +88 -0
- data/lib/muby/helper_methods.rb +46 -0
- data/lib/muby/inputwindow.rb +173 -0
- data/lib/muby/logger.rb +28 -0
- data/lib/muby/outputwindow.rb +189 -0
- data/lib/muby/style.rb +142 -0
- data/lib/muby/user_methods.rb +463 -0
- metadata +90 -0
@@ -0,0 +1,463 @@
|
|
1
|
+
|
2
|
+
module Muby
|
3
|
+
|
4
|
+
#
|
5
|
+
# This is the UserMethod module.
|
6
|
+
#
|
7
|
+
# It is supposed to contain all the muby kernel methods that are
|
8
|
+
# supposed to be used by the user or the key_commands.
|
9
|
+
#
|
10
|
+
module UserMethods
|
11
|
+
|
12
|
+
def help
|
13
|
+
help = <<ENDTEXT
|
14
|
+
##################
|
15
|
+
# muby help text #
|
16
|
+
##################
|
17
|
+
|
18
|
+
http://jrandomhacker.info/Muby
|
19
|
+
http://rubyforge.org/projects/muby
|
20
|
+
|
21
|
+
= Common Issues =
|
22
|
+
|
23
|
+
Typing commands within muby:
|
24
|
+
Begin your command with the / character.
|
25
|
+
|
26
|
+
Connecting to Aardwolf:
|
27
|
+
/connect "aardmud.org", 4010
|
28
|
+
|
29
|
+
== Keyboard Settings ==
|
30
|
+
|
31
|
+
Check your backspace and left/right keys!
|
32
|
+
|
33
|
+
--------------------------------------------------------------
|
34
|
+
You can scroll up to view earlier text with the 'Page Up' key.
|
35
|
+
--------------------------------------------------------------
|
36
|
+
|
37
|
+
This help text will no longer be automatically displayed once you
|
38
|
+
have edited the user_edited_config_file property of your
|
39
|
+
configuration file.
|
40
|
+
|
41
|
+
(Then, you could type /help or press F1 to get the help text again)
|
42
|
+
|
43
|
+
The configuration file the system has tried to create for you
|
44
|
+
is at #{conf.loaded_rc_file}.
|
45
|
+
ENDTEXT
|
46
|
+
info help
|
47
|
+
end
|
48
|
+
|
49
|
+
#
|
50
|
+
# Set the text to display in the top border of the input box.
|
51
|
+
#
|
52
|
+
def set_status_line(message)
|
53
|
+
@statusLine = message
|
54
|
+
update
|
55
|
+
end
|
56
|
+
|
57
|
+
#
|
58
|
+
# Get the current text in the top border of the input box.
|
59
|
+
#
|
60
|
+
def get_status_line
|
61
|
+
@statusLine
|
62
|
+
end
|
63
|
+
|
64
|
+
#
|
65
|
+
# Set the text to display in the bottom border of the input box.
|
66
|
+
#
|
67
|
+
def set_message_line(message)
|
68
|
+
@messageLine = message
|
69
|
+
update
|
70
|
+
end
|
71
|
+
|
72
|
+
#
|
73
|
+
# Get the current text in the top border of the input box.
|
74
|
+
#
|
75
|
+
def get_message_line
|
76
|
+
@messageLine
|
77
|
+
end
|
78
|
+
|
79
|
+
def disconnect
|
80
|
+
c = @connection
|
81
|
+
@connection = nil
|
82
|
+
c.close if c
|
83
|
+
end
|
84
|
+
|
85
|
+
def quit
|
86
|
+
disconnect
|
87
|
+
exit
|
88
|
+
end
|
89
|
+
|
90
|
+
#
|
91
|
+
# Reconnect to last connected host
|
92
|
+
#
|
93
|
+
def reconnect
|
94
|
+
if @last_host && @last_port
|
95
|
+
connect(@last_host, @last_port)
|
96
|
+
else
|
97
|
+
echo("No last connection known")
|
98
|
+
end
|
99
|
+
end
|
100
|
+
|
101
|
+
#
|
102
|
+
# Connect to a host
|
103
|
+
#
|
104
|
+
def connect(host, port)
|
105
|
+
disconnect
|
106
|
+
@last_host = host
|
107
|
+
@last_port = port
|
108
|
+
@connection = Muby::Connection.new(self, Muby::OutputWindow.get_instance, host, port)
|
109
|
+
"Connecting"
|
110
|
+
end
|
111
|
+
|
112
|
+
#
|
113
|
+
# Make a fake connection for debug purposes
|
114
|
+
#
|
115
|
+
def fake_connect
|
116
|
+
@connection = Muby::Connection.new(self, Muby::OutputWindow.get_instance, nil, nil)
|
117
|
+
nil
|
118
|
+
end
|
119
|
+
|
120
|
+
#
|
121
|
+
# Send a message to the server, with no \n
|
122
|
+
#
|
123
|
+
def sendn(string, echo = true)
|
124
|
+
echo(string) if echo
|
125
|
+
@connection.send(string) if @connection
|
126
|
+
log_output(string)
|
127
|
+
end
|
128
|
+
|
129
|
+
# Send a message to the server, with a \n
|
130
|
+
def send(string, echo = true)
|
131
|
+
sendn("#{string}\n", echo)
|
132
|
+
end
|
133
|
+
|
134
|
+
def receive(string)
|
135
|
+
@connection.feed(string) if @connection
|
136
|
+
end
|
137
|
+
|
138
|
+
def ignore_command!(inwin, outwin, match)
|
139
|
+
echo(match[0])
|
140
|
+
nil
|
141
|
+
end
|
142
|
+
|
143
|
+
def shell_command!(inwin, outwin, match)
|
144
|
+
echo(match[0])
|
145
|
+
if match[1] == "cd.."
|
146
|
+
Dir.chdir("..")
|
147
|
+
elsif subMatch = match[1].match(/^cd\s+(\S+.*)$/)
|
148
|
+
Dir.chdir(subMatch[1])
|
149
|
+
else
|
150
|
+
execute_with_verbosity(:info, "`#{match[1]}`")
|
151
|
+
end
|
152
|
+
nil
|
153
|
+
end
|
154
|
+
|
155
|
+
def execute_command!(inwin, outwin, match)
|
156
|
+
echo(match[0])
|
157
|
+
execute(match[1])
|
158
|
+
nil
|
159
|
+
end
|
160
|
+
|
161
|
+
def process_buffer!(inwin, outwin, c)
|
162
|
+
toggle_history_search! if @handle_mode == :history_search!
|
163
|
+
Muby::Completer.get_instance.store(@buffer) if conf.feed_completer_with_history
|
164
|
+
@historyPointer = nil
|
165
|
+
if @history[-1] != @buffer
|
166
|
+
@history.push(@buffer.strip)
|
167
|
+
end
|
168
|
+
if @history.size > conf.max_history
|
169
|
+
@history.shift
|
170
|
+
end
|
171
|
+
@buffer << c.chr
|
172
|
+
conf.local_triggers.each do |regexp, command|
|
173
|
+
begin
|
174
|
+
if match = @buffer.match(regexp)
|
175
|
+
@buffer = "" unless execute(command, self, Muby::OutputWindow.get_instance, match)
|
176
|
+
end
|
177
|
+
rescue RegexpError => error
|
178
|
+
conf.local_triggers.delete(key)
|
179
|
+
exception(error)
|
180
|
+
end
|
181
|
+
end
|
182
|
+
sendn(@buffer) unless @buffer.empty?
|
183
|
+
@buffer = ""
|
184
|
+
@cursorPosition = 0
|
185
|
+
update
|
186
|
+
nil
|
187
|
+
end
|
188
|
+
|
189
|
+
def backspace_buffer!
|
190
|
+
if @handle_mode == :history_search!
|
191
|
+
if @cursorPosition > 1
|
192
|
+
@search_buffer = @search_buffer[0...-1]
|
193
|
+
@cursorPosition -= 1
|
194
|
+
update_history_search!
|
195
|
+
end
|
196
|
+
else
|
197
|
+
if @cursorPosition > 0
|
198
|
+
@buffer = @buffer[0, @cursorPosition - 1] + @buffer[@cursorPosition, @buffer.size - @cursorPosition]
|
199
|
+
@cursorPosition -= 1
|
200
|
+
update
|
201
|
+
end
|
202
|
+
end
|
203
|
+
nil
|
204
|
+
end
|
205
|
+
|
206
|
+
def word_backspace_buffer!
|
207
|
+
unless @handle_mode == :history_search!
|
208
|
+
if @cursorPosition > 0
|
209
|
+
while @cursorPosition != 0 && @buffer[@cursorPosition - 1].chr.match("\\W")
|
210
|
+
@buffer = @buffer[0, @cursorPosition - 1] + @buffer[@cursorPosition, @buffer.size - @cursorPosition]
|
211
|
+
@cursorPosition = @cursorPosition - 1
|
212
|
+
end
|
213
|
+
while @cursorPosition != 0 && @buffer[@cursorPosition - 1].chr.match("\\w")
|
214
|
+
@buffer = @buffer[0, @cursorPosition - 1] + @buffer[@cursorPosition, @buffer.size - @cursorPosition]
|
215
|
+
@cursorPosition = @cursorPosition - 1
|
216
|
+
end
|
217
|
+
update
|
218
|
+
end
|
219
|
+
end
|
220
|
+
nil
|
221
|
+
end
|
222
|
+
|
223
|
+
def delete_buffer!
|
224
|
+
unless @handle_mode == :history_search!
|
225
|
+
if @cursorPosition < @buffer.size
|
226
|
+
@buffer = @buffer[0, @cursorPosition] + @buffer[@cursorPosition + 1, @buffer.size - @cursorPosition - 1]
|
227
|
+
update
|
228
|
+
end
|
229
|
+
end
|
230
|
+
nil
|
231
|
+
end
|
232
|
+
|
233
|
+
def reload_application!
|
234
|
+
conf.reload_application!
|
235
|
+
Muby::OutputWindow.get_instance.reload!
|
236
|
+
end
|
237
|
+
|
238
|
+
def complete!
|
239
|
+
unless @handle_mode == :history_search!
|
240
|
+
last_word = @buffer.match(/(\w*)$/)[1]
|
241
|
+
completions = Muby::Completer.get_instance.complete(last_word)
|
242
|
+
if completions.size == 1
|
243
|
+
@buffer.gsub!(last_word, completions[0])
|
244
|
+
@cursorPosition = @buffer.size
|
245
|
+
update
|
246
|
+
else
|
247
|
+
info(completions.inspect)
|
248
|
+
end
|
249
|
+
end
|
250
|
+
nil
|
251
|
+
end
|
252
|
+
|
253
|
+
def update_history_buffer!
|
254
|
+
if @historyPointer && @history.size > 0
|
255
|
+
@buffer = @history[@historyPointer].clone
|
256
|
+
else
|
257
|
+
@buffer = ""
|
258
|
+
end
|
259
|
+
@cursorPosition = @buffer.size
|
260
|
+
update
|
261
|
+
nil
|
262
|
+
end
|
263
|
+
|
264
|
+
def previous_history_buffer!
|
265
|
+
if @handle_mode == :append_buffer!
|
266
|
+
if @history.size > 0
|
267
|
+
if @historyPointer && @historyPointer > 0
|
268
|
+
@historyPointer -= 1
|
269
|
+
elsif @historyPointer.nil?
|
270
|
+
@historyPointer = @history.size - 1
|
271
|
+
end
|
272
|
+
update_history_buffer!
|
273
|
+
end
|
274
|
+
else
|
275
|
+
@historyPointer += 1
|
276
|
+
update_history_search!
|
277
|
+
end
|
278
|
+
nil
|
279
|
+
end
|
280
|
+
|
281
|
+
def next_history_buffer!
|
282
|
+
if @handle_mode == :append_buffer!
|
283
|
+
if @history.size > 0 && @historyPointer
|
284
|
+
if @historyPointer < @history.size - 1
|
285
|
+
@historyPointer += 1
|
286
|
+
else
|
287
|
+
@historyPointer = nil
|
288
|
+
end
|
289
|
+
update_history_buffer!
|
290
|
+
end
|
291
|
+
else
|
292
|
+
@historyPointer -= 1
|
293
|
+
update_history_search!
|
294
|
+
end
|
295
|
+
nil
|
296
|
+
end
|
297
|
+
|
298
|
+
def next_word_buffer!
|
299
|
+
unless @handle_mode == :history_search!
|
300
|
+
if @buffer.size > 0
|
301
|
+
start = @cursorPosition
|
302
|
+
@cursorPosition = (@cursorPosition + 1) % (@buffer.size)
|
303
|
+
while @cursorPosition != 0 && @cursorPosition != @buffer.size && @cursorPosition != start && @buffer[@cursorPosition].chr.match("\\w")
|
304
|
+
@cursorPosition = (@cursorPosition + 1) % (@buffer.size + 1)
|
305
|
+
end
|
306
|
+
update
|
307
|
+
end
|
308
|
+
end
|
309
|
+
nil
|
310
|
+
end
|
311
|
+
|
312
|
+
def home_buffer!
|
313
|
+
unless @handle_mode == :history_search!
|
314
|
+
@cursorPosition = 0
|
315
|
+
update
|
316
|
+
end
|
317
|
+
nil
|
318
|
+
end
|
319
|
+
|
320
|
+
def previous_word_buffer!
|
321
|
+
unless @handle_mode == :history_search!
|
322
|
+
if @buffer.size > 0
|
323
|
+
start = @cursorPosition
|
324
|
+
@cursorPosition = (@cursorPosition - 1) % (@buffer.size)
|
325
|
+
while @cursorPosition != 0 && @cursorPosition != @buffer.size && @cursorPosition != start && @buffer[@cursorPosition].chr.match("\\w")
|
326
|
+
@cursorPosition = (@cursorPosition - 1) % (@buffer.size + 1)
|
327
|
+
end
|
328
|
+
update
|
329
|
+
end
|
330
|
+
end
|
331
|
+
nil
|
332
|
+
end
|
333
|
+
|
334
|
+
def previous_character_buffer!
|
335
|
+
unless @handle_mode == :history_search!
|
336
|
+
if @buffer.size > 0
|
337
|
+
@cursorPosition = (@cursorPosition - 1) % (@buffer.size + 1)
|
338
|
+
update
|
339
|
+
end
|
340
|
+
end
|
341
|
+
nil
|
342
|
+
end
|
343
|
+
|
344
|
+
def next_character_buffer!
|
345
|
+
unless @handle_mode == :history_search!
|
346
|
+
if @buffer.size > 0
|
347
|
+
@cursorPosition = (@cursorPosition + 1) % (@buffer.size + 1)
|
348
|
+
update
|
349
|
+
end
|
350
|
+
end
|
351
|
+
nil
|
352
|
+
end
|
353
|
+
|
354
|
+
def end_buffer!
|
355
|
+
unless @handle_mode == :history_search!
|
356
|
+
@cursorPosition = @buffer.size
|
357
|
+
update
|
358
|
+
end
|
359
|
+
nil
|
360
|
+
end
|
361
|
+
|
362
|
+
def two_step_quit!
|
363
|
+
if @user_quit then
|
364
|
+
quit
|
365
|
+
else
|
366
|
+
@user_quit = true
|
367
|
+
info "Press <key> again within 5 seconds to quit."
|
368
|
+
Thread.new do
|
369
|
+
sleep(5)
|
370
|
+
@user_quit = false
|
371
|
+
end
|
372
|
+
end
|
373
|
+
nil
|
374
|
+
end
|
375
|
+
|
376
|
+
def toggle_history_search!
|
377
|
+
if @handle_mode == :append_buffer!
|
378
|
+
enable_history_search!
|
379
|
+
else
|
380
|
+
disable_history_search!
|
381
|
+
end
|
382
|
+
nil
|
383
|
+
end
|
384
|
+
|
385
|
+
def enable_history_search!
|
386
|
+
if @handle_mode == :append_buffer!
|
387
|
+
@historyPointer = 0
|
388
|
+
@handle_mode = :history_search!
|
389
|
+
@search_buffer = @buffer
|
390
|
+
update_history_search!
|
391
|
+
end
|
392
|
+
nil
|
393
|
+
end
|
394
|
+
|
395
|
+
def disable_history_search!
|
396
|
+
unless @handle_mode == :append_buffer!
|
397
|
+
@historyPointer = nil
|
398
|
+
@handle_mode = :append_buffer!
|
399
|
+
@buffer = @found_history || ""
|
400
|
+
@cursorPosition = @buffer.size
|
401
|
+
@search_buffer = ""
|
402
|
+
update
|
403
|
+
end
|
404
|
+
nil
|
405
|
+
end
|
406
|
+
|
407
|
+
def update_history_search!
|
408
|
+
@search_buffer ||= ""
|
409
|
+
@found_history_array = @history.reverse.select do |line|
|
410
|
+
line.match(Regexp.new(@search_buffer))
|
411
|
+
end
|
412
|
+
@found_history_array << "" if @found_history_array.empty?
|
413
|
+
@found_history = @found_history_array[@historyPointer % @found_history_array.size]
|
414
|
+
@buffer = "(#{@search_buffer}): `#{@found_history}`"
|
415
|
+
@cursorPosition = @search_buffer.size + 1
|
416
|
+
update
|
417
|
+
end
|
418
|
+
|
419
|
+
def history_search!(c)
|
420
|
+
@search_buffer << c.chr
|
421
|
+
update_history_search!
|
422
|
+
end
|
423
|
+
|
424
|
+
def append_buffer!(c)
|
425
|
+
@buffer = @buffer[0, @cursorPosition] + c.chr + @buffer[@cursorPosition, @buffer.size - @cursorPosition]
|
426
|
+
@cursorPosition = @cursorPosition + 1
|
427
|
+
update
|
428
|
+
nil
|
429
|
+
end
|
430
|
+
|
431
|
+
def scroll_up!(input_window)
|
432
|
+
Muby::OutputWindow.get_instance.scroll_up(input_window)
|
433
|
+
nil
|
434
|
+
end
|
435
|
+
|
436
|
+
def scroll_down!(input_window)
|
437
|
+
Muby::OutputWindow.get_instance.scroll_down(input_window)
|
438
|
+
nil
|
439
|
+
end
|
440
|
+
|
441
|
+
def toggle_verbosity!
|
442
|
+
conf.toggle_verbosity!
|
443
|
+
nil
|
444
|
+
end
|
445
|
+
|
446
|
+
def print(*message)
|
447
|
+
oldStyle = Muby::Style.extract(Muby::OutputWindow.get_instance.outputBuffer)
|
448
|
+
Muby::OutputWindow.get_instance.print(*(message + [oldStyle]))
|
449
|
+
end
|
450
|
+
|
451
|
+
#
|
452
|
+
# Echoes a message, if we want to (conf.echo)
|
453
|
+
#
|
454
|
+
def echo(*message)
|
455
|
+
if conf.echo
|
456
|
+
style = Muby::Style.new(conf.echo_attributes, conf.echo_colors[0], conf.echo_colors[1])
|
457
|
+
oldStyle = Muby::Style.extract(Muby::OutputWindow.get_instance.outputBuffer)
|
458
|
+
Muby::OutputWindow.get_instance.print_on_newline(*([style] + message + [oldStyle]))
|
459
|
+
end
|
460
|
+
end
|
461
|
+
end
|
462
|
+
|
463
|
+
end
|