Skip to content

Commit

Permalink
Outputs image to terminals that support inline images
Browse files Browse the repository at this point in the history
  • Loading branch information
Ruxton authored and matthutchinson committed Oct 14, 2016
1 parent c4333a3 commit 0259e8f
Show file tree
Hide file tree
Showing 2 changed files with 55 additions and 0 deletions.
1 change: 1 addition & 0 deletions lib/lolcommits.rb
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
require 'lolcommits/plugins/tranzlate'
require 'lolcommits/plugins/lol_twitter'
require 'lolcommits/plugins/uploldz'
require 'lolcommits/plugins/term_output'
require 'lolcommits/plugins/lolsrv'
require 'lolcommits/plugins/lol_yammer'
require 'lolcommits/plugins/lol_protonet'
Expand Down
54 changes: 54 additions & 0 deletions lib/lolcommits/plugins/term_output.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
# -*- encoding : utf-8 -*-
require 'base64'

module Lolcommits
class TermOutput < Plugin
def run_postcapture
if terminal_supported?
if !runner.vcs_info || runner.vcs_info.repo.empty?
debug 'repo is empty, skipping term output'
else
base64 = Base64.encode64(open(runner.main_image, &:read))
puts "#{begin_escape}1337;File=inline=1:#{base64};alt=#{runner.message};#{end_escape}\n"
end
else
debug 'Disabled, your terminal is not supported (requires iTerm2)'
end
end

def self.name
'term_output'
end

def self.runner_order
:postcapture
end

def configure_options!
if terminal_supported?
super
else
puts "Sorry, your terminal does not support the #{self.class.name} plugin (requires iTerm2)"
end
end

private

# escape sequences for tmux sessions differ
def begin_escape
tmux? ? "\033Ptmux;\033\033]" : "\033]"
end

def end_escape
tmux? ? "\a\033\\" : "\a"
end

def tmux?
!ENV['TMUX'].nil?
end

def terminal_supported?
ENV['TERM_PROGRAM'] =~ /iTerm/
end
end
end

0 comments on commit 0259e8f

Please sign in to comment.