Module: TerminalImage

Defined in:
lib/terminal_image.rb,
lib/terminal_image/version.rb

Defined Under Namespace

Classes: UnsupportedTerminal

Constant Summary collapse

VERSION =
'1.0.0'

Class Method Summary collapse

Class Method Details

.encode(file) ⇒ Object



31
32
33
34
35
36
37
38
39
40
# File 'lib/terminal_image.rb', line 31

def encode(file)
  if ENV.fetch('TERM_PROGRAM', nil) == 'iTerm.app'
    encode_for_iterm2(file)
  elsif which 'img2sixel'
    encode_for_libsixel(file)
  else
    warn 'Use iTerm2 or install libsixel according to https://github.com/saitoha/libsixel#install'
    raise UnsupportedTerminal, 'Unsupported terminal'
  end
end

.encode_url(url) ⇒ Object



24
25
26
27
28
29
# File 'lib/terminal_image.rb', line 24

def encode_url(url)
  tempfile = Tempfile.create
  tempfile.binmode
  URI.parse(url).open { |o| tempfile.write o.read }
  TerminalImage.encode(tempfile)
end

.show(file) ⇒ Object



20
21
22
# File 'lib/terminal_image.rb', line 20

def show(file)
  puts encode(file)
end

.show_url(url) ⇒ Object



13
14
15
16
17
18
# File 'lib/terminal_image.rb', line 13

def show_url(url)
  tempfile = Tempfile.create
  tempfile.binmode
  URI.parse(url).open { |o| tempfile.write o.read }
  TerminalImage.show(tempfile)
end