1
0
Fork 0
mirror of https://github.com/pry/pry.git synced 2022-11-09 12:35:05 -05:00

make sure we're printing to the right output

This commit is contained in:
Ryan Fitzgerald 2011-10-09 12:13:39 -07:00
parent 844231ac39
commit 037dc17c82
2 changed files with 6 additions and 5 deletions

View file

@ -169,10 +169,11 @@ class Pry
(last_token =~ /^[)\]}\/]$/ || STATEMENT_END_TOKENS.include?(last_kind))
end
# Fix the indentation for closing tags (notably 'end').
# Return a string which, when printed, will rewrite the previous line with
# the correct indentation. Mostly useful for fixing 'end'.
#
# @param [String] full_line The full line of input, including the prompt.
#
# @return [String]
def correct_indentation(full_line)
rws, cols = Readline.get_screen_size
lines = full_line.length / cols
@ -180,7 +181,7 @@ class Pry
kill_line = "\e[0K"
move_down = "\e[#{lines}E"
$stdout.print(move_up, full_line, kill_line, move_down)
"#{move_up}#{full_line}#{kill_line}#{move_down}"
end
end
end

View file

@ -311,8 +311,8 @@ class Pry
if !@command_processor.valid_command?(val, target) && Pry.config.auto_indent && input == Readline
val = @indent.indent(val)
if Pry::Helpers::BaseHelpers.use_ansi_codes?
@indent.correct_indentation(current_prompt + val)
if output.tty? && Pry::Helpers::BaseHelpers.use_ansi_codes?
output.print @indent.correct_indentation(current_prompt + val)
end
end