@@ -46,6 +46,7 @@ def initialize(prompt, prompt_char = '>', histfile = nil, framework = nil)
46
46
47
47
# Initialize the prompt
48
48
self . init_prompt = prompt
49
+ self . cont_prompt = ' > '
49
50
self . prompt_char = prompt_char
50
51
51
52
self . histfile = histfile
@@ -185,17 +186,14 @@ def run(&block)
185
186
self . init_prompt = input . prompt
186
187
end
187
188
188
- output . input = input
189
- line = input . pgets ( )
190
- output . input = nil
191
- log_output ( input . prompt )
189
+ line = get_input_line
192
190
193
191
# If a block was passed in, pass the line to it. If it returns true,
194
192
# break out of the shell loop.
195
193
if ( block )
196
194
break if ( line == nil or block . call ( line ) )
197
195
elsif ( input . eof? or line == nil )
198
- # If you have sessions active, this will give you a shot to exit gravefully
196
+ # If you have sessions active, this will give you a shot to exit gracefully
199
197
# If you really are ambitious, 2 eofs will kick this out
200
198
self . stop_count += 1
201
199
next if ( self . stop_count > 1 )
@@ -350,6 +348,37 @@ def print(msg='')
350
348
351
349
protected
352
350
351
+ #
352
+ # Get a single line of input, following continuation directives as necessary.
353
+ #
354
+ def get_input_line
355
+ line = "\\ \n "
356
+ prompt_needs_reset = false
357
+
358
+ while line =~ /(^|[^\\ ])\\ \s *$/
359
+ # Strip \ and all the trailing whitespace
360
+ line . sub! ( /\\ \s */ , '' )
361
+
362
+ if line . length > 0
363
+ # Using update_prompt will overwrite the primary prompt
364
+ input . prompt = output . update_prompt ( self . cont_prompt )
365
+ prompt_needs_reset = true
366
+ end
367
+
368
+ output . input = input
369
+ line << input . pgets ( )
370
+ output . input = nil
371
+ log_output ( input . prompt )
372
+ end
373
+
374
+ if prompt_needs_reset
375
+ # The continuation prompt was used so reset the prompt
376
+ update_prompt
377
+ end
378
+
379
+ line
380
+ end
381
+
353
382
#
354
383
# Parse a line into an array of arguments.
355
384
#
@@ -389,7 +418,7 @@ def log_output(buf)
389
418
end
390
419
391
420
attr_writer :input , :output # :nodoc:
392
- attr_accessor :stop_flag , :init_prompt # :nodoc:
421
+ attr_accessor :stop_flag , :init_prompt , :cont_prompt # :nodoc:
393
422
attr_accessor :prompt # :nodoc:
394
423
attr_accessor :prompt_char , :tab_complete_proc # :nodoc:
395
424
attr_accessor :histfile # :nodoc:
0 commit comments