Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add two styles underline2x and overline #125

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 6 additions & 4 deletions README.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -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:

Expand Down Expand Up @@ -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:
Expand Down
8 changes: 8 additions & 0 deletions lib/rainbow/null_presenter.rb
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,14 @@ def cross_out
self
end

def underline2x
self
end

def overline
self
end

def black
self
end
Expand Down
12 changes: 11 additions & 1 deletion lib/rainbow/presenter.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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
Expand Down
12 changes: 12 additions & 0 deletions spec/unit/null_presenter_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
22 changes: 22 additions & 0 deletions spec/unit/presenter_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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