terminal 0.0.1.alpha.2 → 0.0.1.alpha.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.gitignore +3 -0
- data/Readme.md +24 -0
- data/bin/terminal +16 -1
- data/examples/curl.sh +4 -0
- data/examples/generate +44 -0
- data/lib/terminal.rb +1 -0
- data/lib/terminal/preview.rb +30 -0
- data/lib/terminal/templates/preview.html.erb +99 -0
- data/lib/terminal/version.rb +1 -1
- data/spec/fixtures/curl.sh.raw +4 -0
- data/spec/fixtures/curl.sh.rendered +4 -0
- data/spec/spec_helper.rb +20 -0
- data/spec/terminal/renderer_spec.rb +41 -0
- metadata +9 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: a2a0074192ba83af5ba05e56242ba68423254d87
|
4
|
+
data.tar.gz: df0a7b8db3e1db4dd26b95f4b13fbc9bfba55019
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 834c6b10127a1c3f040f0a611b8da5276e546f6b2b83b3d9b38f7dd7add2bd7ee05d804aee29426a345db8a36ac3ae610a4a37fa9229feb03e81f5a017f964f8
|
7
|
+
data.tar.gz: b93a742431b08e4af2087e19903e0f97840056cdf939746ee6755575230a7be639a3821932cf6be22332d4b118d96367979f156a717fa303b71ba3b2add29ffa
|
data/.gitignore
CHANGED
data/Readme.md
CHANGED
@@ -47,6 +47,15 @@ terminal output.txt
|
|
47
47
|
|
48
48
|
With `rspec`, you'll need to use the `--tty` and `--color` options to force it to output colors.
|
49
49
|
|
50
|
+
We also provide a utility to preview the rendered version in a web browser. Simply append `--preview` to the command,
|
51
|
+
and when the render has finished, it will open in your web browser with a before/after show.
|
52
|
+
|
53
|
+
```bash
|
54
|
+
rspec --color --tty | terminal --preview
|
55
|
+
```
|
56
|
+
|
57
|
+
![logo](http://buildboxhq.github.io/terminal/images/preview.png)
|
58
|
+
|
50
59
|
### With the Buildbox API
|
51
60
|
|
52
61
|
First install [jq](http://stedolan.github.io/jq/), if you have [Homebrew](http://brew.sh/) installed, you can just `brew install jq`.
|
@@ -60,6 +69,21 @@ echo $(curl $JOB_LOG_URL -s | jq '.content') | terminal
|
|
60
69
|
|
61
70
|
For more information on the Buildbox Builds API, see: https://buildbox.io/docs/api/builds
|
62
71
|
|
72
|
+
## Generating Fixtures
|
73
|
+
|
74
|
+
To generate a fixture, first create a test case inside the `examples` folder. See the `curl.sh`
|
75
|
+
file as an example. You can then generate a `.raw` and `.rendered` file by running:
|
76
|
+
|
77
|
+
```bash
|
78
|
+
./generate curl.sh
|
79
|
+
```
|
80
|
+
|
81
|
+
You should then move the `raw` and `rendered` files to the `fixtures` folder.
|
82
|
+
|
83
|
+
```bash
|
84
|
+
mv examples/*{raw,rendered} spec/fixtures
|
85
|
+
```
|
86
|
+
|
63
87
|
## Contributing
|
64
88
|
|
65
89
|
1. Fork it ( https://github.com/[my-github-username]/terminal/fork )
|
data/bin/terminal
CHANGED
@@ -17,8 +17,23 @@ See https://buildboxhq.github.io/terminal for more information.
|
|
17
17
|
usage
|
18
18
|
end
|
19
19
|
|
20
|
+
preview = ARGV.delete('--preview')
|
21
|
+
|
20
22
|
if ($stdin.tty? && ARGV.empty?) || ARGV.delete('-h') || ARGV.delete('--help')
|
21
23
|
help
|
22
24
|
else
|
23
|
-
|
25
|
+
raw = ARGF.read
|
26
|
+
rendered = Terminal.render(raw)
|
27
|
+
|
28
|
+
if preview
|
29
|
+
require 'tempfile'
|
30
|
+
|
31
|
+
tempfile = Tempfile.new([ 'preview', '.html' ])
|
32
|
+
tempfile.write(Terminal::Preview.new(raw, rendered).render)
|
33
|
+
tempfile.close
|
34
|
+
|
35
|
+
exec %{open "#{tempfile.path}"}
|
36
|
+
else
|
37
|
+
puts rendered
|
38
|
+
end
|
24
39
|
end
|
data/examples/curl.sh
ADDED
data/examples/generate
ADDED
@@ -0,0 +1,44 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require 'pty'
|
4
|
+
$:.unshift(File.join(File.expand_path(File.dirname(__FILE__)), '..', 'lib'))
|
5
|
+
|
6
|
+
require 'terminal'
|
7
|
+
|
8
|
+
output = ""
|
9
|
+
read_io, write_io, pid = nil
|
10
|
+
|
11
|
+
file = ARGV[0]
|
12
|
+
|
13
|
+
read_io, write_io, pid = PTY.spawn("./#{file}")
|
14
|
+
|
15
|
+
write_io.close
|
16
|
+
|
17
|
+
loop do
|
18
|
+
fds, = IO.select([read_io], nil, nil, 5)
|
19
|
+
if fds
|
20
|
+
# should have some data to read
|
21
|
+
begin
|
22
|
+
chunk = read_io.read_nonblock(10240)
|
23
|
+
if block_given?
|
24
|
+
yield chunk
|
25
|
+
end
|
26
|
+
output += chunk
|
27
|
+
rescue Errno::EAGAIN, Errno::EWOULDBLOCK
|
28
|
+
# do select again
|
29
|
+
rescue EOFError, Errno::EIO # EOFError from OSX, EIO is raised by ubuntu
|
30
|
+
break
|
31
|
+
end
|
32
|
+
end
|
33
|
+
# if fds are empty, timeout expired - run another iteration
|
34
|
+
end
|
35
|
+
|
36
|
+
read_io.close
|
37
|
+
Process.waitpid(pid)
|
38
|
+
|
39
|
+
raw = output.chomp.strip
|
40
|
+
rendered = Terminal.render(output)
|
41
|
+
|
42
|
+
File.open("#{file}.raw", "w") { |file| file.write(raw) }
|
43
|
+
File.open("#{file}.rendered", "w") { |file| file.write(rendered) }
|
44
|
+
File.open("#{file}.html", "w") { |file| file.write(Terminal::Preview.new(raw, rendered).render) }
|
data/lib/terminal.rb
CHANGED
@@ -0,0 +1,30 @@
|
|
1
|
+
require 'erb'
|
2
|
+
|
3
|
+
module Terminal
|
4
|
+
class Preview
|
5
|
+
class Binding < Struct.new(:raw, :rendered)
|
6
|
+
def get_binding
|
7
|
+
binding
|
8
|
+
end
|
9
|
+
end
|
10
|
+
|
11
|
+
def initialize(raw, rendered)
|
12
|
+
@raw = raw
|
13
|
+
@rendered = rendered
|
14
|
+
end
|
15
|
+
|
16
|
+
def render
|
17
|
+
template = File.read(template_path)
|
18
|
+
renderer = ERB.new(template)
|
19
|
+
binding = Binding.new(@raw, @rendered)
|
20
|
+
|
21
|
+
renderer.result(binding.get_binding)
|
22
|
+
end
|
23
|
+
|
24
|
+
private
|
25
|
+
|
26
|
+
def template_path
|
27
|
+
File.join(File.expand_path(File.dirname(__FILE__)), 'templates/preview.html.erb')
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
@@ -0,0 +1,99 @@
|
|
1
|
+
<!DOCTYPE html>
|
2
|
+
<html>
|
3
|
+
<head>
|
4
|
+
<style>
|
5
|
+
.code {
|
6
|
+
background: #171717;
|
7
|
+
border-radius: 5px;
|
8
|
+
color: white;
|
9
|
+
padding: 30px;
|
10
|
+
margin-bottom: 15px;
|
11
|
+
word-break: break-word;
|
12
|
+
white-space: pre-wrap;
|
13
|
+
overflow-wrap: break-word;
|
14
|
+
}
|
15
|
+
|
16
|
+
.code pre {
|
17
|
+
margin: 0;
|
18
|
+
padding: 0;
|
19
|
+
font-family: Monaco, courier;
|
20
|
+
font-size: 12px;
|
21
|
+
line-height: 20px;
|
22
|
+
}
|
23
|
+
|
24
|
+
/* yellow */
|
25
|
+
.c33 {
|
26
|
+
color: #c6c502;
|
27
|
+
}
|
28
|
+
|
29
|
+
/* green */
|
30
|
+
.c32 {
|
31
|
+
color: #00bd02;
|
32
|
+
}
|
33
|
+
|
34
|
+
/* intense green */
|
35
|
+
.c1 {
|
36
|
+
color: #5ef765;
|
37
|
+
}
|
38
|
+
|
39
|
+
/* red */
|
40
|
+
.c31 {
|
41
|
+
color: #e10c02;
|
42
|
+
}
|
43
|
+
|
44
|
+
/* blue */
|
45
|
+
.c34 {
|
46
|
+
color: #8db7e0;
|
47
|
+
}
|
48
|
+
|
49
|
+
/* magent */
|
50
|
+
.c35 {
|
51
|
+
color: #ceacde;
|
52
|
+
}
|
53
|
+
|
54
|
+
/* cyan */
|
55
|
+
.c36 {
|
56
|
+
color: #00cdd9;
|
57
|
+
}
|
58
|
+
|
59
|
+
/* black (but we can't use black, so a diff color) */
|
60
|
+
.c30 {
|
61
|
+
color: #666;
|
62
|
+
}
|
63
|
+
|
64
|
+
/* grey */
|
65
|
+
.c90 {
|
66
|
+
color: #838887;
|
67
|
+
}
|
68
|
+
|
69
|
+
body {
|
70
|
+
margin: 0;
|
71
|
+
padding: 0;
|
72
|
+
}
|
73
|
+
|
74
|
+
.previews {
|
75
|
+
overflow: hidden;
|
76
|
+
padding: 20px;
|
77
|
+
}
|
78
|
+
|
79
|
+
.preview-left, .preview-right {
|
80
|
+
width: 50%;
|
81
|
+
float: left;
|
82
|
+
}
|
83
|
+
|
84
|
+
.preview-left .code {
|
85
|
+
margin-right: 10px;
|
86
|
+
}
|
87
|
+
|
88
|
+
.preview-right .code {
|
89
|
+
margin-left: 10px;
|
90
|
+
}
|
91
|
+
</style>
|
92
|
+
</head>
|
93
|
+
<body>
|
94
|
+
<div class="previews">
|
95
|
+
<div class="preview-left"><div class="code"><pre><%= raw %></pre></div></div>
|
96
|
+
<div class="preview-right"><div class="code"><pre><%= rendered %></pre></div></div>
|
97
|
+
</div>
|
98
|
+
</body>
|
99
|
+
</html>
|
data/lib/terminal/version.rb
CHANGED
@@ -0,0 +1,4 @@
|
|
1
|
+
[90m$[0m curl -o /tmp/file.txt https://example.com/file.txt
|
2
|
+
% Total % Received % Xferd Average Speed Time Time Time Current
|
3
|
+
Dload Upload Total Spent Left Speed
|
4
|
+
|
5
|
0 0 0 0 0 0 0 0 --:--:-- --:--:-- --:--:-- 0
|
1
6
|
0 0 0 0 0 0 0 0 --:--:-- --:--:-- --:--:-- 0
|
2
7
|
0 0 0 0 0 0 0 0 --:--:-- 0:00:01 --:--:-- 0
|
data/spec/spec_helper.rb
CHANGED
@@ -2,3 +2,23 @@ require 'bundler/setup'
|
|
2
2
|
Bundler.setup
|
3
3
|
|
4
4
|
require 'terminal'
|
5
|
+
|
6
|
+
class Fixture
|
7
|
+
def self.path
|
8
|
+
File.join(File.expand_path(File.dirname(__FILE__)), 'fixtures')
|
9
|
+
end
|
10
|
+
|
11
|
+
def self.for(name)
|
12
|
+
raw = File.read(File.join(path, "#{name}.raw"))
|
13
|
+
rendered = File.read(File.join(path, "#{name}.rendered"))
|
14
|
+
|
15
|
+
new(raw, rendered)
|
16
|
+
end
|
17
|
+
|
18
|
+
attr_reader :raw, :rendered
|
19
|
+
|
20
|
+
def initialize(raw, rendered)
|
21
|
+
@raw = raw
|
22
|
+
@rendered = rendered
|
23
|
+
end
|
24
|
+
end
|
@@ -0,0 +1,41 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Terminal::Renderer do
|
4
|
+
let(:renderer) { Terminal::Renderer.new }
|
5
|
+
|
6
|
+
describe "rendering of curl.sh" do
|
7
|
+
it "returns the expected result" do
|
8
|
+
fixture = Fixture.for("curl.sh")
|
9
|
+
|
10
|
+
expect(renderer.render(fixture.raw)).to eql(fixture.rendered)
|
11
|
+
end
|
12
|
+
end
|
13
|
+
|
14
|
+
describe "#render" do
|
15
|
+
let(:hello_output) { "he\e[81mllo" }
|
16
|
+
|
17
|
+
it "closes colors that get opened" do
|
18
|
+
raw = "he\e[81mllo"
|
19
|
+
|
20
|
+
expect(renderer.render(raw)).to eql("he<span class='c81'>llo</span>")
|
21
|
+
end
|
22
|
+
|
23
|
+
it "backspaces colors" do
|
24
|
+
raw = "he\e[81m\e[90m\bllo"
|
25
|
+
|
26
|
+
expect(renderer.render(raw)).to eql("hello")
|
27
|
+
end
|
28
|
+
|
29
|
+
it "starts overwriting characters when you \\r midway through somehing" do
|
30
|
+
raw = "hello\rb"
|
31
|
+
|
32
|
+
expect(renderer.render(raw)).to eql("bello")
|
33
|
+
end
|
34
|
+
|
35
|
+
it "colors across multiple lines" do
|
36
|
+
raw = "\e[81mhello\n\nfriend\e[0m"
|
37
|
+
|
38
|
+
expect(renderer.render(raw)).to eql("<span class='c81'>hello\n \nfriend</span>")
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: terminal
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.1.alpha.
|
4
|
+
version: 0.0.1.alpha.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Keith Pitt
|
@@ -79,13 +79,19 @@ files:
|
|
79
79
|
- Rakefile
|
80
80
|
- Readme.md
|
81
81
|
- bin/terminal
|
82
|
+
- examples/curl.sh
|
83
|
+
- examples/generate
|
82
84
|
- lib/terminal.rb
|
83
85
|
- lib/terminal/cli.rb
|
84
86
|
- lib/terminal/color.rb
|
85
87
|
- lib/terminal/node.rb
|
88
|
+
- lib/terminal/preview.rb
|
86
89
|
- lib/terminal/renderer.rb
|
87
90
|
- lib/terminal/reset.rb
|
91
|
+
- lib/terminal/templates/preview.html.erb
|
88
92
|
- lib/terminal/version.rb
|
93
|
+
- spec/fixtures/curl.sh.raw
|
94
|
+
- spec/fixtures/curl.sh.rendered
|
89
95
|
- spec/spec_helper.rb
|
90
96
|
- spec/terminal/renderer_spec.rb
|
91
97
|
- terminal.gemspec
|
@@ -114,5 +120,7 @@ signing_key:
|
|
114
120
|
specification_version: 4
|
115
121
|
summary: Renders ASCII as HTML
|
116
122
|
test_files:
|
123
|
+
- spec/fixtures/curl.sh.raw
|
124
|
+
- spec/fixtures/curl.sh.rendered
|
117
125
|
- spec/spec_helper.rb
|
118
126
|
- spec/terminal/renderer_spec.rb
|