Class: Twterm::PhotoViewerBackend::ImgcatBackend

Inherits:
AbstractPhotoViewerBackend show all
Includes:
Twterm::Publisher
Defined in:
lib/twterm/photo_viewer_backend/imgcat_backend.rb

Instance Method Summary collapse

Methods included from Twterm::Publisher

#publish

Methods included from Utils

check_type

Instance Method Details

#view(url) ⇒ Object



12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
# File 'lib/twterm/photo_viewer_backend/imgcat_backend.rb', line 12

def view(url)
  Curses.close_screen unless Curses.closed?

  puts "\e[H\e[2JDownloading..."

  with_downloaded_file(url) do |file|
    begin
      puts "\e[H\e[2JRendering..."
      system "imgcat #{file.path}"
      getc
    ensure
      puts "\e[H\e[2J"
      Curses.reset_prog_mode
      sleep 0.1
      publish(Event::Screen::Refresh.new)
    end
  end
end