Module: Tty Private

Defined in:
utils/tty.rb,
sorbet/rbi/dsl/tty.rbi

Overview

This module is part of a private API. This module may only be used in the Homebrew/brew repository. Third parties should avoid using this module if possible, as it may be removed or changed without warning.

Various helper functions for interacting with TTYs.

Constant Summary collapse

COLOR_CODES =

This constant is part of a private API. This constant may only be used in the Homebrew/brew repository. Third parties should avoid using this constant if possible, as it may be removed or changed without warning.

{
  red:     31,
  green:   32,
  yellow:  33,
  blue:    34,
  magenta: 35,
  cyan:    36,
  default: 39,
}.freeze
STYLE_CODES =

This constant is part of a private API. This constant may only be used in the Homebrew/brew repository. Third parties should avoid using this constant if possible, as it may be removed or changed without warning.

{
  reset:         0,
  bold:          1,
  italic:        3,
  underline:     4,
  strikethrough: 9,
  no_underline:  24,
}.freeze
SPECIAL_CODES =

This constant is part of a private API. This constant may only be used in the Homebrew/brew repository. Third parties should avoid using this constant if possible, as it may be removed or changed without warning.

{
  up:         "1A",
  down:       "1B",
  right:      "1C",
  left:       "1D",
  erase_line: "K",
  erase_char: "P",
}.freeze
CODES =

This constant is part of a private API. This constant may only be used in the Homebrew/brew repository. Third parties should avoid using this constant if possible, as it may be removed or changed without warning.

COLOR_CODES.merge(STYLE_CODES).freeze

Class Method Summary collapse

Class Method Details

.blueString

This method is part of a private API. This method may only be used in the Homebrew/brew repository. Third parties should avoid using this method if possible, as it may be removed or changed without warning.

Returns:



11
# File 'sorbet/rbi/dsl/tty.rbi', line 11

def blue; end

.boldString

This method is part of a private API. This method may only be used in the Homebrew/brew repository. Third parties should avoid using this method if possible, as it may be removed or changed without warning.

Returns:



14
# File 'sorbet/rbi/dsl/tty.rbi', line 14

def bold; end

.color?Boolean

This method is part of a private API. This method may only be used in the Homebrew/brew repository. Third parties should avoid using this method if possible, as it may be removed or changed without warning.

Returns:

  • (Boolean)


109
110
111
112
113
114
115
116
# File 'utils/tty.rb', line 109

def color?
  require "env_config"

  return false if Homebrew::EnvConfig.no_color?
  return true if Homebrew::EnvConfig.color?

  @stream.tty?
end

.current_escape_sequenceString

This method is part of a private API. This method may only be used in the Homebrew/brew repository. Third parties should avoid using this method if possible, as it may be removed or changed without warning.

Returns:



70
71
72
73
74
# File 'utils/tty.rb', line 70

def current_escape_sequence
  return "" if @escape_sequence.nil?

  "\033[#{@escape_sequence.join(";")}m"
end

.cyanString

This method is part of a private API. This method may only be used in the Homebrew/brew repository. Third parties should avoid using this method if possible, as it may be removed or changed without warning.

Returns:



17
# File 'sorbet/rbi/dsl/tty.rbi', line 17

def cyan; end

.defaultString

This method is part of a private API. This method may only be used in the Homebrew/brew repository. Third parties should avoid using this method if possible, as it may be removed or changed without warning.

Returns:



20
# File 'sorbet/rbi/dsl/tty.rbi', line 20

def default; end

.downString

This method is part of a private API. This method may only be used in the Homebrew/brew repository. Third parties should avoid using this method if possible, as it may be removed or changed without warning.

Returns:



23
# File 'sorbet/rbi/dsl/tty.rbi', line 23

def down; end

.erase_charString

This method is part of a private API. This method may only be used in the Homebrew/brew repository. Third parties should avoid using this method if possible, as it may be removed or changed without warning.

Returns:



26
# File 'sorbet/rbi/dsl/tty.rbi', line 26

def erase_char; end

.erase_lineString

This method is part of a private API. This method may only be used in the Homebrew/brew repository. Third parties should avoid using this method if possible, as it may be removed or changed without warning.

Returns:



29
# File 'sorbet/rbi/dsl/tty.rbi', line 29

def erase_line; end

.greenString

This method is part of a private API. This method may only be used in the Homebrew/brew repository. Third parties should avoid using this method if possible, as it may be removed or changed without warning.

Returns:



32
# File 'sorbet/rbi/dsl/tty.rbi', line 32

def green; end

.italicString

This method is part of a private API. This method may only be used in the Homebrew/brew repository. Third parties should avoid using this method if possible, as it may be removed or changed without warning.

Returns:



35
# File 'sorbet/rbi/dsl/tty.rbi', line 35

