Skip to content
This repository has been archived by the owner on Nov 9, 2017. It is now read-only.

Commit

Permalink
ansi module handles light foreground and background colors
Browse files Browse the repository at this point in the history
  • Loading branch information
rtomayko committed Jun 23, 2010
1 parent 24414e7 commit 60b6aee
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 10 deletions.
22 changes: 12 additions & 10 deletions lib/bcat/ansi.rb
Expand Up @@ -99,16 +99,18 @@ def each
yield data
when :display
case code = data
when 0 ; yield reset_styles if @stack.any?
when 1 ; yield push_tag("b") # bright
when 2 ; #dim
when 3 ; yield push_tag("u")
when 5 ; yield push_tag("blink")
when 7 ; #reverse
when 8 ; yield push_style("display:none")
when 9 ; yield push_tag("strike")
when 30..37 ; yield push_style("ef#{code - 30}")
when 40..47 ; yield push_style("eb#{code - 40}")
when 0 ; yield reset_styles if @stack.any?
when 1 ; yield push_tag("b") # bright
when 2 ; #dim
when 3 ; yield push_tag("u")
when 5 ; yield push_tag("blink")
when 7 ; #reverse
when 8 ; yield push_style("display:none")
when 9 ; yield push_tag("strike")
when 30..37 ; yield push_style("ef#{code - 30}")
when 40..47 ; yield push_style("eb#{code - 40}")
when 90..97 ; yield push_style("ef#{8 + code - 90}")
when 100..107 ; yield push_style("eb#{8 + code - 100}")
end
end
end
Expand Down
4 changes: 4 additions & 0 deletions man/a2h.1.ronn
Expand Up @@ -28,6 +28,10 @@ The following escape sequences are supported:
Foreground color.
* `<ESC>[40-47m`=`<span style='background-color:`<color>`>`:
Background color.
* `<ESC>[90-97m`=`<span style='color:`<color>`>`:
Light foreground colors.
* `<ESC>[100-107m`=`<span style='background-color:`<color>`>`:
Light background color.

## SEE ALSO

Expand Down
18 changes: 18 additions & 0 deletions test/test_bcat_ansi.rb
Expand Up @@ -29,6 +29,15 @@ class ANSITest < Test::Unit::TestCase
assert_equal expect, Bcat::ANSI.new(text).to_html
end

test "light foreground colors" do
text = "colors: \x1b[90mblack\x1b[97mwhite"
expect = "colors: " +
"<span style='color:#555'>black" +
"<span style='color:#FFF'>white" +
"</span></span>"
assert_equal expect, Bcat::ANSI.new(text).to_html
end

test "background colors" do
text = "colors: \x1b[40mblack\x1b[47mwhite"
expect = "colors: " +
Expand All @@ -38,6 +47,15 @@ class ANSITest < Test::Unit::TestCase
assert_equal expect, Bcat::ANSI.new(text).to_html
end

test "light background colors" do
text = "colors: \x1b[100mblack\x1b[107mwhite"
expect = "colors: " +
"<span style='background-color:#555'>black" +
"<span style='background-color:#FFF'>white" +
"</span></span>"
assert_equal expect, Bcat::ANSI.new(text).to_html
end

test "strikethrough" do
text = "strike: \x1b[9mthat"
expect = "strike: <strike>that</strike>"
Expand Down

0 comments on commit 60b6aee

Please sign in to comment.