Simplify Tty methods.
This commit is contained in:
parent
786f5d359f
commit
0cafa83f8a
@ -63,27 +63,22 @@ module Tty
|
|||||||
|
|
||||||
sig { returns(T.nilable([Integer, Integer])) }
|
sig { returns(T.nilable([Integer, Integer])) }
|
||||||
def size
|
def size
|
||||||
`/bin/stty size 2>/dev/null`.presence&.split&.map(&:to_i)
|
return @size if defined?(@size)
|
||||||
|
|
||||||
|
height, width = `/bin/stty size 2>/dev/null`.presence&.split&.map(&:to_i)
|
||||||
|
return if height.nil? || width.nil?
|
||||||
|
|
||||||
|
@size = [height, width]
|
||||||
end
|
end
|
||||||
|
|
||||||
sig { returns(Integer) }
|
sig { returns(Integer) }
|
||||||
def height
|
def height
|
||||||
@height ||= begin
|
@height ||= size&.first || `/usr/bin/tput lines 2>/dev/null`.presence&.to_i || 40
|
||||||
height, = size
|
|
||||||
height, = `/usr/bin/tput lines 2>/dev/null`.split if height.zero?
|
|
||||||
height ||= 40
|
|
||||||
height.to_i
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
|
|
||||||
sig { returns(Integer) }
|
sig { returns(Integer) }
|
||||||
def width
|
def width
|
||||||
@width ||= begin
|
@width ||= size&.second || `/usr/bin/tput cols 2>/dev/null`.presence&.to_i || 80
|
||||||
_, width = size
|
|
||||||
width, = `/usr/bin/tput cols 2>/dev/null`.split if width.zero?
|
|
||||||
width ||= 80
|
|
||||||
width.to_i
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
|
|
||||||
sig { params(string: String).returns(String) }
|
sig { params(string: String).returns(String) }
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user