INNER CODE UNIT · Ruby

colorize

capistrano/sshkit · lib/sshkit/color.rb:41

    def colorize(obj, color, mode=nil)
      string = obj.to_s
      return string unless colorize?
      return string unless COLOR_CODES.key?(color)

      result = mode == :bold ? "\e[1;" : "\e[0;"

      "#{result}#{COLOR_CODES.fetch(color)};49m#{string}\e[0m"
    end

    # Returns `true` if the underlying output is a tty, or if the SSHKIT_COLOR
    # environment variable is set.
    #
    def colorize?
      @env['SSHKIT_COLOR'] || (@output.respond_to?(:tty?) && @output.tty?)
    end
  end
end

View source record →

📰 Research Paper
Loading…
⏳ Fetching content…