From e7514d97922ab9271cc695a238fc2144f699a884 Mon Sep 17 00:00:00 2001 From: Aoran Zeng Date: Sat, 13 May 2023 07:56:41 +0800 Subject: [PATCH 1/4] Add support for doubly underlined and overlined --- lib/rainbow/presenter.rb | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/lib/rainbow/presenter.rb b/lib/rainbow/presenter.rb index 753f273..d94193a 100644 --- a/lib/rainbow/presenter.rb +++ b/lib/rainbow/presenter.rb @@ -15,7 +15,9 @@ class Presenter < ::String blink: 5, inverse: 7, hide: 8, - cross_out: 9 + cross_out: 9, + underline2x: 21, + overline: 53 }.freeze # Sets color of this text. @@ -89,6 +91,14 @@ def cross_out alias strike cross_out + def underline2x + wrap_with_sgr(TERM_EFFECTS[:underline2x]) + end + + def overline + wrap_with_sgr(TERM_EFFECTS[:overline]) + end + def black color(:black) end From a15a40411e91d299ce73a170965414b20677f045 Mon Sep 17 00:00:00 2001 From: Aoran Zeng Date: Sat, 13 May 2023 07:59:53 +0800 Subject: [PATCH 2/4] Add support for null_presenter doubly underlined and overlined --- lib/rainbow/null_presenter.rb | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/lib/rainbow/null_presenter.rb b/lib/rainbow/null_presenter.rb index 104738f..52f4ed9 100644 --- a/lib/rainbow/null_presenter.rb +++ b/lib/rainbow/null_presenter.rb @@ -46,6 +46,14 @@ def cross_out self end + def underline2x + self + end + + def overline + self + end + def black self end From 446f0541d4a587358faf11bc70ebf76484b1ea96 Mon Sep 17 00:00:00 2001 From: Aoran Zeng Date: Sat, 13 May 2023 08:43:55 +0800 Subject: [PATCH 3/4] Add specs for underline2x and overline --- spec/unit/null_presenter_spec.rb | 12 ++++++++++++ spec/unit/presenter_spec.rb | 22 ++++++++++++++++++++++ 2 files changed, 34 insertions(+) diff --git a/spec/unit/null_presenter_spec.rb b/spec/unit/null_presenter_spec.rb index 9dc9189..e423425 100644 --- a/spec/unit/null_presenter_spec.rb +++ b/spec/unit/null_presenter_spec.rb @@ -117,6 +117,18 @@ module Rainbow it_behaves_like "rainbow null string method" end + describe "#underline2x" do + subject { presenter.underline2x } + + it_behaves_like "rainbow null string method" + end + + describe "#overline" do + subject { presenter.overline } + + it_behaves_like "rainbow null string method" + end + it_behaves_like "presenter with shortcut color methods" describe "#method_missing" do diff --git a/spec/unit/presenter_spec.rb b/spec/unit/presenter_spec.rb index d42cc67..559e526 100644 --- a/spec/unit/presenter_spec.rb +++ b/spec/unit/presenter_spec.rb @@ -216,6 +216,28 @@ module Rainbow end end + describe '#underline2x' do + subject { presenter.underline2x } + + it_behaves_like "rainbow string method" + + it 'wraps with 21 code' do + subject + expect(StringUtils).to have_received(:wrap_with_sgr).with('hello', [21]) + end + end + + describe '#overline' do + subject { presenter.overline } + + it_behaves_like "rainbow string method" + + it 'wraps with 53 code' do + subject + expect(StringUtils).to have_received(:wrap_with_sgr).with('hello', [53]) + end + end + it_behaves_like "presenter with shortcut color methods" end end From ad44fb7dfb314e9958201097c4fc7a2dab49d3b1 Mon Sep 17 00:00:00 2001 From: Aoran Zeng Date: Sat, 13 May 2023 08:53:28 +0800 Subject: [PATCH 4/4] Update README --- README.markdown | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/README.markdown b/README.markdown index 8955904..dcf9b50 100644 --- a/README.markdown +++ b/README.markdown @@ -46,6 +46,8 @@ Rainbow presenter adds the following methods to presented string: * `faint` (not well supported by terminal emulators) * `italic` (not well supported by terminal emulators) * `cross_out`, `strike` +* `underline2x` (not well supported by terminal emulators) +* `overline` (not well supported by terminal emulators) Text color can also be changed by calling a method named by a color: @@ -101,10 +103,10 @@ of the following ways: * [ANSI color](https://en.wikipedia.org/wiki/ANSI_escape_code#Colors) name or [X11 color](https://en.wikipedia.org/wiki/X11_color_names) name as a symbol: `Rainbow("hello").color(:yellow)`. - This can be simplified to `Rainbow("hello").yellow` - - See [Color list](#user-content-color-list) for all available color names. - Note that ANSI colors can be changed in accordance with terminal setting. + This can be simplified to `Rainbow("hello").yellow` + + See [Color list](#user-content-color-list) for all available color names. + Note that ANSI colors can be changed in accordance with terminal setting. But X11 color is just a syntax sugar for RGB triplet. So you always see what you specified. * RGB triplet as separate values in the range 0-255: