diff options
author | Dmitriy Zaporozhets <dmitriy.zaporozhets@gmail.com> | 2012-11-13 18:06:30 +0200 |
---|---|---|
committer | Dmitriy Zaporozhets <dmitriy.zaporozhets@gmail.com> | 2012-11-13 18:06:39 +0200 |
commit | a73f28243e1f782ff84cd1e787c4c22bd7350ab6 (patch) | |
tree | 978b83da445de5b1d852e2d93dc3424692c48c5e /lib | |
parent | 6a0e60b84308df41b3cee5c7ced39229512bb32a (diff) | |
download | gitlab-ci-a73f28243e1f782ff84cd1e787c4c22bd7350ab6.tar.gz |
Move ansi library in project core
Diffstat (limited to 'lib')
-rw-r--r-- | lib/ansi2html.rb | 32 |
1 files changed, 32 insertions, 0 deletions
diff --git a/lib/ansi2html.rb b/lib/ansi2html.rb new file mode 100644 index 0000000..5650d81 --- /dev/null +++ b/lib/ansi2html.rb @@ -0,0 +1,32 @@ +# ANSI color library +module Ansi2html + COLOR = { + '1' => 'bold', + '30' => 'black', + '31' => 'red', + '32' => 'green', + '33' => 'yellow', + '34' => 'blue', + '35' => 'magenta', + '36' => 'cyan', + '37' => 'white', + '90' => 'grey' + } + + def self.convert(ansi) + out = "" + s = StringScanner.new(ansi.gsub("<", "<")) + while(!s.eos?) + if s.scan(/\e\[(3[0-7]|90|1)m/) + out << %{<span class="#{COLOR[s[1]]}">} + else + if s.scan(/\e\[0m/) + out << %{</span>} + else + out << s.scan(/./m) + end + end + end + out + end +end |