mirror of
https://github.com/pry/pry.git
synced 2022-11-09 12:35:05 -05:00
Use io/console to get console size when possible
This commit is contained in:
parent
74d3d0da48
commit
e4d1169afa
1 changed files with 12 additions and 1 deletions
|
@ -1,6 +1,14 @@
|
||||||
require 'coderay'
|
require 'coderay'
|
||||||
|
|
||||||
class Pry
|
class Pry
|
||||||
|
begin
|
||||||
|
require 'io/console'
|
||||||
|
rescue LoadError
|
||||||
|
IO_CONSOLE_AVAILABLE = false
|
||||||
|
else
|
||||||
|
IO_CONSOLE_AVAILABLE = true
|
||||||
|
end
|
||||||
|
|
||||||
##
|
##
|
||||||
# Pry::Indent is a class that can be used to indent a number of lines
|
# Pry::Indent is a class that can be used to indent a number of lines
|
||||||
# containing Ruby code similar as to how IRB does it (but better). The class
|
# containing Ruby code similar as to how IRB does it (but better). The class
|
||||||
|
@ -194,7 +202,10 @@ class Pry
|
||||||
# @return [String]
|
# @return [String]
|
||||||
def correct_indentation(prompt, code, overhang=0)
|
def correct_indentation(prompt, code, overhang=0)
|
||||||
full_line = prompt + code
|
full_line = prompt + code
|
||||||
if Readline.respond_to?(:get_screen_size)
|
if IO_CONSOLE_AVAILABLE && $stdout.tty?
|
||||||
|
_, cols = $stdout.winsize
|
||||||
|
lines = full_line.length / cols + 1
|
||||||
|
elsif Readline.respond_to?(:get_screen_size)
|
||||||
_, cols = Readline.get_screen_size
|
_, cols = Readline.get_screen_size
|
||||||
lines = full_line.length / cols + 1
|
lines = full_line.length / cols + 1
|
||||||
elsif ENV['COLUMNS'] && ENV['COLUMNS'] != ''
|
elsif ENV['COLUMNS'] && ENV['COLUMNS'] != ''
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue