Class: Chamomile::Options

Inherits:
Data
  • Object
show all
Defined in:
lib/chamomile/options.rb

Overview

Immutable configuration for a Program run.

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#alt_screenObject (readonly)

Returns the value of attribute alt_screen

Returns:

  • (Object)

    the current value of alt_screen



7
8
9
# File 'lib/chamomile/options.rb', line 7

def alt_screen
  @alt_screen
end

#bracketed_pasteObject (readonly)

Returns the value of attribute bracketed_paste

Returns:

  • (Object)

    the current value of bracketed_paste



7
8
9
# File 'lib/chamomile/options.rb', line 7

def bracketed_paste
  @bracketed_paste
end

#catch_panicsObject (readonly)

Returns the value of attribute catch_panics

Returns:

  • (Object)

    the current value of catch_panics



7
8
9
# File 'lib/chamomile/options.rb', line 7

def catch_panics
  @catch_panics
end

#filterObject (readonly)

Returns the value of attribute filter

Returns:

  • (Object)

    the current value of filter



7
8
9
# File 'lib/chamomile/options.rb', line 7

def filter
  @filter
end

#fpsObject (readonly)

Returns the value of attribute fps

Returns:

  • (Object)

    the current value of fps



7
8
9
# File 'lib/chamomile/options.rb', line 7

def fps
  @fps
end

#handle_signalsObject (readonly)

Returns the value of attribute handle_signals

Returns:

  • (Object)

    the current value of handle_signals



7
8
9
# File 'lib/chamomile/options.rb', line 7

def handle_signals
  @handle_signals
end

#initial_heightObject (readonly)

Returns the value of attribute initial_height

Returns:

  • (Object)

    the current value of initial_height



7
8
9
# File 'lib/chamomile/options.rb', line 7

def initial_height
  @initial_height
end

#initial_widthObject (readonly)

Returns the value of attribute initial_width

Returns:

  • (Object)

    the current value of initial_width



7
8
9
# File 'lib/chamomile/options.rb', line 7

def initial_width
  @initial_width
end

#inputObject (readonly)

Returns the value of attribute input

Returns:

  • (Object)

    the current value of input



7
8
9
# File 'lib/chamomile/options.rb', line 7

def input
  @input
end

#input_ttyObject (readonly)

Returns the value of attribute input_tty

Returns:

  • (Object)

    the current value of input_tty



7
8
9
# File 'lib/chamomile/options.rb', line 7

def input_tty
  @input_tty
end

#mouseObject (readonly)

Returns the value of attribute mouse

Returns:

  • (Object)

    the current value of mouse



7
8
9
# File 'lib/chamomile/options.rb', line 7

def mouse
  @mouse
end

#outputObject (readonly)

Returns the value of attribute output

Returns:

  • (Object)

    the current value of output



7
8
9
# File 'lib/chamomile/options.rb', line 7

def output
  @output
end

#report_focusObject (readonly)

Returns the value of attribute report_focus

Returns:

  • (Object)

    the current value of report_focus



7
8
9
# File 'lib/chamomile/options.rb', line 7

def report_focus
  @report_focus
end

#without_rendererObject (readonly)

Returns the value of attribute without_renderer

Returns:

  • (Object)

    the current value of without_renderer



7
8
9
# File 'lib/chamomile/options.rb', line 7

def without_renderer
  @without_renderer
end

Class Method Details

.default(**overrides) ⇒ Object



23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
# File 'lib/chamomile/options.rb', line 23

def self.default(**overrides)
  opts = new(alt_screen: true,
             mouse: :none,
             report_focus: false,
             bracketed_paste: true,
             fps: 60,
             input: $stdin,
             output: $stdout,
             filter: nil,
             catch_panics: true,
             handle_signals: true,
             input_tty: false,
             without_renderer: false,
             initial_width: nil,
             initial_height: nil, **overrides)

  opts.validate
  opts
end

Instance Method Details

#validateObject

Raises:

  • (ArgumentError)


43
44
45
46
47
48
49
50
51
52
53
# File 'lib/chamomile/options.rb', line 43

def validate
  unless VALID_MOUSE_MODES.include?(mouse)
    raise ArgumentError, "invalid mouse mode: #{mouse.inspect} (valid: #{VALID_MOUSE_MODES.join(", ")})"
  end

  unless fps.is_a?(Numeric) && fps >= 0
    raise ArgumentError, "fps must be a non-negative number, got: #{fps.inspect}"
  end

  raise ArgumentError, "filter must respond to #call, got: #{filter.class}" if filter && !filter.respond_to?(:call)
end