diff --git a/lib/pry/indent.rb b/lib/pry/indent.rb index a1a6c000..66eb8f06 100644 --- a/lib/pry/indent.rb +++ b/lib/pry/indent.rb @@ -132,5 +132,16 @@ class Pry return output.gsub!(/\s+$/, '') end + + + # Fix the indentation for closing tags (notably 'end'). + # @param [String] full_line The full line of input, including the prompt. + def correct_indentation(full_line) + # The whitespace is used to "clear" the current line so existing + # characters don't show up. + spaces = ' ' * full_line.length + + $stdout.write(`tput sc` + `tput cuu1` + full_line + spaces + `tput rc`) + end end # Indent end # Pry diff --git a/lib/pry/pry_instance.rb b/lib/pry/pry_instance.rb index b8820099..4b85caf4 100644 --- a/lib/pry/pry_instance.rb +++ b/lib/pry/pry_instance.rb @@ -311,13 +311,7 @@ class Pry # Refresh the current line. This uses tput and since that doesn't work # on Windows this process will not be executed on that platform. if !Kernel.const_defined?(:Win32) && input == Readline - prompt = current_prompt + val - - # The whitespace is used to "clear" the current line so existing - # characters don't show up. - spaces = ' ' * prompt.length - - $stdout.write(`tput sc` + `tput cuu1` + prompt + spaces + `tput rc`) + @indent.correct_indentation(current_prompt + val) end end