Class: ITerm2::Protocol::Formatter
- Inherits:
-
Object
- Object
- ITerm2::Protocol::Formatter
- Includes:
- Aspect::HasAttributes
- Defined in:
- lib/iterm2/protocol/formatter.rb
Class Method Summary collapse
Instance Method Summary collapse
-
#content ⇒ nil, String
Get the content.
-
#content= ⇒ nil, String
Set the content.
-
#initialize(attributes = {}) ⇒ Formatter
constructor
A new instance of Formatter.
-
#key ⇒ String
Get the key.
-
#key= ⇒ String
Set the key.
-
#tmux ⇒ Boolean
Get whether to format for tmux output.
-
#tmux= ⇒ Boolean
Set whether to format for tmux output.
-
#to_s ⇒ String
Get the key-value pair formatted as an iTerm2 escape sequence.
-
#value ⇒ Hash, String
Get the value.
-
#value= ⇒ Hash, String
Set the value.
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
#content ⇒ nil, String
Get the content.
|
|
# File 'lib/iterm2/protocol/formatter.rb', line 48
|
#content= ⇒ nil, String
Set the content.
58 |
# File 'lib/iterm2/protocol/formatter.rb', line 58 attribute(:content) { |value| value.nil? ? nil : value.to_s } |
#key ⇒ String
Get the key.
|
|
# File 'lib/iterm2/protocol/formatter.rb', line 24
|
#key= ⇒ String
Set the key.
34 |
# File 'lib/iterm2/protocol/formatter.rb', line 34 attribute(:key) { |value| value.to_s } |
#tmux ⇒ Boolean
Get whether to format for tmux output.
|
|
# File 'lib/iterm2/protocol/formatter.rb', line 60
|
#tmux= ⇒ Boolean
Set whether to format for tmux output.
70 |
# File 'lib/iterm2/protocol/formatter.rb', line 70 attribute(:tmux, query: true) |
#to_s ⇒ String
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 (`;`).
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 |
#value ⇒ Hash, String
Get the value.
|
|
# File 'lib/iterm2/protocol/formatter.rb', line 36
|
#value= ⇒ Hash, String
Set the value.
46 |
# File 'lib/iterm2/protocol/formatter.rb', line 46 attribute(:value) { |value| value.respond_to?(:to_h) ? value.to_h : value.to_s } |