class Lolcommits::Plugin::TermOutput
Public Instance Methods
Prompts the user to configure the plugin's options. The default
superclass method will ask for the `enabled` option to be set.
@return [Hash] hash of configured options `{ enabled: true/false }` @return [Nil] if this terminal does not support this plugin
# File lib/lolcommits/plugin/term_output.rb, line 16 def configure_options! if terminal_supported? super else puts "Sorry, this terminal does not support this plugin (requires iTerm2)" {} end end
Post-capture hook, runs after lolcommits captures a snapshot. If the # terminal is supported (and we have commits) the lolcommit image is rendered inline to the terminal output (with the commit message).
See here for more details: iterm2.com/documentation-images.html
# File lib/lolcommits/plugin/term_output.rb, line 33 def run_capture_ready if terminal_supported? if !runner.vcs_info || runner.vcs_info.repo.empty? debug 'repo is empty, skipping term output' elsif !image_path debug 'lolcommit videos not supported' else debug "rendering image in iTerm" base64 = Base64.encode64(open(image_path, &:read).to_s) puts "#{begin_escape}1337;File=inline=1:#{base64};alt=#{runner.message};#{end_escape}\n" end else debug 'Terminal not supported (requires iTerm2)' end end
Private Instance Methods
Generate starting escape character sequence. Terminals running Tmux sessions require a different escape code.
@return [String] escape char sequence for inline images
# File lib/lolcommits/plugin/term_output.rb, line 71 def begin_escape tmux? ? "\033Ptmux;\033\033]" : "\033]" end
Generate ending escape character sequence. Terminals running Tmux sessions require a different escape code.
@return [String] escape char sequence for inline images
# File lib/lolcommits/plugin/term_output.rb, line 81 def end_escape tmux? ? "\a\033\\" : "\a" end
The full path to the lolcommit image (gif or jpg), returns nil if runner only captured a video
@return [String] file path
# File lib/lolcommits/plugin/term_output.rb, line 57 def image_path @image_path ||= if runner.capture_video && !runner.capture_gif nil else runner.capture_gif ? runner.lolcommit_gif_path : runner.lolcommit_path end end
Determine if the terminal is supported by this plugin.
@return [Boolan] true when terminal identifies as iTerm
# File lib/lolcommits/plugin/term_output.rb, line 100 def terminal_supported? ENV['TERM_PROGRAM'] =~ /iTerm/ end
Determine if the terminal is running a Tmux session (checks for the TMUX env var to be set).
@return [Boolan] true when running within a Tmux session
# File lib/lolcommits/plugin/term_output.rb, line 91 def tmux? !ENV['TMUX'].nil? end