Sha256: 1ee3e7cb05303409f46d61ea22a0b20e2f2936f064560f4e2419014b554036d9
Contents?: true
Size: 1.58 KB
Versions: 4
Compression:
Stored size: 1.58 KB
Contents
# encoding: utf-8 module Inch module Utils class UI attr_reader :out, :err def initialize(stdout = $stdout, stderr = $stderr) @out, @err = stdout, stderr end def debug(msg) return unless ENV['DEBUG'] msg.to_s.lines.each do |line| trace edged :dark, line.gsub(/\n$/, '').color(:dark) end end def sub(msg = '') color = @current_header_color || :white trace __edged(color, msg) end def edged(color, msg, edge = '┃ ') trace __edged(color, msg, edge) end # Writes the given +text+ to out # # @param text [String] # @return [void] def trace(text = '') @current_header_color = nil if text.to_s.empty? out.puts text end # Writes the given +text+ to err # # @param text [String] # @return [void] def warn(text = '') err.puts text end def header(text, color, bg_color = nil) @current_header_color = color trace __header(text, color, bg_color) trace unless use_color? end # @return [Boolean] true if the UI uses coloring def use_color? Term::ANSIColor.coloring? end private def __edged(color, msg, edge = '┃ ') edge.color(color) + msg end def __header(text, color, bg_color = nil) bg_color ||= "intense_#{color}" bar = " #{text}".ljust(CLI::COLUMNS - 1) .on_color(bg_color).color(:color16) '#'.color(color).on_color(color) + bar end end end end
Version data entries
4 entries across 4 versions & 1 rubygems
Version | Path |
---|---|
inch-0.9.0.rc1 | lib/inch/utils/ui.rb |
inch-0.8.0 | lib/inch/utils/ui.rb |
inch-0.8.0.rc2 | lib/inch/utils/ui.rb |
inch-0.8.0.rc1 | lib/inch/utils/ui.rb |