From 40cb9bd46aed6b1c5fa203fbaf97d57d5b07ffa4 Mon Sep 17 00:00:00 2001 From: Rick Ohnemus Date: Thu, 20 Jun 2024 13:35:19 -0700 Subject: [PATCH] Preserve user color defaults User set default colors are lost after the first call to anything that colorizes data. For example, without this change: AmazingPrint.defaults = { color: { integer: :blueish } } ap 123 # output with bluish color ap 123 # output with blue color (the builtin default) --- CHANGELOG.md | 2 ++ lib/amazing_print/inspector.rb | 2 +- spec/misc_spec.rb | 11 +++++++++++ 3 files changed, 14 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 70f70c8..04fc04c 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,8 @@ ## Unreleased +- Preserve user defined color defaults + ## V1.6.0 - Use pager with Pry #96 diff --git a/lib/amazing_print/inspector.rb b/lib/amazing_print/inspector.rb index 4cd9bad..a7b4e67 100644 --- a/lib/amazing_print/inspector.rb +++ b/lib/amazing_print/inspector.rb @@ -192,7 +192,7 @@ def dotfile_readable?(dotfile) #--------------------------------------------------------------------------- def merge_custom_defaults! load_dotfile - merge_options!(AmazingPrint.defaults) if AmazingPrint.defaults.is_a?(Hash) + merge_options!(AmazingPrint.defaults.dup) if AmazingPrint.defaults.is_a?(Hash) rescue StandardError => e warn "Could not load '.aprc' from ENV['HOME']: #{e}" end diff --git a/spec/misc_spec.rb b/spec/misc_spec.rb index 3ba0755..af7a52c 100644 --- a/spec/misc_spec.rb +++ b/spec/misc_spec.rb @@ -139,6 +139,17 @@ def ==(other) } EOS end + + it 'preserves user color defaults' do + COLORIZED_123 = "\e[0;34m123\e[0m" + + AmazingPrint.force_colors = true + AmazingPrint.defaults = { color: { integer: :blueish } } + out = 123.ai + expect(out).to eq COLORIZED_123 + out = 123.ai + expect(out).to eq COLORIZED_123 + end end #------------------------------------------------------------------------------