Skip to content

Commit 36e8f7a

Browse files
committed
Land rapid7#9585, fix ctrl-D handling with block continuation
2 parents 42b4381 + 99965c1 commit 36e8f7a

File tree

1 file changed

+19
-11
lines changed

1 file changed

+19
-11
lines changed

lib/rex/ui/text/shell.rb

Lines changed: 19 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,7 @@ def run(&block)
128128

129129
while true
130130
# If the stop flag was set or we've hit EOF, break out
131-
break if (self.stop_flag or self.stop_count > 1)
131+
break if self.stop_flag || self.stop_count > 1
132132

133133
init_tab_complete
134134

@@ -190,19 +190,21 @@ def run(&block)
190190

191191
line = get_input_line
192192

193-
# If a block was passed in, pass the line to it. If it returns true,
194-
# break out of the shell loop.
195-
if (block)
196-
break if (line == nil or block.call(line))
197-
elsif(input.eof? or line == nil)
198-
# If you have sessions active, this will give you a shot to exit gracefully
199-
# If you really are ambitious, 2 eofs will kick this out
193+
# If you have sessions active, this will give you a shot to exit
194+
# gracefully. If you really are ambitious, 2 eofs will kick this out
195+
if input.eof? || line == nil
200196
self.stop_count += 1
201-
next if(self.stop_count > 1)
197+
next if self.stop_count > 1
202198
run_single("quit")
203-
else
199+
200+
# If a block was passed in, pass the line to it. If it returns true,
201+
# break out of the shell loop.
202+
elsif block
203+
break if block.call(line)
204+
204205
# Otherwise, call what should be an overriden instance method to
205206
# process the line.
207+
else
206208
ret = run_single(line)
207209
# don't bother saving lines that couldn't be found as a
208210
# command, create the file if it doesn't exist
@@ -370,7 +372,13 @@ def get_input_line
370372
end
371373

372374
output.input = input
373-
line << input.pgets
375+
str = input.pgets
376+
if str
377+
line << str
378+
else
379+
line = nil
380+
end
381+
374382
output.input = nil
375383
log_output(input.prompt)
376384
end

0 commit comments

Comments
 (0)