mirror of
https://github.com/pry/pry.git
synced 2022-11-09 12:35:05 -05:00
replace tput
with ansi codes, and fix bug with long lines
This commit is contained in:
parent
88f65f3cb0
commit
844231ac39
4 changed files with 17 additions and 11 deletions
|
@ -65,6 +65,10 @@ class Pry
|
|||
end
|
||||
end
|
||||
|
||||
def use_ansi_codes?
|
||||
ENV['TERM'] != "dumb"
|
||||
end
|
||||
|
||||
def colorize_code(code)
|
||||
if Pry.color
|
||||
CodeRay.scan(code, :ruby).term
|
||||
|
|
|
@ -9,7 +9,7 @@ class Pry
|
|||
# will be indented or un-indented by correctly.
|
||||
#
|
||||
class Indent
|
||||
# Array containing all the indentation levels.
|
||||
# String containing the spaces to be inserted before the next line.
|
||||
attr_reader :indent_level
|
||||
|
||||
# The amount of spaces to insert for each indent level.
|
||||
|
@ -169,19 +169,18 @@ class Pry
|
|||
(last_token =~ /^[)\]}\/]$/ || STATEMENT_END_TOKENS.include?(last_kind))
|
||||
end
|
||||
|
||||
# Fix the indentation for closing tags (notably 'end'). This method currently
|
||||
# does nothing on Windows, since `tput` isn't supported.
|
||||
# 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)
|
||||
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
|
||||
rws, cols = Readline.get_screen_size
|
||||
lines = full_line.length / cols
|
||||
move_up = "\e[#{lines+1}F"
|
||||
kill_line = "\e[0K"
|
||||
move_down = "\e[#{lines}E"
|
||||
|
||||
$stdout.write(`tput sc` + `tput cuu1` + full_line + spaces + `tput rc`)
|
||||
end
|
||||
$stdout.print(move_up, full_line, kill_line, move_down)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -185,7 +185,7 @@ class Pry
|
|||
config.exception_whitelist = DEFAULT_EXCEPTION_WHITELIST
|
||||
config.hooks = DEFAULT_HOOKS
|
||||
config.input_stack = []
|
||||
config.color = true
|
||||
config.color = Pry::Helpers::BaseHelpers.use_ansi_codes?
|
||||
config.pager = true
|
||||
config.system = DEFAULT_SYSTEM
|
||||
config.editor = default_editor_for_platform
|
||||
|
|
|
@ -310,7 +310,10 @@ class Pry
|
|||
|
||||
if !@command_processor.valid_command?(val, target) && Pry.config.auto_indent && input == Readline
|
||||
val = @indent.indent(val)
|
||||
@indent.correct_indentation(current_prompt + val)
|
||||
|
||||
if Pry::Helpers::BaseHelpers.use_ansi_codes?
|
||||
@indent.correct_indentation(current_prompt + val)
|
||||
end
|
||||
end
|
||||
|
||||
Pry.history << val.dup
|
||||
|
|
Loading…
Reference in a new issue