Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Check `respond_to?(:winsize)` (fix #549)

  • Loading branch information...
commit 00f7877b0f8c3cdf3810093063e7f7c349d16749 1 parent 037b382
@rf- rf- authored
Showing with 6 additions and 10 deletions.
  1. +6 −10 lib/pry/indent.rb
View
16 lib/pry/indent.rb
@@ -1,12 +1,10 @@
require 'coderay'
class Pry
+ # Load io-console if possible, so that we can use $stdout.winsize.
begin
require 'io/console'
rescue LoadError
- IO_CONSOLE_AVAILABLE = false
- else
- IO_CONSOLE_AVAILABLE = true
end
##
@@ -292,19 +290,18 @@ def open_delimiters_line
# @return [String]
def correct_indentation(prompt, code, overhang=0)
full_line = prompt + code
- if IO_CONSOLE_AVAILABLE && $stdout.tty?
+ whitespace = ' ' * overhang
+
+ if $stdout.tty? && $stdout.respond_to?(:winsize)
_, cols = $stdout.winsize
- lines = full_line.length / cols + 1
elsif Readline.respond_to?(:get_screen_size)
_, cols = Readline.get_screen_size
- lines = full_line.length / cols + 1
elsif ENV['COLUMNS'] && ENV['COLUMNS'] != ''
cols = ENV['COLUMNS'].to_i
- lines = full_line.length / cols + 1
- else
- lines = 1
end
+ lines = cols ? (full_line.length / cols + 1) : 1
+
if defined?(Win32::Console)
move_up = "\e[#{lines}F"
move_down = "\e[#{lines}E"
@@ -312,7 +309,6 @@ def correct_indentation(prompt, code, overhang=0)
move_up = "\e[#{lines}A\e[0G"
move_down = "\e[#{lines}B\e[0G"
end
- whitespace = ' ' * overhang
"#{move_up}#{prompt}#{colorize_code(code)}#{whitespace}#{move_down}"
end
Please sign in to comment.
Something went wrong with that request. Please try again.