From 815d02f51c4d232a396dcb5321b42f58c7d58ba2 Mon Sep 17 00:00:00 2001 From: Mike Karlesky Date: Fri, 3 May 2024 22:45:09 -0400 Subject: [PATCH] =?UTF-8?q?=E2=99=BB=EF=B8=8F=20Added=20additional=20deocr?= =?UTF-8?q?ators?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - Broke out `decorate()` method in Loginator to support access to all decorators - Updated banner and heading generation to calculate widths including Unicode characters - Fixed logging statements. --- bin/cli_helper.rb | 8 +-- ceedling.gemspec | 1 + lib/ceedling/build_batchinator.rb | 2 +- lib/ceedling/constants.rb | 22 +++---- lib/ceedling/loginator.rb | 59 ++++++++++++------- lib/ceedling/rakefile.rb | 5 +- lib/ceedling/reportinator.rb | 6 +- .../assets/template.erb | 3 +- 8 files changed, 66 insertions(+), 40 deletions(-) diff --git a/bin/cli_helper.rb b/bin/cli_helper.rb index 27cffa8d3..9daca1c88 100644 --- a/bin/cli_helper.rb +++ b/bin/cli_helper.rb @@ -18,7 +18,7 @@ def setup @actions = @actions_wrapper # Automatic setting of console printing decorations - @loginator.decorate = !windows?() + @loginator.decorators = !windows?() end @@ -216,7 +216,7 @@ def process_decoration(env, config={}) decorate = true end - @loginator.decorate = decorate + @loginator.decorators = decorate end # Otherwise inspect project configuration (could be blank and gets skipped) @@ -224,9 +224,9 @@ def process_decoration(env, config={}) if (!walk[:value].nil?) case walk[:value] when :all - @loginator.decorate = true + @loginator.decorators = true when :none - @loginator.decorate = false + @loginator.decorators = false else #:auto # Retain what was set in `setup()` above based on platform end diff --git a/ceedling.gemspec b/ceedling.gemspec index 757e66b81..192fd3d18 100644 --- a/ceedling.gemspec +++ b/ceedling.gemspec @@ -43,6 +43,7 @@ Ceedling projects are created with a YAML configuration file. A variety of conve s.add_dependency "rake", ">= 12", "< 14" s.add_dependency "deep_merge", "~> 1.2" s.add_dependency "constructor", "~> 2" + s.add_dependency "unicode-display_width", ">= 2.5.0" # Files needed from submodules s.files = [] diff --git a/lib/ceedling/build_batchinator.rb b/lib/ceedling/build_batchinator.rb index cdf88fb46..b099c067c 100644 --- a/lib/ceedling/build_batchinator.rb +++ b/lib/ceedling/build_batchinator.rb @@ -16,7 +16,7 @@ def setup # Neaten up a build step with progress message and some scope encapsulation def build_step(msg, heading: true, &block) if heading - msg = @reportinator.generate_heading(msg) + msg = @reportinator.generate_heading( @loginator.decorate( msg, LogLabels::RUN ) ) else # Progress message msg = "\n" + @reportinator.generate_progress(msg) end diff --git a/lib/ceedling/constants.rb b/lib/ceedling/constants.rb index e364e251b..8c09afdd3 100644 --- a/lib/ceedling/constants.rb +++ b/lib/ceedling/constants.rb @@ -26,16 +26,18 @@ class Verbosity # Label + decorator options for logging class LogLabels - NONE = 0 # Override logic and settings with no label and no decoration - AUTO = 1 # Default labeling and decorators - NOTICE = 2 # 'NOTICE:' - WARNING = 3 # 'WARNING:' - ERROR = 4 # 'ERROR:' - EXCEPTION = 5 # 'EXCEPTION:' - CONSTRUCT = 6 # 🚧 decorator only - STOPWATCH = 7 # ⏱ī¸ decorator only - SEGFAULT = 8 # ☠ī¸ decorator only - TITLE = 9 # 🌱 decorator only + NONE = 0 # Override logic and settings with no label and no decoration + AUTO = 1 # Default labeling and decorators + NOTICE = 2 # decorator + 'NOTICE:' + WARNING = 3 # decorator + 'WARNING:' + ERROR = 4 # decorator + 'ERROR:' + EXCEPTION = 5 # decorator + 'EXCEPTION:' + CONSTRUCT = 6 # decorator only + RUN = 7 # decorator only + SEGFAULT = 8 # decorator only + PASS = 9 # decorator only + FAIL = 10 # decorator only + TITLE = 11 # decorator only # Verbosity levels ERRORS – DEBUG default to certain labels or lack thereof # The above label constants are available to override Loginator's default AUTO level as needed diff --git a/lib/ceedling/loginator.rb b/lib/ceedling/loginator.rb index 328f1f4b3..d871cf3dd 100644 --- a/lib/ceedling/loginator.rb +++ b/lib/ceedling/loginator.rb @@ -12,12 +12,12 @@ class Loginator attr_reader :project_logging - attr_writer :decorate + attr_writer :decorators constructor :verbosinator, :stream_wrapper, :file_wrapper, :system_wrapper def setup() - @decorate = false + @decorators = false @replace = { # Problematic characters pattern => Simple characters @@ -91,10 +91,42 @@ def out(string, verbosity=Verbosity::NORMAL, label=LogLabels::AUTO, stream=nil) return if !(@verbosinator.should_output?( verbosity )) # Add labels and fun characters - console_str = format( string, verbosity, label, @decorate ) + console_str = format( string, verbosity, label, @decorators ) # Write to output stream after optionally removing any problematic characters - stream.print( sanitize( console_str, @decorate ) ) + stream.print( sanitize( console_str, @decorators ) ) + end + + + def decorate(str, label=LogLabels::NONE) + return str if !@decorators + + prepend = '' + + case label + when LogLabels::NOTICE + prepend = 'ℹī¸ ' + when LogLabels::WARNING + prepend = '⚠ī¸ ' + when LogLabels::ERROR + prepend = 'đŸĒ˛ ' + when LogLabels::EXCEPTION + prepend = '🧨 ' + when LogLabels::CONSTRUCT + prepend = '🚧 ' + when LogLabels::SEGFAULT + prepend = '☠ī¸ ' + when LogLabels::RUN + prepend = '👟 ' + when LogLabels::PASS + prepend = '✅ ' + when LogLabels::FAIL + prepend = '❌ ' + when LogLabels::TITLE + prepend = '🌱 ' + end + + return prepend + str end ### Private ### @@ -130,22 +162,9 @@ def format(string, verbosity, label, decorate) prepend = '⚠ī¸ ' end # Otherwise, no decorators for verbosity levels - when LogLabels::NOTICE - prepend = 'ℹī¸ ' - when LogLabels::WARNING - prepend = '⚠ī¸ ' - when LogLabels::ERROR - prepend = 'đŸĒ˛ ' - when LogLabels::EXCEPTION - prepend = '🧨 ' - when LogLabels::CONSTRUCT - prepend = '🚧 ' - when LogLabels::STOPWATCH - prepend = '⏱ī¸ ' - when LogLabels::SEGFAULT - prepend = '☠ī¸ ' - when LogLabels::TITLE - prepend = '🌱 ' + else + # If not auto, go get us a decorator + prepend = decorate('', label) end end diff --git a/lib/ceedling/rakefile.rb b/lib/ceedling/rakefile.rb index e97a55e59..e527658ae 100644 --- a/lib/ceedling/rakefile.rb +++ b/lib/ceedling/rakefile.rb @@ -30,7 +30,7 @@ def log_runtime(run, start_time_s, end_time_s, enabled) return if duration.empty? @ceedling[:loginator].out( "\n" ) - @ceedling[:loginator].log( "Ceedling #{run} completed in #{duration}", Verbosity::NORMAL, LogLabels::STOPWATCH ) + @ceedling[:loginator].log( "Ceedling #{run} completed in #{duration}", Verbosity::NORMAL) end start_time = nil # Outside scope of exception handling @@ -133,7 +133,8 @@ def test_failures_handler() exit(0) else - @ceedling[:loginator].log( "Ceedling could not complete operations because of errors", Verbosity::ERRORS ) + msg = "Ceedling could not complete operations because of errors" + @ceedling[:loginator].log( msg, Verbosity::ERRORS, LogLabels::TITLE ) begin @ceedling[:plugin_manager].post_error rescue => ex diff --git a/lib/ceedling/reportinator.rb b/lib/ceedling/reportinator.rb index 40fc35786..0c83dee44 100644 --- a/lib/ceedling/reportinator.rb +++ b/lib/ceedling/reportinator.rb @@ -5,6 +5,8 @@ # SPDX-License-Identifier: MIT # ========================================================================= +require 'unicode/display_width' + ## # Pretifies reports class Reportinator @@ -87,14 +89,14 @@ def generate_banner(message, width=nil) # --------- # # --------- - dash_count = ((width.nil?) ? message.strip.length : width) + dash_count = ((width.nil?) ? Unicode::DisplayWidth.of( message.strip ) : width) return "#{'-' * dash_count}\n#{message}\n#{'-' * dash_count}\n" end def generate_heading(message) # # --------- - return "\n#{message}\n#{'-' * message.length}" + return "\n#{message}\n#{'-' * Unicode::DisplayWidth.of( message.strip )}" end def generate_progress(message) diff --git a/plugins/report_tests_pretty_stdout/assets/template.erb b/plugins/report_tests_pretty_stdout/assets/template.erb index 52b29f7f0..32d1c9968 100644 --- a/plugins/report_tests_pretty_stdout/assets/template.erb +++ b/plugins/report_tests_pretty_stdout/assets/template.erb @@ -46,7 +46,8 @@ % end % total_string = hash[:results][:counts][:total].to_s % format_string = "%#{total_string.length}i" -<%=@ceedling[:plugin_reportinator].generate_banner(header_prepend + 'OVERALL TEST SUMMARY')%> +% decorator = (failed > 0) ? LogLabels::FAIL : LogLabels::PASS +<%=@ceedling[:plugin_reportinator].generate_banner(header_prepend + @loginator.decorate('OVERALL TEST SUMMARY', decorator))%> % if (hash[:results][:counts][:total] > 0) TESTED: <%=hash[:results][:counts][:total].to_s%> PASSED: <%=sprintf(format_string, hash[:results][:counts][:passed])%>