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

fix command history to work with indentation

This commit is contained in:
Ryan Fitzgerald 2011-10-09 01:41:42 -07:00
parent 7694cfeaaa
commit 58f9c8b726
3 changed files with 13 additions and 19 deletions

View file

@ -34,7 +34,7 @@ class Pry
# @param [String] line
# @return [String] The same line that was passed in
def push(line)
unless line.empty? || (@history.last && line.strip == @history.last.strip)
unless line.empty? || (@history.last && line == @history.last)
Readline::HISTORY << line
@history << line
end

View file

@ -169,18 +169,19 @@ class Pry
(last_token =~ /^[)\]}\/]$/ || STATEMENT_END_TOKENS.include?(last_kind))
end
# Fix the indentation for closing tags (notably 'end'). Note that this
# method will not work on Win32 based systems (or other systems that don't
# have the tput command).
# Fix the indentation for closing tags (notably 'end'). This method currently
# does nothing on Windows, since `tput` isn't supported.
#
# @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
if !Kernel.const_defined?(:Win32)
# 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`)
$stdout.write(`tput sc` + `tput cuu1` + full_line + spaces + `tput rc`)
end
end
end
end

View file

@ -301,7 +301,6 @@ class Pry
@indent.reset if Pry.config.auto_indent
""
else
# Change the eval_string into the input encoding (Issue 284)
# TODO: This wouldn't be necessary if the eval_string was constructed from
# input strings only.
@ -309,16 +308,12 @@ class Pry
eval_string.force_encoding(val.encoding)
end
if !@command_processor.valid_command?(val, target) && Pry.config.auto_indent
if !@command_processor.valid_command?(val, target) && Pry.config.auto_indent && input == Readline
val = @indent.indent(val)
# 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
@indent.correct_indentation(current_prompt + val)
end
@indent.correct_indentation(current_prompt + val)
end
Pry.history << val.dup
val
end
end
@ -443,9 +438,7 @@ class Pry
handle_read_errors do
if input == Readline
line = input.readline(current_prompt, false)
Pry.history << line.dup if line
line
input.readline(current_prompt, false) # false since we'll add it manually
else
if input.method(:readline).arity == 1
input.readline(current_prompt)