ansi_stream 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +22 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +22 -0
- data/README.md +29 -0
- data/Rakefile +25 -0
- data/ansi_stream.gemspec +26 -0
- data/lib/ansi_stream.rb +9 -0
- data/lib/ansi_stream/version.rb +3 -0
- data/spec/javascripts/ansi_stream_spec.coffee +36 -0
- data/spec/javascripts/ansi_stream_spec.js +41 -0
- data/spec/javascripts/helpers/.gitkeep +0 -0
- data/spec/javascripts/support/jasmine.yml +124 -0
- data/spec/javascripts/support/jasmine_helper.rb +11 -0
- data/src/javascripts/ansi_stream.coffee +95 -0
- data/vendor/assets/javascripts/ansi_stream.js +152 -0
- data/vendor/assets/stylesheets/ansi_stream.css +67 -0
- metadata +136 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 381fa7ea723333fd9446734b183ad2f128a1b77d
|
4
|
+
data.tar.gz: d7e1e56e2bb6a2a2fe4cc79e5073e3874b86b3f4
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: b1e565dd4991086124164b09e18abe0da764557f4c6b2fd6c74e122f3df4d183ee2d3654dbc7e944d134a33609cc7eeb094bbf5fb311ac5e69fe16b04ab59341
|
7
|
+
data.tar.gz: a6ffffa607bf712a8858f9d12fda0c43efe5483fc3ad754922499f3d640a91d54791cb0ce7b05ba4648a09b3e4696ef3924284acaa4adf6bc7470e9d699d1738
|
data/.gitignore
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
*.gem
|
2
|
+
*.rbc
|
3
|
+
.bundle
|
4
|
+
.config
|
5
|
+
.yardoc
|
6
|
+
Gemfile.lock
|
7
|
+
InstalledFiles
|
8
|
+
_yardoc
|
9
|
+
coverage
|
10
|
+
doc/
|
11
|
+
lib/bundler/man
|
12
|
+
pkg
|
13
|
+
rdoc
|
14
|
+
spec/reports
|
15
|
+
test/tmp
|
16
|
+
test/version_tmp
|
17
|
+
tmp
|
18
|
+
*.bundle
|
19
|
+
*.so
|
20
|
+
*.o
|
21
|
+
*.a
|
22
|
+
mkmf.log
|
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2014 Guillaume Malette
|
2
|
+
|
3
|
+
MIT License
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
6
|
+
a copy of this software and associated documentation files (the
|
7
|
+
"Software"), to deal in the Software without restriction, including
|
8
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
9
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
10
|
+
permit persons to whom the Software is furnished to do so, subject to
|
11
|
+
the following conditions:
|
12
|
+
|
13
|
+
The above copyright notice and this permission notice shall be
|
14
|
+
included in all copies or substantial portions of the Software.
|
15
|
+
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
17
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
18
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
19
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
20
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
21
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
22
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,29 @@
|
|
1
|
+
# AnsiStream
|
2
|
+
|
3
|
+
TODO: Write a gem description
|
4
|
+
|
5
|
+
## Installation
|
6
|
+
|
7
|
+
Add this line to your application's Gemfile:
|
8
|
+
|
9
|
+
gem 'ansi_stream'
|
10
|
+
|
11
|
+
And then execute:
|
12
|
+
|
13
|
+
$ bundle
|
14
|
+
|
15
|
+
Or install it yourself as:
|
16
|
+
|
17
|
+
$ gem install ansi_stream
|
18
|
+
|
19
|
+
## Usage
|
20
|
+
|
21
|
+
TODO: Write usage instructions here
|
22
|
+
|
23
|
+
## Contributing
|
24
|
+
|
25
|
+
1. Fork it ( https://github.com/[my-github-username]/ansi_stream/fork )
|
26
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
27
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
28
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
29
|
+
5. Create a new Pull Request
|
data/Rakefile
ADDED
@@ -0,0 +1,25 @@
|
|
1
|
+
require "bundler/gem_tasks"
|
2
|
+
require 'jasmine'
|
3
|
+
require 'coffee-script'
|
4
|
+
load 'jasmine/tasks/jasmine.rake'
|
5
|
+
|
6
|
+
task :vendorize do
|
7
|
+
def compile(file, target)
|
8
|
+
File.new(target, "w").write(CoffeeScript.compile(File.read(file), bare: true))
|
9
|
+
end
|
10
|
+
|
11
|
+
Dir['src/**/*.coffee'].each do |file|
|
12
|
+
target = file.gsub(/^src/, "vendor/assets").gsub(/.coffee$/, ".js")
|
13
|
+
compile(file, target)
|
14
|
+
end
|
15
|
+
|
16
|
+
Dir['spec/**/*.coffee'].each do |file|
|
17
|
+
target = file.gsub(/.coffee$/, ".js")
|
18
|
+
compile(file, target)
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
task :test do
|
23
|
+
end
|
24
|
+
|
25
|
+
task default: [:vendorize, 'jasmine:ci']
|
data/ansi_stream.gemspec
ADDED
@@ -0,0 +1,26 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'ansi_stream/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "ansi_stream"
|
8
|
+
spec.version = AnsiStream::VERSION
|
9
|
+
spec.authors = ["Guillaume Malette"]
|
10
|
+
spec.email = ["gmalette@gmail.com"]
|
11
|
+
spec.summary = %q{Javascipt to colorize HTML with span}
|
12
|
+
spec.description = %q{Javascipt to colorize HTML with span}
|
13
|
+
spec.homepage = ""
|
14
|
+
spec.license = "MIT"
|
15
|
+
|
16
|
+
spec.files = `git ls-files -z`.split("\x0")
|
17
|
+
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
18
|
+
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
19
|
+
spec.require_paths = ["lib"]
|
20
|
+
|
21
|
+
spec.add_development_dependency "bundler", "~> 1.6"
|
22
|
+
spec.add_development_dependency "rake"
|
23
|
+
spec.add_development_dependency "jasmine"
|
24
|
+
spec.add_development_dependency "phantomjs", "~> 1.8"
|
25
|
+
spec.add_development_dependency "coffee-script"
|
26
|
+
end
|
data/lib/ansi_stream.rb
ADDED
@@ -0,0 +1,36 @@
|
|
1
|
+
describe "AnsiStream", ->
|
2
|
+
stream = null
|
3
|
+
beforeEach ->
|
4
|
+
stream = new AnsiStream()
|
5
|
+
|
6
|
+
expectClass = (span, color) ->
|
7
|
+
expect(span).toMatch(new RegExp("class='[^']*#{color}.*'"))
|
8
|
+
|
9
|
+
it 'returns uncolorized spans if there are no escape codes', ->
|
10
|
+
expect(stream.process("toto")[0]).toBe("toto")
|
11
|
+
|
12
|
+
it 'returns colorized spans if there is an foreground color code', ->
|
13
|
+
expectClass(stream.process('\u001B[31mtoto')[0], 'ansi-foreground-red')
|
14
|
+
|
15
|
+
it 'returns colorized spans if there is an background color code', ->
|
16
|
+
expectClass(stream.process("\u001B[41mtoto")[0], 'ansi-background-red')
|
17
|
+
|
18
|
+
it 'keeps modifying the style', ->
|
19
|
+
stream.process("\u001B[41mtoto")[0]
|
20
|
+
span = stream.process('\u001B[31mtoto')[0]
|
21
|
+
expectClass(span, 'ansi-background-red')
|
22
|
+
expectClass(span, 'ansi-foreground-red')
|
23
|
+
|
24
|
+
it 'resets the style when encountering a marker', ->
|
25
|
+
spans = stream.process("\u001B[41;31mtoto\u001B[0mtiti")
|
26
|
+
expectClass(spans[0], 'ansi-background-red')
|
27
|
+
expectClass(spans[1], 'ansi-background-default')
|
28
|
+
|
29
|
+
it 'makes the text bright', ->
|
30
|
+
expectClass(stream.process("\u001B[1mtoto")[0], 'ansi-bright')
|
31
|
+
|
32
|
+
it 'handles underline', ->
|
33
|
+
spans = stream.process("\u001B[4mtoto\u001B[24mtiti")
|
34
|
+
expectClass(spans[0], 'ansi-underline')
|
35
|
+
expect(spans[1].indexOf('ansi-underline')).toBe(-1)
|
36
|
+
|
@@ -0,0 +1,41 @@
|
|
1
|
+
describe("AnsiStream", function() {
|
2
|
+
var expectClass, stream;
|
3
|
+
stream = null;
|
4
|
+
beforeEach(function() {
|
5
|
+
return stream = new AnsiStream();
|
6
|
+
});
|
7
|
+
expectClass = function(span, color) {
|
8
|
+
return expect(span).toMatch(new RegExp("class='[^']*" + color + ".*'"));
|
9
|
+
};
|
10
|
+
it('returns uncolorized spans if there are no escape codes', function() {
|
11
|
+
return expect(stream.process("toto")[0]).toBe("toto");
|
12
|
+
});
|
13
|
+
it('returns colorized spans if there is an foreground color code', function() {
|
14
|
+
return expectClass(stream.process('\u001B[31mtoto')[0], 'ansi-foreground-red');
|
15
|
+
});
|
16
|
+
it('returns colorized spans if there is an background color code', function() {
|
17
|
+
return expectClass(stream.process("\u001B[41mtoto")[0], 'ansi-background-red');
|
18
|
+
});
|
19
|
+
it('keeps modifying the style', function() {
|
20
|
+
var span;
|
21
|
+
stream.process("\u001B[41mtoto")[0];
|
22
|
+
span = stream.process('\u001B[31mtoto')[0];
|
23
|
+
expectClass(span, 'ansi-background-red');
|
24
|
+
return expectClass(span, 'ansi-foreground-red');
|
25
|
+
});
|
26
|
+
it('resets the style when encountering a marker', function() {
|
27
|
+
var spans;
|
28
|
+
spans = stream.process("\u001B[41;31mtoto\u001B[0mtiti");
|
29
|
+
expectClass(spans[0], 'ansi-background-red');
|
30
|
+
return expectClass(spans[1], 'ansi-background-default');
|
31
|
+
});
|
32
|
+
it('makes the text bright', function() {
|
33
|
+
return expectClass(stream.process("\u001B[1mtoto")[0], 'ansi-bright');
|
34
|
+
});
|
35
|
+
return it('handles underline', function() {
|
36
|
+
var spans;
|
37
|
+
spans = stream.process("\u001B[4mtoto\u001B[24mtiti");
|
38
|
+
expectClass(spans[0], 'ansi-underline');
|
39
|
+
return expect(spans[1].indexOf('ansi-underline')).toBe(-1);
|
40
|
+
});
|
41
|
+
});
|
File without changes
|
@@ -0,0 +1,124 @@
|
|
1
|
+
# src_files
|
2
|
+
#
|
3
|
+
# Return an array of filepaths relative to src_dir to include before jasmine specs.
|
4
|
+
# Default: []
|
5
|
+
#
|
6
|
+
# EXAMPLE:
|
7
|
+
#
|
8
|
+
# src_files:
|
9
|
+
# - lib/source1.js
|
10
|
+
# - lib/source2.js
|
11
|
+
# - dist/**/*.js
|
12
|
+
#
|
13
|
+
src_files:
|
14
|
+
- vendor/**/*.js
|
15
|
+
|
16
|
+
# stylesheets
|
17
|
+
#
|
18
|
+
# Return an array of stylesheet filepaths relative to src_dir to include before jasmine specs.
|
19
|
+
# Default: []
|
20
|
+
#
|
21
|
+
# EXAMPLE:
|
22
|
+
#
|
23
|
+
# stylesheets:
|
24
|
+
# - css/style.css
|
25
|
+
# - stylesheets/*.css
|
26
|
+
#
|
27
|
+
stylesheets:
|
28
|
+
- stylesheets/**/*.css
|
29
|
+
|
30
|
+
# helpers
|
31
|
+
#
|
32
|
+
# Return an array of filepaths relative to spec_dir to include before jasmine specs.
|
33
|
+
# Default: ["helpers/**/*.js"]
|
34
|
+
#
|
35
|
+
# EXAMPLE:
|
36
|
+
#
|
37
|
+
# helpers:
|
38
|
+
# - helpers/**/*.js
|
39
|
+
#
|
40
|
+
helpers:
|
41
|
+
- 'helpers/**/*.js'
|
42
|
+
|
43
|
+
# spec_files
|
44
|
+
#
|
45
|
+
# Return an array of filepaths relative to spec_dir to include.
|
46
|
+
# Default: ["**/*[sS]pec.js"]
|
47
|
+
#
|
48
|
+
# EXAMPLE:
|
49
|
+
#
|
50
|
+
# spec_files:
|
51
|
+
# - **/*[sS]pec.js
|
52
|
+
#
|
53
|
+
spec_files:
|
54
|
+
- '**/*[sS]pec.js'
|
55
|
+
|
56
|
+
# src_dir
|
57
|
+
#
|
58
|
+
# Source directory path. Your src_files must be returned relative to this path. Will use root if left blank.
|
59
|
+
# Default: project root
|
60
|
+
#
|
61
|
+
# EXAMPLE:
|
62
|
+
#
|
63
|
+
# src_dir: public
|
64
|
+
#
|
65
|
+
src_dir:
|
66
|
+
|
67
|
+
# spec_dir
|
68
|
+
#
|
69
|
+
# Spec directory path. Your spec_files must be returned relative to this path.
|
70
|
+
# Default: spec/javascripts
|
71
|
+
#
|
72
|
+
# EXAMPLE:
|
73
|
+
#
|
74
|
+
# spec_dir: spec/javascripts
|
75
|
+
#
|
76
|
+
spec_dir:
|
77
|
+
|
78
|
+
# spec_helper
|
79
|
+
#
|
80
|
+
# Ruby file that Jasmine server will require before starting.
|
81
|
+
# Returned relative to your root path
|
82
|
+
# Default spec/javascripts/support/jasmine_helper.rb
|
83
|
+
#
|
84
|
+
# EXAMPLE:
|
85
|
+
#
|
86
|
+
# spec_helper: spec/javascripts/support/jasmine_helper.rb
|
87
|
+
#
|
88
|
+
spec_helper: spec/javascripts/support/jasmine_helper.rb
|
89
|
+
|
90
|
+
# boot_dir
|
91
|
+
#
|
92
|
+
# Boot directory path. Your boot_files must be returned relative to this path.
|
93
|
+
# Default: Built in boot file
|
94
|
+
#
|
95
|
+
# EXAMPLE:
|
96
|
+
#
|
97
|
+
# boot_dir: spec/javascripts/support/boot
|
98
|
+
#
|
99
|
+
boot_dir:
|
100
|
+
|
101
|
+
# boot_files
|
102
|
+
#
|
103
|
+
# Return an array of filepaths relative to boot_dir to include in order to boot Jasmine
|
104
|
+
# Default: Built in boot file
|
105
|
+
#
|
106
|
+
# EXAMPLE
|
107
|
+
#
|
108
|
+
# boot_files:
|
109
|
+
# - '**/*.js'
|
110
|
+
#
|
111
|
+
boot_files:
|
112
|
+
|
113
|
+
# rack_options
|
114
|
+
#
|
115
|
+
# Extra options to be passed to the rack server
|
116
|
+
# by default, Port and AccessLog are passed.
|
117
|
+
#
|
118
|
+
# This is an advanced options, and left empty by default
|
119
|
+
#
|
120
|
+
# EXAMPLE
|
121
|
+
#
|
122
|
+
# rack_options:
|
123
|
+
# server: 'thin'
|
124
|
+
|
@@ -0,0 +1,11 @@
|
|
1
|
+
#Use this file to set/override Jasmine configuration options
|
2
|
+
#You can remove it if you don't need it.
|
3
|
+
#This file is loaded *after* jasmine.yml is interpreted.
|
4
|
+
#
|
5
|
+
#Example: using a different boot file.
|
6
|
+
#Jasmine.configure do |config|
|
7
|
+
# config.boot_dir = '/absolute/path/to/boot_dir'
|
8
|
+
# config.boot_files = lambda { ['/absolute/path/to/boot_dir/file.js'] }
|
9
|
+
#end
|
10
|
+
#
|
11
|
+
|
@@ -0,0 +1,95 @@
|
|
1
|
+
class AnsiStream
|
2
|
+
constructor: ->
|
3
|
+
@style = new AnsiStyle()
|
4
|
+
@span = new AnsiSpan()
|
5
|
+
|
6
|
+
process: (text) ->
|
7
|
+
parts = text.split(/\033\[/)
|
8
|
+
parts = parts.filter (part) -> part
|
9
|
+
|
10
|
+
spans = for part in parts
|
11
|
+
[partText, styles] = @_extractTextAndStyles(part)
|
12
|
+
if styles
|
13
|
+
@style.apply(styles)
|
14
|
+
@span.create(partText, @style)
|
15
|
+
else
|
16
|
+
partText
|
17
|
+
|
18
|
+
spans
|
19
|
+
|
20
|
+
_extractTextAndStyles: (originalText) ->
|
21
|
+
matches = originalText.match(/^([\d;]*)m([^]*)$/m)
|
22
|
+
|
23
|
+
return [originalText, null] unless matches
|
24
|
+
|
25
|
+
[matches, numbers, text] = matches
|
26
|
+
[text, numbers.split(";")]
|
27
|
+
|
28
|
+
class AnsiStyle
|
29
|
+
COLORS =
|
30
|
+
0: 'black'
|
31
|
+
1: 'red'
|
32
|
+
2: 'green'
|
33
|
+
3: 'yellow'
|
34
|
+
4: 'blue'
|
35
|
+
5: 'magenta'
|
36
|
+
6: 'cyan'
|
37
|
+
7: 'white'
|
38
|
+
8: null
|
39
|
+
9: 'default'
|
40
|
+
|
41
|
+
constructor: ->
|
42
|
+
@reset()
|
43
|
+
|
44
|
+
apply: (newStyles) ->
|
45
|
+
return unless newStyles
|
46
|
+
for style in newStyles
|
47
|
+
style = parseInt(style)
|
48
|
+
if style == 0
|
49
|
+
@reset()
|
50
|
+
else if style == 1
|
51
|
+
@bright = true
|
52
|
+
else if 30 <= style <= 39 and style != 38
|
53
|
+
@_applyStyle('foreground', style)
|
54
|
+
else if 40 <= style <= 49 and style != 48
|
55
|
+
@_applyStyle('background', style)
|
56
|
+
else if style == 4
|
57
|
+
@underline = true
|
58
|
+
else if style == 24
|
59
|
+
@underline = false
|
60
|
+
|
61
|
+
reset: ->
|
62
|
+
@background = @foreground = 'default'
|
63
|
+
@underline = @bright = false
|
64
|
+
|
65
|
+
toClass: ->
|
66
|
+
classes = []
|
67
|
+
if @background
|
68
|
+
classes.push("ansi-background-#{@background}")
|
69
|
+
if @foreground
|
70
|
+
classes.push("ansi-foreground-#{@foreground}")
|
71
|
+
if @bright
|
72
|
+
classes.push("ansi-bright")
|
73
|
+
if @underline
|
74
|
+
classes.push("ansi-underline")
|
75
|
+
|
76
|
+
classes.join(" ")
|
77
|
+
|
78
|
+
_applyStyle: (layer, number) ->
|
79
|
+
this[layer] = COLORS[number % 10]
|
80
|
+
|
81
|
+
class AnsiSpan
|
82
|
+
ENTITIES =
|
83
|
+
'&': '&'
|
84
|
+
'<': '<'
|
85
|
+
'>': '>'
|
86
|
+
"'": '''
|
87
|
+
|
88
|
+
ESCAPE_PATTERN = new RegExp("[#{(Object.keys(ENTITIES).join(''))}]", 'g');
|
89
|
+
|
90
|
+
create: (text, style) ->
|
91
|
+
"<span class='#{style.toClass()}'>#{@_escapeHTML(text)}</span>"
|
92
|
+
|
93
|
+
_escapeHTML: (text) ->
|
94
|
+
text.replace ESCAPE_PATTERN, (char) ->
|
95
|
+
ENTITIES[char]
|
@@ -0,0 +1,152 @@
|
|
1
|
+
var AnsiSpan, AnsiStream, AnsiStyle;
|
2
|
+
|
3
|
+
AnsiStream = (function() {
|
4
|
+
function AnsiStream() {
|
5
|
+
this.style = new AnsiStyle();
|
6
|
+
this.span = new AnsiSpan();
|
7
|
+
}
|
8
|
+
|
9
|
+
AnsiStream.prototype.process = function(text) {
|
10
|
+
var part, partText, parts, spans, styles;
|
11
|
+
parts = text.split(/\033\[/);
|
12
|
+
parts = parts.filter(function(part) {
|
13
|
+
return part;
|
14
|
+
});
|
15
|
+
spans = (function() {
|
16
|
+
var _i, _len, _ref, _results;
|
17
|
+
_results = [];
|
18
|
+
for (_i = 0, _len = parts.length; _i < _len; _i++) {
|
19
|
+
part = parts[_i];
|
20
|
+
_ref = this._extractTextAndStyles(part), partText = _ref[0], styles = _ref[1];
|
21
|
+
if (styles) {
|
22
|
+
this.style.apply(styles);
|
23
|
+
_results.push(this.span.create(partText, this.style));
|
24
|
+
} else {
|
25
|
+
_results.push(partText);
|
26
|
+
}
|
27
|
+
}
|
28
|
+
return _results;
|
29
|
+
}).call(this);
|
30
|
+
return spans;
|
31
|
+
};
|
32
|
+
|
33
|
+
AnsiStream.prototype._extractTextAndStyles = function(originalText) {
|
34
|
+
var matches, numbers, text, _ref;
|
35
|
+
matches = originalText.match(/^([\d;]*)m([^]*)$/m);
|
36
|
+
if (!matches) {
|
37
|
+
return [originalText, null];
|
38
|
+
}
|
39
|
+
_ref = matches, matches = _ref[0], numbers = _ref[1], text = _ref[2];
|
40
|
+
return [text, numbers.split(";")];
|
41
|
+
};
|
42
|
+
|
43
|
+
return AnsiStream;
|
44
|
+
|
45
|
+
})();
|
46
|
+
|
47
|
+
AnsiStyle = (function() {
|
48
|
+
var COLORS;
|
49
|
+
|
50
|
+
COLORS = {
|
51
|
+
0: 'black',
|
52
|
+
1: 'red',
|
53
|
+
2: 'green',
|
54
|
+
3: 'yellow',
|
55
|
+
4: 'blue',
|
56
|
+
5: 'magenta',
|
57
|
+
6: 'cyan',
|
58
|
+
7: 'white',
|
59
|
+
8: null,
|
60
|
+
9: 'default'
|
61
|
+
};
|
62
|
+
|
63
|
+
function AnsiStyle() {
|
64
|
+
this.reset();
|
65
|
+
}
|
66
|
+
|
67
|
+
AnsiStyle.prototype.apply = function(newStyles) {
|
68
|
+
var style, _i, _len, _results;
|
69
|
+
if (!newStyles) {
|
70
|
+
return;
|
71
|
+
}
|
72
|
+
_results = [];
|
73
|
+
for (_i = 0, _len = newStyles.length; _i < _len; _i++) {
|
74
|
+
style = newStyles[_i];
|
75
|
+
style = parseInt(style);
|
76
|
+
if (style === 0) {
|
77
|
+
_results.push(this.reset());
|
78
|
+
} else if (style === 1) {
|
79
|
+
_results.push(this.bright = true);
|
80
|
+
} else if ((30 <= style && style <= 39) && style !== 38) {
|
81
|
+
_results.push(this._applyStyle('foreground', style));
|
82
|
+
} else if ((40 <= style && style <= 49) && style !== 48) {
|
83
|
+
_results.push(this._applyStyle('background', style));
|
84
|
+
} else if (style === 4) {
|
85
|
+
_results.push(this.underline = true);
|
86
|
+
} else if (style === 24) {
|
87
|
+
_results.push(this.underline = false);
|
88
|
+
} else {
|
89
|
+
_results.push(void 0);
|
90
|
+
}
|
91
|
+
}
|
92
|
+
return _results;
|
93
|
+
};
|
94
|
+
|
95
|
+
AnsiStyle.prototype.reset = function() {
|
96
|
+
this.background = this.foreground = 'default';
|
97
|
+
return this.underline = this.bright = false;
|
98
|
+
};
|
99
|
+
|
100
|
+
AnsiStyle.prototype.toClass = function() {
|
101
|
+
var classes;
|
102
|
+
classes = [];
|
103
|
+
if (this.background) {
|
104
|
+
classes.push("ansi-background-" + this.background);
|
105
|
+
}
|
106
|
+
if (this.foreground) {
|
107
|
+
classes.push("ansi-foreground-" + this.foreground);
|
108
|
+
}
|
109
|
+
if (this.bright) {
|
110
|
+
classes.push("ansi-bright");
|
111
|
+
}
|
112
|
+
if (this.underline) {
|
113
|
+
classes.push("ansi-underline");
|
114
|
+
}
|
115
|
+
return classes.join(" ");
|
116
|
+
};
|
117
|
+
|
118
|
+
AnsiStyle.prototype._applyStyle = function(layer, number) {
|
119
|
+
return this[layer] = COLORS[number % 10];
|
120
|
+
};
|
121
|
+
|
122
|
+
return AnsiStyle;
|
123
|
+
|
124
|
+
})();
|
125
|
+
|
126
|
+
AnsiSpan = (function() {
|
127
|
+
var ENTITIES, ESCAPE_PATTERN;
|
128
|
+
|
129
|
+
function AnsiSpan() {}
|
130
|
+
|
131
|
+
ENTITIES = {
|
132
|
+
'&': '&',
|
133
|
+
'<': '<',
|
134
|
+
'>': '>',
|
135
|
+
"'": '''
|
136
|
+
};
|
137
|
+
|
138
|
+
ESCAPE_PATTERN = new RegExp("[" + (Object.keys(ENTITIES).join('')) + "]", 'g');
|
139
|
+
|
140
|
+
AnsiSpan.prototype.create = function(text, style) {
|
141
|
+
return "<span class='" + (style.toClass()) + "'>" + (this._escapeHTML(text)) + "</span>";
|
142
|
+
};
|
143
|
+
|
144
|
+
AnsiSpan.prototype._escapeHTML = function(text) {
|
145
|
+
return text.replace(ESCAPE_PATTERN, function(char) {
|
146
|
+
return ENTITIES[char];
|
147
|
+
});
|
148
|
+
};
|
149
|
+
|
150
|
+
return AnsiSpan;
|
151
|
+
|
152
|
+
})();
|
@@ -0,0 +1,67 @@
|
|
1
|
+
.ansi-underline {
|
2
|
+
text-decoration: underline;
|
3
|
+
}
|
4
|
+
|
5
|
+
.ansi-foreground-black {
|
6
|
+
color: rgb(0,0,0);
|
7
|
+
}
|
8
|
+
|
9
|
+
.ansi-foreground-red {
|
10
|
+
color: rgb(194,54,33);
|
11
|
+
}
|
12
|
+
|
13
|
+
.ansi-foreground-green {
|
14
|
+
color: rgb(37,188,36);
|
15
|
+
}
|
16
|
+
|
17
|
+
.ansi-foreground-yellow {
|
18
|
+
color: rgb(173,173,39);
|
19
|
+
}
|
20
|
+
|
21
|
+
.ansi-foreground-blue {
|
22
|
+
color: rgb(73,46,225);
|
23
|
+
}
|
24
|
+
|
25
|
+
.ansi-foreground-magenta {
|
26
|
+
color: rgb(211,56,211);
|
27
|
+
}
|
28
|
+
|
29
|
+
.ansi-foreground-cyan {
|
30
|
+
color: rgb(51,187,200);
|
31
|
+
}
|
32
|
+
|
33
|
+
.ansi-foreground-default {
|
34
|
+
}
|
35
|
+
|
36
|
+
// Background
|
37
|
+
|
38
|
+
.ansi-background-black {
|
39
|
+
background-color: rgb(129,131,131);
|
40
|
+
}
|
41
|
+
|
42
|
+
.ansi-foreground-red {
|
43
|
+
background-color: rgb(252,57,31);
|
44
|
+
}
|
45
|
+
|
46
|
+
.ansi-background-green {
|
47
|
+
background-color: rgb(49,231,34);
|
48
|
+
}
|
49
|
+
|
50
|
+
.ansi-background-yellow {
|
51
|
+
background-color: rgb(234,236,35);
|
52
|
+
}
|
53
|
+
|
54
|
+
.ansi-background-blue {
|
55
|
+
background-color: rgb(88,51,255);
|
56
|
+
}
|
57
|
+
|
58
|
+
.ansi-background-magenta {
|
59
|
+
background-color: rgb(249,53,248);
|
60
|
+
}
|
61
|
+
|
62
|
+
.ansi-background-cyan {
|
63
|
+
background-color: rgb(20,240,240);
|
64
|
+
}
|
65
|
+
|
66
|
+
.ansi-background-default {
|
67
|
+
}
|
metadata
ADDED
@@ -0,0 +1,136 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: ansi_stream
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Guillaume Malette
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2014-05-21 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: bundler
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '1.6'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '1.6'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rake
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ">="
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ">="
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: jasmine
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - ">="
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '0'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - ">="
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '0'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: phantomjs
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - "~>"
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '1.8'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - "~>"
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '1.8'
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: coffee-script
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - ">="
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '0'
|
76
|
+
type: :development
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - ">="
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '0'
|
83
|
+
description: Javascipt to colorize HTML with span
|
84
|
+
email:
|
85
|
+
- gmalette@gmail.com
|
86
|
+
executables: []
|
87
|
+
extensions: []
|
88
|
+
extra_rdoc_files: []
|
89
|
+
files:
|
90
|
+
- ".gitignore"
|
91
|
+
- Gemfile
|
92
|
+
- LICENSE.txt
|
93
|
+
- README.md
|
94
|
+
- Rakefile
|
95
|
+
- ansi_stream.gemspec
|
96
|
+
- lib/ansi_stream.rb
|
97
|
+
- lib/ansi_stream/version.rb
|
98
|
+
- spec/javascripts/ansi_stream_spec.coffee
|
99
|
+
- spec/javascripts/ansi_stream_spec.js
|
100
|
+
- spec/javascripts/helpers/.gitkeep
|
101
|
+
- spec/javascripts/support/jasmine.yml
|
102
|
+
- spec/javascripts/support/jasmine_helper.rb
|
103
|
+
- src/javascripts/ansi_stream.coffee
|
104
|
+
- vendor/assets/javascripts/ansi_stream.js
|
105
|
+
- vendor/assets/stylesheets/ansi_stream.css
|
106
|
+
homepage: ''
|
107
|
+
licenses:
|
108
|
+
- MIT
|
109
|
+
metadata: {}
|
110
|
+
post_install_message:
|
111
|
+
rdoc_options: []
|
112
|
+
require_paths:
|
113
|
+
- lib
|
114
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
115
|
+
requirements:
|
116
|
+
- - ">="
|
117
|
+
- !ruby/object:Gem::Version
|
118
|
+
version: '0'
|
119
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
120
|
+
requirements:
|
121
|
+
- - ">="
|
122
|
+
- !ruby/object:Gem::Version
|
123
|
+
version: '0'
|
124
|
+
requirements: []
|
125
|
+
rubyforge_project:
|
126
|
+
rubygems_version: 2.2.2
|
127
|
+
signing_key:
|
128
|
+
specification_version: 4
|
129
|
+
summary: Javascipt to colorize HTML with span
|
130
|
+
test_files:
|
131
|
+
- spec/javascripts/ansi_stream_spec.coffee
|
132
|
+
- spec/javascripts/ansi_stream_spec.js
|
133
|
+
- spec/javascripts/helpers/.gitkeep
|
134
|
+
- spec/javascripts/support/jasmine.yml
|
135
|
+
- spec/javascripts/support/jasmine_helper.rb
|
136
|
+
has_rdoc:
|