class Selfie::ITerm2::Image

Attributes

path[R]

Public Class Methods

new(path, options = {}) click to toggle source
# File lib/selfie/iterm2/image.rb, line 8
def initialize(path, options = {})
  @path = path
  @options = options.dup
  @options[:inline] = 1
  @image = Base64.encode64(File.read(path))
end

Public Instance Methods

to_s(options = {}) click to toggle source
# File lib/selfie/iterm2/image.rb, line 15
def to_s(options = {})
  sprintf("%s1337;File=%s:%s%s", start_esc, format_options(options), @image, end_esc)
end

Private Instance Methods

end_esc() click to toggle source
# File lib/selfie/iterm2/image.rb, line 30
def end_esc
  @screen == true ? "\a\e\\" : "\a"
end
format_options(options) click to toggle source

# File lib/selfie/iterm2/image.rb, line 35
def format_options(options)
  @options.merge(options).map do |name, value|
    if name == :preserve_aspect_ratio
      name  = "preserveAspectRatio"
      value = value == false ? 0 : 1
    end

    sprintf "%s=%s", name, value
  end.join(";")
end
screen_tty?() click to toggle source
# File lib/selfie/iterm2/image.rb, line 21
def screen_tty?
  $stdout.tty? && ENV.include?("TERM") && ENV["TERM"].start_with?("screen")
end
start_esc() click to toggle source

From imgls: raw.githubusercontent.com/gnachman/iTerm2/master/tests/imgls

# File lib/selfie/iterm2/image.rb, line 26
def start_esc
  @screen == true ? "\ePtmux;\e\e]" : "\e]"
end