summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKyrylo Silin <silin@kyrylo.org>2018-10-22 04:52:32 +0800
committerGitHub <noreply@github.com>2018-10-22 04:52:32 +0800
commit12b69fb6279f05d77ff595d3729b800cdef87b86 (patch)
tree431aadbe0163d0b61369a7b9d7e9debcca650c7f
parentafa3a1cb0eb84e4ae7b01591bb5c340420880a3b (diff)
parent7d51b040adcb6f37c903db75d8193c3d2963e13f (diff)
downloadpry-12b69fb6279f05d77ff595d3729b800cdef87b86.tar.gz
Merge pull request #1821 from pry/correct-indentation-refactoring
indent: tidy up #correct_indentation
-rw-r--r--lib/pry/indent.rb21
1 files changed, 10 insertions, 11 deletions
diff --git a/lib/pry/indent.rb b/lib/pry/indent.rb
index 315b6a55..2a77c0a8 100644
--- a/lib/pry/indent.rb
+++ b/lib/pry/indent.rb
@@ -382,25 +382,24 @@ class Pry
# the correct indentation. Mostly useful for fixing 'end'.
#
# @param [String] prompt The user's prompt
- # @param [String] code The code the user just typed in.
- # @param [Fixnum] overhang (0) The number of chars to erase afterwards (i.e.,
- # the difference in length between the old line and the new one).
- # @return [String]
- def correct_indentation(prompt, code, overhang=0)
+ # @param [String] code The code the user just typed in
+ # @param [Integer] overhang The number of characters to erase afterwards (the
+ # the difference in length between the old line and the new one)
+ #
+ # @return [String] correctly indented line
+ def correct_indentation(prompt, code, overhang = 0)
prompt = prompt.delete("\001\002")
line_to_measure = Pry::Helpers::Text.strip_color(prompt) << code
whitespace = ' ' * overhang
- _, cols = Terminal.screen_size
-
- cols = cols.to_i
- lines = (cols != 0 ? (line_to_measure.length / cols + 1) : 1).to_i
+ cols = Terminal.width!
+ lines = cols == 0 ? 1 : (line_to_measure.length / cols + 1).to_i
if Pry::Helpers::BaseHelpers.windows_ansi?
- move_up = "\e[#{lines}F"
+ move_up = "\e[#{lines}F"
move_down = "\e[#{lines}E"
else
- move_up = "\e[#{lines}A\e[0G"
+ move_up = "\e[#{lines}A\e[0G"
move_down = "\e[#{lines}B\e[0G"
end