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 more Colorize::Mode flags #13745

Merged
Merged
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
5 changes: 5 additions & 0 deletions spec/std/colorize_spec.cr
Original file line number Diff line number Diff line change
Expand Up @@ -86,10 +86,15 @@ describe "colorize" do
colorize("hello").bold.to_s.should eq("\e[1mhello\e[0m")
colorize("hello").bright.to_s.should eq("\e[1mhello\e[0m")
colorize("hello").dim.to_s.should eq("\e[2mhello\e[0m")
colorize("hello").italic.to_s.should eq("\e[3mhello\e[0m")
colorize("hello").underline.to_s.should eq("\e[4mhello\e[0m")
colorize("hello").blink.to_s.should eq("\e[5mhello\e[0m")
colorize("hello").blink_fast.to_s.should eq("\e[6mhello\e[0m")
colorize("hello").reverse.to_s.should eq("\e[7mhello\e[0m")
colorize("hello").hidden.to_s.should eq("\e[8mhello\e[0m")
colorize("hello").strikethrough.to_s.should eq("\e[9mhello\e[0m")
colorize("hello").double_underline.to_s.should eq("\e[21mhello\e[0m")
colorize("hello").overline.to_s.should eq("\e[53mhello\e[0m")
end

it "colorizes mode combination" do
Expand Down
29 changes: 22 additions & 7 deletions src/colorize.cr
Original file line number Diff line number Diff line change
Expand Up @@ -285,24 +285,39 @@ module Colorize
Bright = 1
# Dims the text color.
Dim
# Underlines the text.
# Draws a line below the text.
Underline
# Makes the text blink slowly.
Blink
# Swaps the foreground and background colors of the text.
Reverse
# Makes the text invisible.
Hidden
# Italicizes the text.
Italic
# Makes the text blink quickly.
BlinkFast
# Crosses out the text.
Strikethrough
# Draws two lines below the text.
DoubleUnderline
# Draws a line above the text.
Overline
end
end

private def each_code(mode : Colorize::Mode, &)
yield '1' if mode.bold?
yield '2' if mode.dim?
yield '4' if mode.underline?
yield '5' if mode.blink?
yield '7' if mode.reverse?
yield '8' if mode.hidden?
yield "1" if mode.bold?
yield "2" if mode.dim?
yield "3" if mode.italic?
yield "4" if mode.underline?
yield "5" if mode.blink?
yield "6" if mode.blink_fast?
yield "7" if mode.reverse?
yield "8" if mode.hidden?
yield "9" if mode.strikethrough?
yield "21" if mode.double_underline?
yield "53" if mode.overline?
end

# A colorized object. Colors and text decorations can be modified.
Expand Down