Skip to content

Commit

Permalink
Simplify Tty methods.
Browse files Browse the repository at this point in the history
  • Loading branch information
reitermarkus committed Jul 16, 2024
1 parent 73fd778 commit ed41a39
Showing 1 changed file with 8 additions and 13 deletions.
21 changes: 8 additions & 13 deletions Library/Homebrew/utils/tty.rb
Original file line number Diff line number Diff line change
Expand Up @@ -63,27 +63,22 @@ def show_cursor

sig { returns(T.nilable([Integer, Integer])) }
def size
`/bin/stty size 2>/dev/null`.presence&.split&.map(&:to_i)
@size ||= begin
height, width = `/bin/stty size 2>/dev/null`.presence&.split&.map(&:to_i)
return if height.nil? || width.nil?

[height, width]
end
end

sig { returns(Integer) }
def height
@height ||= begin
height, = size
height, = `/usr/bin/tput lines 2>/dev/null`.split if height.zero?
height ||= 40
height.to_i
end
@height ||= size&.first || `/usr/bin/tput lines 2>/dev/null`.presence&.to_i || 40
end

sig { returns(Integer) }
def width
@width ||= begin
_, width = size
width, = `/usr/bin/tput cols 2>/dev/null`.split if width.zero?
width ||= 80
width.to_i
end
@width ||= size&.second || `/usr/bin/tput cols 2>/dev/null`.presence&.to_i || 80
end

sig { params(string: String).returns(String) }
Expand Down

0 comments on commit ed41a39

Please sign in to comment.