Class: ITerm2::Protocol::Formatter

Inherits:
Object
  • Object
show all
Includes:
Aspect::HasAttributes
Defined in:
lib/iterm2/protocol/formatter.rb

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(attributes = {}) ⇒ Formatter

Returns a new instance of Formatter.



18
19
20
21
22
# File 'lib/iterm2/protocol/formatter.rb', line 18

def initialize(attributes={})
  @tmux = ENV["TERM"] =~ /^screen/

  update_attributes(attributes)
end

Class Method Details

.format(attributes = {}) ⇒ Object



10
11
12
# File 'lib/iterm2/protocol/formatter.rb', line 10

def format(attributes={})
  new(attributes).to_s
end

Instance Method Details

#contentnil, String

Get the content.

Returns:

  • (nil, String)


# File 'lib/iterm2/protocol/formatter.rb', line 48


#content=nil, String

Set the content.

Parameters:

  • value (nil, #to_s)

Returns:

  • (nil, String)


58
# File 'lib/iterm2/protocol/formatter.rb', line 58

attribute(:content) { |value| value.nil? ? nil : value.to_s }

#keyString

Get the key.

Returns:

  • (String)


# File 'lib/iterm2/protocol/formatter.rb', line 24


#key=String

Set the key.

Parameters:

Returns:

  • (String)


34
# File 'lib/iterm2/protocol/formatter.rb', line 34

attribute(:key) { |value| value.to_s }

#tmuxBoolean

Get whether to format for tmux output.

Returns:

  • (Boolean)


# File 'lib/iterm2/protocol/formatter.rb', line 60


#tmux=Boolean

Set whether to format for tmux output.

Parameters:

  • value (Boolean)

Returns:

  • (Boolean)


70
# File 'lib/iterm2/protocol/formatter.rb', line 70

attribute(:tmux, query: true)

#to_sString

Get the key-value pair formatted as an iTerm2 escape sequence.

If the value is a Hash, it will be formatted as ‘key=value` with each pair being delimited by a semicolon (`;`).

Returns:

  • (String)


78
79
80
81
82
83
84
85
86
87
88
# File 'lib/iterm2/protocol/formatter.rb', line 78

def to_s
  [].tap do |segments|
    segments << escape_sequence
    segments << "1337;"
    segments << @key
    segments << "="
    segments << format_value(@value)
    segments << ":#{@content}" unless @content.nil?
    segments << st_sequence
  end.join
end

#valueHash, String

Get the value.

Returns:

  • (Hash, String)


# File 'lib/iterm2/protocol/formatter.rb', line 36


#value=Hash, String

Set the value.

Parameters:

  • value (#to_h, #to_s)

Returns:

  • (Hash, String)


46
# File 'lib/iterm2/protocol/formatter.rb', line 46

attribute(:value) { |value| value.respond_to?(:to_h) ? value.to_h : value.to_s }