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: 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 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 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