ansi_stream 0.0.1 → 0.0.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Rakefile +12 -9
- data/lib/ansi_stream/version.rb +1 -1
- data/spec/javascripts/ansi_stream_spec.coffee +13 -11
- data/spec/javascripts/support/jasmine.yml +3 -3
- data/{src → vendor/assets}/javascripts/ansi_stream.coffee +10 -20
- metadata +2 -3
- data/vendor/assets/javascripts/ansi_stream.js +0 -152
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 6b4720f95b21296654c6a78831eeb147ce974e9d
|
4
|
+
data.tar.gz: 70c57a31f3941699d388ffa946da543dbf23041c
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 14c84a8c76714cbef8887e2499a2ae26dbe943106d90132ecd39392d8f641daeed5021f5a5918c66fdc3c03684f435c19daa610a3fb4c4cd11ac271c5fe49bdc
|
7
|
+
data.tar.gz: 1b6d377aba05ba03bd74e6dd3315b5070b8af4ab49103a8e799536e16081977a2ea22cf6bd28c05ba16bd8b33ac0251c38ced218387c4ab107bd1d62d43c9513
|
data/Rakefile
CHANGED
@@ -1,25 +1,28 @@
|
|
1
1
|
require "bundler/gem_tasks"
|
2
2
|
require 'jasmine'
|
3
3
|
require 'coffee-script'
|
4
|
+
require 'fileutils'
|
4
5
|
load 'jasmine/tasks/jasmine.rake'
|
5
6
|
|
6
|
-
task :
|
7
|
+
task :compile do
|
7
8
|
def compile(file, target)
|
8
9
|
File.new(target, "w").write(CoffeeScript.compile(File.read(file), bare: true))
|
9
10
|
end
|
10
11
|
|
11
|
-
|
12
|
-
|
13
|
-
compile(file, target)
|
14
|
-
end
|
12
|
+
def compile_dir(source_dir, target_dir)
|
13
|
+
FileUtils.mkdir_p target_dir
|
15
14
|
|
16
|
-
|
17
|
-
|
18
|
-
|
15
|
+
Dir["#{source_dir}/**/*.coffee"].each do |file|
|
16
|
+
target = "#{target_dir}/#{File.basename(file, ".coffee")}.js"
|
17
|
+
compile(file, target)
|
18
|
+
end
|
19
19
|
end
|
20
|
+
|
21
|
+
compile_dir('vendor', 'tmp/assets')
|
22
|
+
compile_dir('spec', 'tmp/spec')
|
20
23
|
end
|
21
24
|
|
22
25
|
task :test do
|
23
26
|
end
|
24
27
|
|
25
|
-
task default: [:
|
28
|
+
task default: [:compile, 'jasmine:ci']
|
data/lib/ansi_stream/version.rb
CHANGED
@@ -4,33 +4,35 @@ describe "AnsiStream", ->
|
|
4
4
|
stream = new AnsiStream()
|
5
5
|
|
6
6
|
expectClass = (span, color) ->
|
7
|
-
expect(span
|
7
|
+
expect(span.className.indexOf(color)).toBeGreaterThan(-1)
|
8
8
|
|
9
9
|
it 'returns uncolorized spans if there are no escape codes', ->
|
10
|
-
|
10
|
+
span = stream.process("toto").childNodes[0]
|
11
|
+
expectClass(span, 'ansi-background-default')
|
12
|
+
expectClass(span, 'ansi-foreground-default')
|
11
13
|
|
12
14
|
it 'returns colorized spans if there is an foreground color code', ->
|
13
|
-
expectClass(stream.process('\u001B[31mtoto')[0], 'ansi-foreground-red')
|
15
|
+
expectClass(stream.process('\u001B[31mtoto').childNodes[0], 'ansi-foreground-red')
|
14
16
|
|
15
17
|
it 'returns colorized spans if there is an background color code', ->
|
16
|
-
expectClass(stream.process("\u001B[41mtoto")[0], 'ansi-background-red')
|
18
|
+
expectClass(stream.process("\u001B[41mtoto").childNodes[0], 'ansi-background-red')
|
17
19
|
|
18
20
|
it 'keeps modifying the style', ->
|
19
|
-
stream.process("\u001B[41mtoto")
|
20
|
-
span = stream.process('\u001B[31mtoto')[0]
|
21
|
+
stream.process("\u001B[41mtoto")
|
22
|
+
span = stream.process('\u001B[31mtoto').childNodes[0]
|
21
23
|
expectClass(span, 'ansi-background-red')
|
22
24
|
expectClass(span, 'ansi-foreground-red')
|
23
25
|
|
24
26
|
it 'resets the style when encountering a marker', ->
|
25
27
|
spans = stream.process("\u001B[41;31mtoto\u001B[0mtiti")
|
26
|
-
expectClass(spans[0], 'ansi-background-red')
|
27
|
-
expectClass(spans[1], 'ansi-background-default')
|
28
|
+
expectClass(spans.childNodes[0], 'ansi-background-red')
|
29
|
+
expectClass(spans.childNodes[1], 'ansi-background-default')
|
28
30
|
|
29
31
|
it 'makes the text bright', ->
|
30
|
-
expectClass(stream.process("\u001B[1mtoto")[0], 'ansi-bright')
|
32
|
+
expectClass(stream.process("\u001B[1mtoto").childNodes[0], 'ansi-bright')
|
31
33
|
|
32
34
|
it 'handles underline', ->
|
33
35
|
spans = stream.process("\u001B[4mtoto\u001B[24mtiti")
|
34
|
-
expectClass(spans[0], 'ansi-underline')
|
35
|
-
expect(spans[1].indexOf('ansi-underline')).toBe(-1)
|
36
|
+
expectClass(spans.childNodes[0], 'ansi-underline')
|
37
|
+
expect(spans.childNodes[1].className.indexOf('ansi-underline')).toBe(-1)
|
36
38
|
|
@@ -11,7 +11,7 @@
|
|
11
11
|
# - dist/**/*.js
|
12
12
|
#
|
13
13
|
src_files:
|
14
|
-
-
|
14
|
+
- '*.js'
|
15
15
|
|
16
16
|
# stylesheets
|
17
17
|
#
|
@@ -62,7 +62,7 @@ spec_files:
|
|
62
62
|
#
|
63
63
|
# src_dir: public
|
64
64
|
#
|
65
|
-
src_dir:
|
65
|
+
src_dir: tmp/assets
|
66
66
|
|
67
67
|
# spec_dir
|
68
68
|
#
|
@@ -73,7 +73,7 @@ src_dir:
|
|
73
73
|
#
|
74
74
|
# spec_dir: spec/javascripts
|
75
75
|
#
|
76
|
-
spec_dir:
|
76
|
+
spec_dir: tmp/spec
|
77
77
|
|
78
78
|
# spec_helper
|
79
79
|
#
|
@@ -1,4 +1,4 @@
|
|
1
|
-
class AnsiStream
|
1
|
+
class @AnsiStream
|
2
2
|
constructor: ->
|
3
3
|
@style = new AnsiStyle()
|
4
4
|
@span = new AnsiSpan()
|
@@ -7,13 +7,12 @@ class AnsiStream
|
|
7
7
|
parts = text.split(/\033\[/)
|
8
8
|
parts = parts.filter (part) -> part
|
9
9
|
|
10
|
-
spans =
|
10
|
+
spans = document.createDocumentFragment()
|
11
|
+
for part in parts
|
11
12
|
[partText, styles] = @_extractTextAndStyles(part)
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
else
|
16
|
-
partText
|
13
|
+
@style.apply(styles)
|
14
|
+
span = @span.create(partText, @style)
|
15
|
+
spans.appendChild(span)
|
17
16
|
|
18
17
|
spans
|
19
18
|
|
@@ -79,17 +78,8 @@ class AnsiStyle
|
|
79
78
|
this[layer] = COLORS[number % 10]
|
80
79
|
|
81
80
|
class AnsiSpan
|
82
|
-
ENTITIES =
|
83
|
-
'&': '&'
|
84
|
-
'<': '<'
|
85
|
-
'>': '>'
|
86
|
-
"'": '''
|
87
|
-
|
88
|
-
ESCAPE_PATTERN = new RegExp("[#{(Object.keys(ENTITIES).join(''))}]", 'g');
|
89
|
-
|
90
81
|
create: (text, style) ->
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
ENTITIES[char]
|
82
|
+
span = document.createElement('span')
|
83
|
+
span.innerHTML = text
|
84
|
+
span.className = style.toClass()
|
85
|
+
span
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: ansi_stream
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Guillaume Malette
|
@@ -100,8 +100,7 @@ files:
|
|
100
100
|
- spec/javascripts/helpers/.gitkeep
|
101
101
|
- spec/javascripts/support/jasmine.yml
|
102
102
|
- spec/javascripts/support/jasmine_helper.rb
|
103
|
-
-
|
104
|
-
- vendor/assets/javascripts/ansi_stream.js
|
103
|
+
- vendor/assets/javascripts/ansi_stream.coffee
|
105
104
|
- vendor/assets/stylesheets/ansi_stream.css
|
106
105
|
homepage: ''
|
107
106
|
licenses:
|
@@ -1,152 +0,0 @@
|
|
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
|
-
})();
|