Class: Rich::ConsoleOptions

Inherits:
Object
  • Object
show all
Defined in:
lib/rich/console.rb

Overview

Console rendering options

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(min_width: 1, max_width: 80, height: nil, legacy_windows: false, encoding: "utf-8", is_terminal: true, highlight: true, markup: true, no_wrap: false) ⇒ ConsoleOptions

Returns a new instance of ConsoleOptions.



43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
# File 'lib/rich/console.rb', line 43

def initialize(
  min_width: 1,
  max_width: 80,
  height: nil,
  legacy_windows: false,
  encoding: "utf-8",
  is_terminal: true,
  highlight: true,
  markup: true,
  no_wrap: false
)
  @min_width = min_width
  @max_width = max_width
  @height = height
  @legacy_windows = legacy_windows
  @encoding = encoding
  @is_terminal = is_terminal
  @highlight = highlight
  @markup = markup
  @no_wrap = no_wrap
  freeze
end

Instance Attribute Details

#encodingString (readonly)

Returns Output encoding.

Returns:

  • (String)

    Output encoding



29
30
31
# File 'lib/rich/console.rb', line 29

def encoding
  @encoding
end

#heightInteger? (readonly)

Returns Height for rendering.

Returns:

  • (Integer, nil)

    Height for rendering



23
24
25
# File 'lib/rich/console.rb', line 23

def height
  @height
end

#highlightBoolean (readonly)

Returns Enable highlighting.

Returns:

  • (Boolean)

    Enable highlighting



35
36
37
# File 'lib/rich/console.rb', line 35

def highlight
  @highlight
end

#is_terminalBoolean (readonly)

Returns Terminal output.

Returns:

  • (Boolean)

    Terminal output



32
33
34
# File 'lib/rich/console.rb', line 32

def is_terminal
  @is_terminal
end

#legacy_windowsBoolean (readonly)

Returns Legacy Windows console mode.

Returns:

  • (Boolean)

    Legacy Windows console mode



26
27
28
# File 'lib/rich/console.rb', line 26

def legacy_windows
  @legacy_windows
end

#markupBoolean (readonly)

Returns Enable markup.

Returns:

  • (Boolean)

    Enable markup



38
39
40
# File 'lib/rich/console.rb', line 38

def markup
  @markup
end

#max_widthInteger (readonly)

Returns Maximum width for rendering.

Returns:

  • (Integer)

    Maximum width for rendering



20
21
22
# File 'lib/rich/console.rb', line 20

def max_width
  @max_width
end

#min_widthInteger (readonly)

Returns Minimum width for rendering.

Returns:

  • (Integer)

    Minimum width for rendering



17
18
19
# File 'lib/rich/console.rb', line 17

def min_width
  @min_width
end

#no_wrapBoolean (readonly)

Returns No wrapping.

Returns:

  • (Boolean)

    No wrapping



41
42
43
# File 'lib/rich/console.rb', line 41

def no_wrap
  @no_wrap
end

Instance Method Details

#update(**kwargs) ⇒ ConsoleOptions

Update options, returning a new instance

Returns:



68
69
70
71
72
73
74
75
76
77
78
79
80
# File 'lib/rich/console.rb', line 68

def update(**kwargs)
  ConsoleOptions.new(
    min_width: kwargs.fetch(:min_width, @min_width),
    max_width: kwargs.fetch(:max_width, @max_width),
    height: kwargs.fetch(:height, @height),
    legacy_windows: kwargs.fetch(:legacy_windows, @legacy_windows),
    encoding: kwargs.fetch(:encoding, @encoding),
    is_terminal: kwargs.fetch(:is_terminal, @is_terminal),
    highlight: kwargs.fetch(:highlight, @highlight),
    markup: kwargs.fetch(:markup, @markup),
    no_wrap: kwargs.fetch(:no_wrap, @no_wrap)
  )
end

#update_width(width) ⇒ ConsoleOptions

Update width

Parameters:

  • width (Integer)

    New width

Returns:



85
86
87
# File 'lib/rich/console.rb', line 85

def update_width(width)
  update(min_width: width, max_width: width)
end