Sha256: ad21b941228fa2a6fda4a9f684dcd49bdf6c3f735284471d7e02836240bc5d7b

Contents?: true

Size: 1.23 KB

Versions: 5

Compression:

Stored size: 1.23 KB

Contents

require 'base64'

module Lolcommits
  module Plugin
    class TermOutput < Base
      def run_capture_ready
        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
        :capture_ready
      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
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
lolcommits-0.9.7 lib/lolcommits/plugin/term_output.rb
lolcommits-0.9.7.pre1 lib/lolcommits/plugin/term_output.rb
lolcommits-0.9.6 lib/lolcommits/plugin/term_output.rb
lolcommits-0.9.5 lib/lolcommits/plugin/term_output.rb
lolcommits-0.9.5.pre1 lib/lolcommits/plugin/term_output.rb