Class: TTY::Command::Window::WindowOptions

Inherits:
Struct
  • Object
show all
Defined in:
lib/tty/command/window/window_options.rb

Overview

Immutable, validated configuration for a single windowed run.

Built from the raw options hash the user passed to run_windowed by WindowOptions.build. Runner and Block consume named accessors on this object instead of dereferencing symbol keys, so the option contract is explicit.

Struct.new(..., keyword_init: true) is used (rather than Data.define) because Data.define ships in Ruby 3.2 and the gemspec's required_ruby_version floor is 3.1. Instances are frozen in WindowOptions.build for immutability.

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#captureObject

Returns the value of attribute capture

Returns:

  • (Object)

    the current value of capture



17
18
19
# File 'lib/tty/command/window/window_options.rb', line 17

def capture
  @capture
end

#capture_max_bytesObject

Returns the value of attribute capture_max_bytes

Returns:

  • (Object)

    the current value of capture_max_bytes



17
18
19
# File 'lib/tty/command/window/window_options.rb', line 17

def capture_max_bytes
  @capture_max_bytes
end

#interactiveObject

Returns the value of attribute interactive

Returns:

  • (Object)

    the current value of interactive



17
18
19
# File 'lib/tty/command/window/window_options.rb', line 17

def interactive
  @interactive
end

#linesObject

Returns the value of attribute lines

Returns:

  • (Object)

    the current value of lines



17
18
19
# File 'lib/tty/command/window/window_options.rb', line 17

def lines
  @lines
end

#on_exitObject

Returns the value of attribute on_exit

Returns:

  • (Object)

    the current value of on_exit



17
18
19
# File 'lib/tty/command/window/window_options.rb', line 17

def on_exit
  @on_exit
end

#output_logObject

Returns the value of attribute output_log

Returns:

  • (Object)

    the current value of output_log



17
18
19
# File 'lib/tty/command/window/window_options.rb', line 17

def output_log
  @output_log
end

#scrollbackObject

Returns the value of attribute scrollback

Returns:

  • (Object)

    the current value of scrollback



17
18
19
# File 'lib/tty/command/window/window_options.rb', line 17

def scrollback
  @scrollback
end

#titleObject

Returns the value of attribute title

Returns:

  • (Object)

    the current value of title



17
18
19
# File 'lib/tty/command/window/window_options.rb', line 17

def title
  @title
end

Class Method Details

.build(window_options, cmd) ⇒ WindowOptions

Parameters:

Returns:

Raises:

  • (ArgumentError)


26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
# File 'lib/tty/command/window/window_options.rb', line 26

def self.build(window_options, cmd)
  lines = Integer(window_options.fetch(:lines, DEFAULT_LINES))
  raise ArgumentError, "lines must be >= 1" if lines < 1

  on_exit = validated_enum(window_options, :on_exit, ON_EXIT_MODES, :freeze)
  capture = validated_enum(window_options, :capture, CAPTURE_MODES, :raw)

  capture_max_bytes = window_options.fetch(:capture_max_bytes, DEFAULT_CAPTURE_MAX_BYTES)
  unless capture_max_bytes.nil?
    capture_max_bytes = Integer(capture_max_bytes)
    raise ArgumentError, "capture_max_bytes must be >= 1 or nil" if capture_max_bytes < 1
  end

  Window.validate_on_unavailable!(window_options)

  title = window_options.fetch(:title, nil)
  title = cmd.to_command if title.nil?

  new(
    lines: lines,
    title: title,
    on_exit: on_exit,
    capture: capture,
    capture_max_bytes: capture_max_bytes,
    scrollback: Integer(window_options.fetch(:scrollback, DEFAULT_SCROLLBACK)),
    output_log: window_options[:output_log],
    interactive: window_options[:interactive] == true
  ).freeze
end

Instance Method Details

#capture_screen?Boolean

Returns:

  • (Boolean)


70
71
72
# File 'lib/tty/command/window/window_options.rb', line 70

def capture_screen?
  capture == :screen
end

#interactive?Boolean

Returns:

  • (Boolean)


66
67
68
# File 'lib/tty/command/window/window_options.rb', line 66

def interactive?
  interactive
end