Class: ITerm2::Protocol::FileSequence

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

Overview

Escape sequence for use file downloads.

Direct Known Subclasses

ImageSequence

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(attributes = {}) ⇒ FileSequence

Returns a new instance of FileSequence.

Raises:

  • (ArgumentError)


21
22
23
24
25
26
27
# File 'lib/iterm2/protocol/file_sequence.rb', line 21

def initialize(attributes={})
  @inline = false

  update_attributes(attributes)

  raise ArgumentError, "path must be given" if @path.nil?
end

Class Method Details

.format(attributes = {}) ⇒ Object



13
14
15
# File 'lib/iterm2/protocol/file_sequence.rb', line 13

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

Instance Method Details

#inlineBoolean

Get whether the file will be displayed inline.

Returns:

  • (Boolean)


# File 'lib/iterm2/protocol/file_sequence.rb', line 41


#inline=Boolean

Set whether the file will be displayed inline.

Parameters:

  • value (Boolean)

Returns:

  • (Boolean)


51
# File 'lib/iterm2/protocol/file_sequence.rb', line 51

attribute(:inline, query: true)

#pathString

Get the path.

Returns:

  • (String)


# File 'lib/iterm2/protocol/file_sequence.rb', line 29


#path=String

Set the path.

Parameters:

Returns:

  • (String)


39
# File 'lib/iterm2/protocol/file_sequence.rb', line 39

attribute(:path) { |value| value.is_a?(Pathname) ? value : Pathname.new(value.to_s) }

#to_h(output = nil) ⇒ Hash

Return the arguments to this escape sequence.

Parameters:

  • output (nil, Symbol) (defaults to: nil)

    The output format to return the Hash for.

    Set to ‘:terminal` to format for an escape sequence.

Returns:

  • (Hash)


60
61
62
63
64
65
66
67
68
69
# File 'lib/iterm2/protocol/file_sequence.rb', line 60

def to_h(output=nil)
  result = {
    name: Base64.encode64(@path.to_s),
    size: @path.size
  }

  result[:inline] = output == :terminal ? (@inline ? 1 : 0) : @inline

  result
end

#to_s(attributes = {}) ⇒ String

Get the escape sequence.

Parameters:

  • attributes (#to_h) (defaults to: {})

    The attributes to pass to the ‘Formatter`.

Returns:

  • (String)


75
76
77
78
79
80
81
82
83
# File 'lib/iterm2/protocol/file_sequence.rb', line 75

def to_s(attributes={})
  attributes = {
    key: "File",
    value: to_h(:terminal),
    content: Base64.encode64(@path.read)
  }.merge(attributes)

  Formatter.format(attributes)
end