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
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def use_ansi_codes?
|
||||||
|
ENV['TERM'] != "dumb"
|
||||||
|
end
|
||||||
|
|
||||||
def colorize_code(code)
|
def colorize_code(code)
|
||||||
if Pry.color
|
if Pry.color
|
||||||
CodeRay.scan(code, :ruby).term
|
CodeRay.scan(code, :ruby).term
|
||||||
|
|
|
@ -9,7 +9,7 @@ class Pry
|
||||||
# will be indented or un-indented by correctly.
|
# will be indented or un-indented by correctly.
|
||||||
#
|
#
|
||||||
class Indent
|
class Indent
|
||||||
# Array containing all the indentation levels.
|
# String containing the spaces to be inserted before the next line.
|
||||||
attr_reader :indent_level
|
attr_reader :indent_level
|
||||||
|
|
||||||
# The amount of spaces to insert for each 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))
|
(last_token =~ /^[)\]}\/]$/ || STATEMENT_END_TOKENS.include?(last_kind))
|
||||||
end
|
end
|
||||||
|
|
||||||
# Fix the indentation for closing tags (notably 'end'). This method currently
|
# Fix the indentation for closing tags (notably 'end').
|
||||||
# does nothing on Windows, since `tput` isn't supported.
|
|
||||||
#
|
#
|
||||||
# @param [String] full_line The full line of input, including the prompt.
|
# @param [String] full_line The full line of input, including the prompt.
|
||||||
#
|
#
|
||||||
def correct_indentation(full_line)
|
def correct_indentation(full_line)
|
||||||
if !Kernel.const_defined?(:Win32)
|
rws, cols = Readline.get_screen_size
|
||||||
# The whitespace is used to "clear" the current line so existing
|
lines = full_line.length / cols
|
||||||
# characters don't show up.
|
move_up = "\e[#{lines+1}F"
|
||||||
spaces = ' ' * full_line.length
|
kill_line = "\e[0K"
|
||||||
|
move_down = "\e[#{lines}E"
|
||||||
|
|
||||||
$stdout.write(`tput sc` + `tput cuu1` + full_line + spaces + `tput rc`)
|
$stdout.print(move_up, full_line, kill_line, move_down)
|
||||||
end
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -185,7 +185,7 @@ class Pry
|
||||||
config.exception_whitelist = DEFAULT_EXCEPTION_WHITELIST
|
config.exception_whitelist = DEFAULT_EXCEPTION_WHITELIST
|
||||||
config.hooks = DEFAULT_HOOKS
|
config.hooks = DEFAULT_HOOKS
|
||||||
config.input_stack = []
|
config.input_stack = []
|
||||||
config.color = true
|
config.color = Pry::Helpers::BaseHelpers.use_ansi_codes?
|
||||||
config.pager = true
|
config.pager = true
|
||||||
config.system = DEFAULT_SYSTEM
|
config.system = DEFAULT_SYSTEM
|
||||||
config.editor = default_editor_for_platform
|
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
|
if !@command_processor.valid_command?(val, target) && Pry.config.auto_indent && input == Readline
|
||||||
val = @indent.indent(val)
|
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
|
end
|
||||||
|
|
||||||
Pry.history << val.dup
|
Pry.history << val.dup
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue