class TermImages::Image

Public Class Methods

new(path) click to toggle source
# File lib/term-images.rb, line 13
def initialize path
  @path = path
end

Public Instance Methods

pstree(pid = Process.pid) click to toggle source
# File lib/term-images.rb, line 77
def pstree pid = Process.pid
  processes = []
  while pid != 0
    `/bin/ps #{::OS.mac? ? "-p" : "axww -q"} #{pid} -o ppid,command`.each_line do |line|
      next if line !~ /^\s*\d+/
      line.strip!
      result = line.split(/\s+/, 2)
      processes << result[1].split(" ").first.split("/").last
      pid = result[0].to_i
    end
  end
  processes
end
puts() click to toggle source
# File lib/term-images.rb, line 90
def puts
  commands = {
    "kitty" => CommandLineImageDisplayer.new([(::OS.mac? ? "/Applications/kitty.app/Contents/MacOS/" : "") + "kitty", "+kitten", "icat"]),
    "terminology" => CommandLineImageDisplayer.new(%w(tycat)),
    "mlterm" => CommandLineImageDisplayer.new(%w(img2sixel)),
    "iTerm" => CommandLineImageDisplayer.new(%w(imgcat))
  }
  ptree = pstree
  terminals = commands.keys.map { |terminal| ptree.include?(terminal) ? terminal : nil }.select { |x| !x.nil? }
  if terminals.size > 0
    command = commands[terminals.first]
  else
    w3mImageDisplayer = W3MImageDisplayer.new
    if w3mImageDisplayer.supported?
      command = w3mImageDisplayer
    else
      command = CommandLineImageDisplayer.new %w(icat)
    end
  end
  command.run @path
end