Class: Bolt::Outputter::Rainbow
- Inherits:
-
Human
- Object
- Bolt::Outputter
- Human
- Bolt::Outputter::Rainbow
- Defined in:
- lib/bolt/outputter/rainbow.rb
Constant Summary
Constants inherited from Human
Instance Method Summary collapse
- #colorize(color, string) ⇒ Object
-
#initialize(color, verbose, trace, stream = $stdout) ⇒ Rainbow
constructor
A new instance of Rainbow.
- #print_summary(results, elapsed_time = nil) ⇒ Object
-
#rainbow ⇒ Object
The algorithm is from lolcat (github.com/busyloop/lolcat) lolcat is released with WTFPL.
Methods inherited from Human
#duration_to_string, #enabled?, #fatal_error, #format_log, #handle_event, #indent, #plan_logging?, #print_apply_result, #print_groups, #print_head, #print_message, #print_message_event, #print_module_list, #print_plan_finish, #print_plan_info, #print_plan_result, #print_plan_start, #print_plans, #print_puppetfile_result, #print_result, #print_result_set, #print_start, #print_step_finish, #print_step_start, #print_table, #print_target_info, #print_targets, #print_task_info, #print_tasks, #remove_trail
Methods inherited from Bolt::Outputter
Constructor Details
#initialize(color, verbose, trace, stream = $stdout) ⇒ Rainbow
Returns a new instance of Rainbow.
8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 |
# File 'lib/bolt/outputter/rainbow.rb', line 8 def initialize(color, verbose, trace, stream = $stdout) begin require 'paint' if Bolt::Util.windows? # the Paint gem thinks that windows does not support ansi colors # but windows 10 or later does # we can display colors if we force mode to TRUE_COLOR Paint.mode = 0xFFFFFF end rescue LoadError raise "The 'paint' gem is required to use the rainbow outputter." end super @line_color = 0 @color = 0 @state = :normal end |
Instance Method Details
#colorize(color, string) ⇒ Object
36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 |
# File 'lib/bolt/outputter/rainbow.rb', line 36 def colorize(color, string) if @color && @stream.isatty if %i[green rainbow].include?(color) a = string.chars.map do |c| case @state when :normal case c when "\e" @state = :ansi when "\n" @line_color += 1 @color = @line_color c else Paint[c, rainbow] end when :ansi @state = :normal if c == 'm' end end a.join('') else "\033[#{COLORS[color]}m#{string}\033[0m" end else string end end |
#print_summary(results, elapsed_time = nil) ⇒ Object
65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 |
# File 'lib/bolt/outputter/rainbow.rb', line 65 def print_summary(results, elapsed_time = nil) ok_set = results.ok_set unless ok_set.empty? @stream.puts colorize(:rainbow, format('Successful on %<size>d target%<plural>s: %<names>s', size: ok_set.size, plural: ok_set.size == 1 ? '' : 's', names: ok_set.targets.map(&:safe_name).join(','))) end error_set = results.error_set unless error_set.empty? @stream.puts colorize(:red, format('Failed on %<size>d target%<plural>s: %<names>s', size: error_set.size, plural: error_set.size == 1 ? '' : 's', names: error_set.targets.map(&:safe_name).join(','))) end total_msg = format('Ran on %<size>d target%<plural>s', size: results.size, plural: results.size == 1 ? '' : 's') total_msg << " in #{duration_to_string(elapsed_time)}" unless elapsed_time.nil? @stream.puts colorize(:rainbow, total_msg) end |
#rainbow ⇒ Object
The algorithm is from lolcat (github.com/busyloop/lolcat) lolcat is released with WTFPL
28 29 30 31 32 33 34 |
# File 'lib/bolt/outputter/rainbow.rb', line 28 def rainbow red = Math.sin(0.3 * @color + 0) * 127 + 128 green = Math.sin(0.3 * @color + 2 * Math::PI / 3) * 127 + 128 blue = Math.sin(0.3 * @color + 4 * Math::PI / 3) * 127 + 128 @color += 1 / 8.0 format("%<red>02X%<green>02X%<blue>02X", red: red, green: green, blue: blue) end |