terminal 0.0.1.alpha.3 → 0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.gitignore +0 -1
- data/Gemfile.lock +33 -0
- data/Readme.md +2 -2
- data/bin/terminal +3 -0
- data/examples/ascii.sh +5 -0
- data/examples/homer.txt +18 -0
- data/lib/terminal/renderer.rb +26 -37
- data/lib/terminal/templates/preview.html.erb +1 -1
- data/lib/terminal/version.rb +1 -1
- data/spec/fixtures/ascii.sh.raw +18 -0
- data/spec/fixtures/ascii.sh.rendered +18 -0
- data/spec/spec_helper.rb +9 -17
- data/spec/support/fixture.rb +19 -0
- data/spec/terminal/renderer_spec.rb +12 -6
- metadata +13 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: d516a6b1b58bab0cc47218e13a03e77ad2cf00e0
|
4
|
+
data.tar.gz: 5cbcd3804c846cc919e4e5c3cb043fd8a4239164
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 2972ffd87796ed75c73ed8f72e54864c0d6d092c5d658ea0b36f58f8c1fb90251867c786977e8e2916df83398d2b3dddaac6f24f352e192dc7b1aa979887eb42
|
7
|
+
data.tar.gz: 00807d190ecb2c6c194e6bad44700e60591e5eb00e6b23277b734d8dafe600132341063afddc5c8823f96fc0a41cb59fe25a02412c505b58259506ab838aafd6
|
data/.gitignore
CHANGED
data/Gemfile.lock
ADDED
@@ -0,0 +1,33 @@
|
|
1
|
+
PATH
|
2
|
+
remote: .
|
3
|
+
specs:
|
4
|
+
terminal (0.0.1)
|
5
|
+
escape_utils (~> 1.0)
|
6
|
+
|
7
|
+
GEM
|
8
|
+
remote: https://rubygems.org/
|
9
|
+
specs:
|
10
|
+
diff-lcs (1.2.5)
|
11
|
+
escape_utils (1.0.1)
|
12
|
+
rake (10.3.2)
|
13
|
+
rspec (3.0.0)
|
14
|
+
rspec-core (~> 3.0.0)
|
15
|
+
rspec-expectations (~> 3.0.0)
|
16
|
+
rspec-mocks (~> 3.0.0)
|
17
|
+
rspec-core (3.0.2)
|
18
|
+
rspec-support (~> 3.0.0)
|
19
|
+
rspec-expectations (3.0.2)
|
20
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
21
|
+
rspec-support (~> 3.0.0)
|
22
|
+
rspec-mocks (3.0.2)
|
23
|
+
rspec-support (~> 3.0.0)
|
24
|
+
rspec-support (3.0.2)
|
25
|
+
|
26
|
+
PLATFORMS
|
27
|
+
ruby
|
28
|
+
|
29
|
+
DEPENDENCIES
|
30
|
+
bundler (~> 1.6)
|
31
|
+
rake
|
32
|
+
rspec
|
33
|
+
terminal!
|
data/Readme.md
CHANGED
@@ -1,8 +1,8 @@
|
|
1
|
-
![logo](http://buildboxhq.github.io/terminal/images/logo.
|
1
|
+
![logo](http://buildboxhq.github.io/terminal/images/logo.svg)
|
2
2
|
|
3
3
|
[![Gem Version](https://badge.fury.io/rb/terminal.png)](https://rubygems.org/gems/terminal)
|
4
4
|
|
5
|
-
Terminal
|
5
|
+
Terminal is a Ruby library for converting arbitrary shell output (with ANSI) into beautifully rendered HTML. See http://www.termsys.demon.co.uk/vtansi.htm for more information about ANSI Terminal Control Escape Sequences.
|
6
6
|
|
7
7
|
## Installation
|
8
8
|
|
data/bin/terminal
CHANGED
data/examples/ascii.sh
ADDED
data/examples/homer.txt
ADDED
@@ -0,0 +1,18 @@
|
|
1
|
+
___ _____
|
2
|
+
.'/,-Y" "~-.
|
3
|
+
l.Y ^.
|
4
|
+
/\ _\_
|
5
|
+
i ___/" "\
|
6
|
+
| /" "\ o !
|
7
|
+
l ] o !__./
|
8
|
+
\ _ _ \.___./ "~\
|
9
|
+
X \/ \ ___./
|
10
|
+
( \ ___. _..--~~" ~`-.
|
11
|
+
` Z,-- / \
|
12
|
+
\__. ( / ______)
|
13
|
+
\ l /-----~~" /
|
14
|
+
Y \ /
|
15
|
+
| "x______.^
|
16
|
+
| \
|
17
|
+
j Y
|
18
|
+
->Homer<-
|
data/lib/terminal/renderer.rb
CHANGED
@@ -39,7 +39,7 @@ module Terminal
|
|
39
39
|
# \e[?m use the ? color going forward
|
40
40
|
def emulate_terminal_rendering(string)
|
41
41
|
# Splits the output into intersting parts.
|
42
|
-
parts = string.scan(/[\n\r\b]|\e\[[\d;]+m|\e
|
42
|
+
parts = string.scan(/[\n\r\b]|\e\[[\d;]+m|\e|./)
|
43
43
|
|
44
44
|
lines = []
|
45
45
|
|
@@ -66,46 +66,35 @@ module Terminal
|
|
66
66
|
when "\b"
|
67
67
|
pointer = cursor-1
|
68
68
|
|
69
|
-
# Seek backwards until something that isn't a color is reached.
|
69
|
+
# Seek backwards until something that isn't a color is reached. When we
|
70
|
+
# reach it (probably a string) remove the last character of it.
|
70
71
|
# Colors aren't affected by \b
|
71
|
-
while pointer
|
72
|
+
while pointer >= 0
|
72
73
|
char_at_pointer = line[pointer]
|
73
|
-
|
74
|
+
|
75
|
+
unless char_at_pointer.kind_of?(Terminal::Node)
|
76
|
+
line[pointer] = char_at_pointer[0..-2]
|
77
|
+
break
|
78
|
+
end
|
74
79
|
|
75
80
|
pointer -= 1
|
76
81
|
end
|
82
|
+
when /\A\e\[(.*)m\z/
|
83
|
+
color_code = $1.to_s
|
77
84
|
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
seeked = string[index..(index + 10)]
|
82
|
-
|
83
|
-
# Does the next lot of characters look like a color code?
|
84
|
-
matched = seeked.to_s.match(/\A\e\[(.*)m\z/)
|
85
|
-
|
86
|
-
# If it does, skip over the characters that are the color,
|
87
|
-
# and track it at a single color object in the line. We do this
|
88
|
-
# so when we \b after a color, we skip back across the whole color
|
89
|
-
# not just the last character in the color sequence.
|
90
|
-
if matched
|
91
|
-
color_code = matched[1].to_s
|
92
|
-
|
93
|
-
# Determine what sort of color code it is.
|
94
|
-
if color_code == "0"
|
95
|
-
line[cursor] = Terminal::Reset.new(colors_opened)
|
96
|
-
|
97
|
-
colors_opened = 0
|
98
|
-
else
|
99
|
-
line[cursor] = Terminal::Color.new(color_code)
|
100
|
-
|
101
|
-
colors_opened += 1
|
102
|
-
end
|
85
|
+
# Determine what sort of color code it is.
|
86
|
+
if color_code == "0"
|
87
|
+
line[cursor] = Terminal::Reset.new(colors_opened)
|
103
88
|
|
104
|
-
|
105
|
-
|
89
|
+
colors_opened = 0
|
90
|
+
else
|
91
|
+
line[cursor] = Terminal::Color.new(color_code)
|
106
92
|
|
107
|
-
|
93
|
+
colors_opened += 1
|
108
94
|
end
|
95
|
+
|
96
|
+
index += char.length
|
97
|
+
cursor += 1
|
109
98
|
else
|
110
99
|
line[cursor] = char
|
111
100
|
cursor += 1
|
@@ -118,15 +107,15 @@ module Terminal
|
|
118
107
|
index += 1
|
119
108
|
end
|
120
109
|
|
110
|
+
# Be sure to reset any unclosed colors on the last line
|
111
|
+
if colors_opened > 0
|
112
|
+
line << Terminal::Reset.new(colors_opened)
|
113
|
+
end
|
114
|
+
|
121
115
|
# Add back in the last line if the end of the output
|
122
116
|
# didn't end with a \n
|
123
117
|
lines << line if line.any?
|
124
118
|
|
125
|
-
# Be sure to reset any unclosed colors.
|
126
|
-
if colors_opened > 0
|
127
|
-
lines << [ Terminal::Reset.new(colors_opened) ]
|
128
|
-
end
|
129
|
-
|
130
119
|
# Join all the strings back together again
|
131
120
|
lines = lines.map do |parts|
|
132
121
|
completed_line = parts.map(&:to_s).join("")
|
data/lib/terminal/version.rb
CHANGED
@@ -0,0 +1,18 @@
|
|
1
|
+
[33m ___ _____
|
2
|
+
.'/,-Y" "~-.
|
3
|
+
l.Y ^.
|
4
|
+
/\ _\_
|
5
|
+
i ___/" "\
|
6
|
+
| /" "\ o !
|
7
|
+
l ] o !__./
|
8
|
+
\ _ _ \.___./ "~\
|
9
|
+
X \/ \ ___./
|
10
|
+
( \ ___. _..--~~" ~`-.
|
11
|
+
` Z,-- / \
|
12
|
+
\__. ( / ______)
|
13
|
+
\ l /-----~~" /
|
14
|
+
Y \ /
|
15
|
+
| "x______.^
|
16
|
+
| \
|
17
|
+
j Y
|
18
|
+
->Homer<-[0m
|
@@ -0,0 +1,18 @@
|
|
1
|
+
<span class='c33'> ___ _____
|
2
|
+
.'/,-Y" "~-.
|
3
|
+
l.Y ^.
|
4
|
+
/\ _\_
|
5
|
+
i ___/" "\
|
6
|
+
| /" "\ o !
|
7
|
+
l ] o !__./
|
8
|
+
\ _ _ \.___./ "~\
|
9
|
+
X \/ \ ___./
|
10
|
+
( \ ___. _..--~~" ~`-.
|
11
|
+
` Z,-- / \
|
12
|
+
\__. ( / ______)
|
13
|
+
\ l /-----~~" /
|
14
|
+
Y \ /
|
15
|
+
| "x______.^
|
16
|
+
| \
|
17
|
+
j Y
|
18
|
+
->Homer<-</span>
|
data/spec/spec_helper.rb
CHANGED
@@ -3,22 +3,14 @@ Bundler.setup
|
|
3
3
|
|
4
4
|
require 'terminal'
|
5
5
|
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
end
|
6
|
+
# Requires supporting ruby files with custom matchers and macros, etc,
|
7
|
+
# in spec/support/ and its subdirectories.
|
8
|
+
Dir["./spec/support/**/*.rb"].sort.each {|f| require f}
|
10
9
|
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
attr_reader :raw, :rendered
|
19
|
-
|
20
|
-
def initialize(raw, rendered)
|
21
|
-
@raw = raw
|
22
|
-
@rendered = rendered
|
23
|
-
end
|
10
|
+
RSpec.configure do |config|
|
11
|
+
# Run specs in random order to surface order dependencies. If you find an
|
12
|
+
# order dependency and want to debug it, you can fix the order by providing
|
13
|
+
# the seed, which is printed after each run.
|
14
|
+
# --seed 1234
|
15
|
+
config.order = "random"
|
24
16
|
end
|
@@ -0,0 +1,19 @@
|
|
1
|
+
class Fixture
|
2
|
+
def self.path
|
3
|
+
File.join(File.expand_path(File.dirname(__FILE__)), '..', 'fixtures')
|
4
|
+
end
|
5
|
+
|
6
|
+
def self.for(name)
|
7
|
+
raw = File.read(File.join(path, "#{name}.raw"))
|
8
|
+
rendered = File.read(File.join(path, "#{name}.rendered"))
|
9
|
+
|
10
|
+
new(raw, rendered)
|
11
|
+
end
|
12
|
+
|
13
|
+
attr_reader :raw, :rendered
|
14
|
+
|
15
|
+
def initialize(raw, rendered)
|
16
|
+
@raw = raw
|
17
|
+
@rendered = rendered
|
18
|
+
end
|
19
|
+
end
|
@@ -11,19 +11,25 @@ describe Terminal::Renderer do
|
|
11
11
|
end
|
12
12
|
end
|
13
13
|
|
14
|
-
describe "
|
15
|
-
|
14
|
+
describe "rendering of ascii.sh" do
|
15
|
+
it "returns the expected result" do
|
16
|
+
fixture = Fixture.for("ascii.sh")
|
16
17
|
|
18
|
+
expect(renderer.render(fixture.raw)).to eql(fixture.rendered)
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
describe "#render" do
|
17
23
|
it "closes colors that get opened" do
|
18
|
-
raw = "he\
|
24
|
+
raw = "he\033[81mllo"
|
19
25
|
|
20
26
|
expect(renderer.render(raw)).to eql("he<span class='c81'>llo</span>")
|
21
27
|
end
|
22
28
|
|
23
|
-
it "
|
24
|
-
raw = "he\e[
|
29
|
+
it "skips over colors when backspacing" do
|
30
|
+
raw = "he\e[32m\e[33m\bllo"
|
25
31
|
|
26
|
-
expect(renderer.render(raw)).to eql("
|
32
|
+
expect(renderer.render(raw)).to eql("h<span class='c32'><span class='c33'>llo</span></span>")
|
27
33
|
end
|
28
34
|
|
29
35
|
it "starts overwriting characters when you \\r midway through somehing" do
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: terminal
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: '0.1'
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Keith Pitt
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-07-
|
11
|
+
date: 2014-07-10 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: escape_utils
|
@@ -76,11 +76,14 @@ extra_rdoc_files: []
|
|
76
76
|
files:
|
77
77
|
- ".gitignore"
|
78
78
|
- Gemfile
|
79
|
+
- Gemfile.lock
|
79
80
|
- Rakefile
|
80
81
|
- Readme.md
|
81
82
|
- bin/terminal
|
83
|
+
- examples/ascii.sh
|
82
84
|
- examples/curl.sh
|
83
85
|
- examples/generate
|
86
|
+
- examples/homer.txt
|
84
87
|
- lib/terminal.rb
|
85
88
|
- lib/terminal/cli.rb
|
86
89
|
- lib/terminal/color.rb
|
@@ -90,9 +93,12 @@ files:
|
|
90
93
|
- lib/terminal/reset.rb
|
91
94
|
- lib/terminal/templates/preview.html.erb
|
92
95
|
- lib/terminal/version.rb
|
96
|
+
- spec/fixtures/ascii.sh.raw
|
97
|
+
- spec/fixtures/ascii.sh.rendered
|
93
98
|
- spec/fixtures/curl.sh.raw
|
94
99
|
- spec/fixtures/curl.sh.rendered
|
95
100
|
- spec/spec_helper.rb
|
101
|
+
- spec/support/fixture.rb
|
96
102
|
- spec/terminal/renderer_spec.rb
|
97
103
|
- terminal.gemspec
|
98
104
|
homepage: https://github.com/buildboxhq/terminal
|
@@ -110,9 +116,9 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
110
116
|
version: '0'
|
111
117
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
112
118
|
requirements:
|
113
|
-
- - "
|
119
|
+
- - ">="
|
114
120
|
- !ruby/object:Gem::Version
|
115
|
-
version:
|
121
|
+
version: '0'
|
116
122
|
requirements: []
|
117
123
|
rubyforge_project:
|
118
124
|
rubygems_version: 2.3.0
|
@@ -120,7 +126,10 @@ signing_key:
|
|
120
126
|
specification_version: 4
|
121
127
|
summary: Renders ASCII as HTML
|
122
128
|
test_files:
|
129
|
+
- spec/fixtures/ascii.sh.raw
|
130
|
+
- spec/fixtures/ascii.sh.rendered
|
123
131
|
- spec/fixtures/curl.sh.raw
|
124
132
|
- spec/fixtures/curl.sh.rendered
|
125
133
|
- spec/spec_helper.rb
|
134
|
+
- spec/support/fixture.rb
|
126
135
|
- spec/terminal/renderer_spec.rb
|