def italic; end

.leftString

This method is part of a private API. This method may only be used in the Homebrew/brew repository. Third parties should avoid using this method if possible, as it may be removed or changed without warning.

Returns:



38
# File 'sorbet/rbi/dsl/tty.rbi', line 38

def left; end

.magentaString

This method is part of a private API. This method may only be used in the Homebrew/brew repository. Third parties should avoid using this method if possible, as it may be removed or changed without warning.

Returns:



41
# File 'sorbet/rbi/dsl/tty.rbi', line 41

def magenta; end

.no_underlineString

This method is part of a private API. This method may only be used in the Homebrew/brew repository. Third parties should avoid using this method if possible, as it may be removed or changed without warning.

Returns:



44
# File 'sorbet/rbi/dsl/tty.rbi', line 44

def no_underline; end

.redString

This method is part of a private API. This method may only be used in the Homebrew/brew repository. Third parties should avoid using this method if possible, as it may be removed or changed without warning.

Returns:



47
# File 'sorbet/rbi/dsl/tty.rbi', line 47

def red; end

.resetString

This method is part of a private API. This method may only be used in the Homebrew/brew repository. Third parties should avoid using this method if possible, as it may be removed or changed without warning.

Returns:



50
# File 'sorbet/rbi/dsl/tty.rbi', line 50

def reset; end

.reset_escape_sequence!void

This method is part of a private API. This method may only be used in the Homebrew/brew repository. Third parties should avoid using this method if possible, as it may be removed or changed without warning.

This method returns an undefined value.



77
78
79
# File 'utils/tty.rb', line 77

def reset_escape_sequence!
  @escape_sequence = nil
end

.rightString

This method is part of a private API. This method may only be used in the Homebrew/brew repository. Third parties should avoid using this method if possible, as it may be removed or changed without warning.

Returns:



53
# File 'sorbet/rbi/dsl/tty.rbi', line 53

def right; end

.strikethroughString

This method is part of a private API. This method may only be used in the Homebrew/brew repository. Third parties should avoid using this method if possible, as it may be removed or changed without warning.

Returns:



56
# File 'sorbet/rbi/dsl/tty.rbi', line 56

def strikethrough; end

.strip_ansi(string) ⇒ String

This method is part of a private API. This method may only be used in the Homebrew/brew repository. Third parties should avoid using this method if possible, as it may be removed or changed without warning.

Parameters:

Returns:



50
51
52
# File 'utils/tty.rb', line 50

def strip_ansi(string)
  string.gsub(/\033\[\d+(;\d+)*m/, "")
end

.truncate(string) ⇒ String

This method is part of a private API. This method may only be used in the Homebrew/brew repository. Third parties should avoid using this method if possible, as it may be removed or changed without warning.

Parameters:

Returns:



65
66
67
# File 'utils/tty.rb', line 65

def truncate(string)
  (w = width).zero? ? string.to_s : (string.to_s[0, w - 4] || "")
end

.underlineString

This method is part of a private API. This method may only be used in the Homebrew/brew repository. Third parties should avoid using this method if possible, as it may be removed or changed without warning.

Returns:



59
# File 'sorbet/rbi/dsl/tty.rbi', line 59

def underline; end

.upString

This method is part of a private API. This method may only be used in the Homebrew/brew repository. Third parties should avoid using this method if possible, as it may be removed or changed without warning.

Returns:



62
# File 'sorbet/rbi/dsl/tty.rbi', line 62

def up; end

.widthInteger

This method is part of a private API. This method may only be used in the Homebrew/brew repository. Third parties should avoid using this method if possible, as it may be removed or changed without warning.

Returns:

  • (Integer)


55
56
57
58
59
60
61
62
# File 'utils/tty.rb', line 55

def width
  @width ||= begin
    _, width = `/bin/stty size 2>/dev/null`.split
    width, = `/usr/bin/tput cols 2>/dev/null`.split if width.to_i.zero?
    width ||= 80
    width.to_i
  end
end

.with(stream, &_block) ⇒ void

This method is part of a private API. This method may only be used in the Homebrew/brew repository. Third parties should avoid using this method if possible, as it may be removed or changed without warning.

This method returns an undefined value.

Parameters:

  • stream (IO, StringIO)
  • _block (T.proc.params(arg0: T.any(IO, StringIO)).void)


40
41
42
43
44
45
46
47
# File 'utils/tty.rb', line 40

def with(stream, &_block)
  previous_stream = @stream
  @stream = stream

  yield stream
ensure
  @stream = previous_stream
end

.yellowString

This method is part of a private API. This method may only be used in the Homebrew/brew repository. Third parties should avoid using this method if possible, as it may be removed or changed without warning.

Returns:



65
# File 'sorbet/rbi/dsl/tty.rbi', line 65

def yellow; end