terminal 0.1.1 → 0.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Gemfile.lock +1 -1
- data/Readme.md +4 -4
- data/lib/terminal/renderer.rb +59 -6
- data/lib/terminal/version.rb +1 -1
- data/spec/terminal/renderer_spec.rb +42 -0
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 4f11cc567d402255f58454144255b1f72881b70e
|
4
|
+
data.tar.gz: df412b25640995f4ee16c04e01bf0de484771f25
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 81ea8c713c6b2d49f2bc8b6b0c7c1f82298cb435b25f58a166eedb5ef33a74d9b0171f146b168a0cc2778fb2945df88a0133485b97402f582e8964b998349919
|
7
|
+
data.tar.gz: 2f68cdd314e1503a8227d986497fbf047fe437956dc9a799f1f2b6773d31b22feade0c8c5c06d68f5a8072a385953dc0c4d073465680fcf547d996baddb08a09
|
data/Gemfile.lock
CHANGED
data/Readme.md
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
![logo](http://
|
1
|
+
![logo](http://buildbox.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
|
|
@@ -54,7 +54,7 @@ and when the render has finished, it will open in your web browser with a before
|
|
54
54
|
rspec --color --tty | terminal --preview
|
55
55
|
```
|
56
56
|
|
57
|
-
![logo](http://
|
57
|
+
![logo](http://buildbox.github.io/terminal/images/preview.png)
|
58
58
|
|
59
59
|
### With the Buildbox API
|
60
60
|
|
@@ -63,8 +63,8 @@ First install [jq](http://stedolan.github.io/jq/), if you have [Homebrew](http:/
|
|
63
63
|
Then, you can:
|
64
64
|
|
65
65
|
```bash
|
66
|
-
|
67
|
-
|
66
|
+
export JOB_LOG_URL="https://api.buildbox.io/v1/accounts/[account]/projects/[project]/builds/[build]/jobs/[job]/log?api_key=[api-key]"
|
67
|
+
curl $JOB_LOG_URL -s | jq '.content' -r | terminal
|
68
68
|
```
|
69
69
|
|
70
70
|
For more information on the Buildbox Builds API, see: https://buildbox.io/docs/api/builds
|
data/lib/terminal/renderer.rb
CHANGED
@@ -2,6 +2,41 @@ require 'escape_utils'
|
|
2
2
|
|
3
3
|
module Terminal
|
4
4
|
class Renderer
|
5
|
+
# If the string (which is a regex) matches, it'll split on that space, so we
|
6
|
+
# end up with an array of special characters and normal characters, i.e:
|
7
|
+
# [ '\n', '\r', 'a', 'b', '\e123m' ]
|
8
|
+
SPLIT_BY_CHARACTERS = [
|
9
|
+
# \n moves the cursor to a new line
|
10
|
+
# \r moves the cursor to the begining of the line
|
11
|
+
# \b moves the cursor back one
|
12
|
+
'[\n\r\b]',
|
13
|
+
|
14
|
+
# [K Erases from the current cursor position to the end of the current line.
|
15
|
+
'\e\[0?K',
|
16
|
+
|
17
|
+
# Clears tab at the current position
|
18
|
+
'\e\[0?[Gg]',
|
19
|
+
|
20
|
+
# [1K Erases from the current cursor position to the start of the current line.
|
21
|
+
# [2K Erases the entire current line.
|
22
|
+
'\e\[[1-2]K',
|
23
|
+
|
24
|
+
# \e[?D move the cursor back ? many characters
|
25
|
+
'\e\[[\d;]+D',
|
26
|
+
|
27
|
+
# \e[0m reset color information
|
28
|
+
# \e[?m use the ? color going forward
|
29
|
+
'\e\[[\d;]+m',
|
30
|
+
|
31
|
+
# Random escpae sequences
|
32
|
+
'\e',
|
33
|
+
|
34
|
+
# Every other character
|
35
|
+
'.'
|
36
|
+
]
|
37
|
+
|
38
|
+
SPLIT_BY_CHARACTERS_REGEX = Regexp.new(SPLIT_BY_CHARACTERS.join("|"))
|
39
|
+
|
5
40
|
def render(output)
|
6
41
|
return "" if output.nil? || output.strip.length == 0
|
7
42
|
|
@@ -32,14 +67,9 @@ module Terminal
|
|
32
67
|
|
33
68
|
private
|
34
69
|
|
35
|
-
# \n moves the cursor to a new line
|
36
|
-
# \r moves the cursor to the begining of the line
|
37
|
-
# \b moves the cursor back one
|
38
|
-
# \e[0m reset color information
|
39
|
-
# \e[?m use the ? color going forward
|
40
70
|
def emulate_terminal_rendering(string)
|
41
71
|
# Splits the output into intersting parts.
|
42
|
-
parts = string.scan(
|
72
|
+
parts = string.scan(SPLIT_BY_CHARACTERS_REGEX)
|
43
73
|
|
44
74
|
lines = []
|
45
75
|
|
@@ -58,11 +88,27 @@ module Terminal
|
|
58
88
|
parts.each do |char|
|
59
89
|
case char
|
60
90
|
when "\n"
|
91
|
+
# Starts writing from a new line
|
61
92
|
lines << line
|
62
93
|
line = []
|
63
94
|
cursor = 0
|
64
95
|
when "\r"
|
96
|
+
# Returns the writing cursor back to the begining of the line
|
65
97
|
cursor = 0
|
98
|
+
when "\e[G", "\e[0G", "\e[g"
|
99
|
+
# TODO: I have no idea how these characters are supposed to work,
|
100
|
+
# but this seems to be produce nicer results that what currently
|
101
|
+
# gets rendered.
|
102
|
+
cursor = 0
|
103
|
+
when "\e[K", "\e[0K"
|
104
|
+
# erases everything after the cursor
|
105
|
+
line = line.fill(" ", cursor..line.length)
|
106
|
+
when "\e[1K"
|
107
|
+
# erases everything before the cursor
|
108
|
+
line = line.fill(" ", 0..cursor)
|
109
|
+
when "\e[2K"
|
110
|
+
# erase entire line
|
111
|
+
line = Array.new(line.length, " ")
|
66
112
|
when "\b"
|
67
113
|
pointer = cursor-1
|
68
114
|
|
@@ -79,6 +125,13 @@ module Terminal
|
|
79
125
|
|
80
126
|
pointer -= 1
|
81
127
|
end
|
128
|
+
when /\e\[(\d+)D/
|
129
|
+
backwards = $1.to_i
|
130
|
+
|
131
|
+
new_position = cursor - backwards
|
132
|
+
new_position = 0 if new_position < 0
|
133
|
+
|
134
|
+
cursor = new_position
|
82
135
|
when /\A\e\[(.*)m\z/
|
83
136
|
color_code = $1.to_s
|
84
137
|
|
data/lib/terminal/version.rb
CHANGED
@@ -49,5 +49,47 @@ describe Terminal::Renderer do
|
|
49
49
|
|
50
50
|
expect(renderer.render(raw)).to eql("<span class='c81'>hello\n \nfriend</span>")
|
51
51
|
end
|
52
|
+
|
53
|
+
it "allows you to control the cursor backwards" do
|
54
|
+
raw = "this is good\e[4Dpoop and stuff"
|
55
|
+
|
56
|
+
expect(renderer.render(raw)).to eql("this is poop and stuff")
|
57
|
+
end
|
58
|
+
|
59
|
+
it "doesn't blow up if you go back too many characters" do
|
60
|
+
raw = "this is good\e[100Dpoop and stuff"
|
61
|
+
|
62
|
+
expect(renderer.render(raw)).to eql("poop and stuff")
|
63
|
+
end
|
64
|
+
|
65
|
+
it "ignores \\e1[K" do
|
66
|
+
raw = "hello friend\e[K!"
|
67
|
+
|
68
|
+
expect(renderer.render(raw)).to eql("hello friend!")
|
69
|
+
end
|
70
|
+
|
71
|
+
it "ignores \\e1[0K" do
|
72
|
+
raw = "hello friend\e[0K!"
|
73
|
+
|
74
|
+
expect(renderer.render(raw)).to eql("hello friend!")
|
75
|
+
end
|
76
|
+
|
77
|
+
it "handles \\e[0G ghetto style" do
|
78
|
+
raw = "hello friend\e[Ggoodbye buddy!"
|
79
|
+
|
80
|
+
expect(renderer.render(raw)).to eql("goodbye buddy!")
|
81
|
+
end
|
82
|
+
|
83
|
+
it "allows erasing the current line up to a point" do
|
84
|
+
raw = "hello friend\e[1K!"
|
85
|
+
|
86
|
+
expect(renderer.render(raw)).to eql(" !")
|
87
|
+
end
|
88
|
+
|
89
|
+
it "allows clearing of the current line" do
|
90
|
+
raw = "hello friend\e[2K!"
|
91
|
+
|
92
|
+
expect(renderer.render(raw)).to eql(" !")
|
93
|
+
end
|
52
94
|
end
|
53
95
|
end
|
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.2'
|
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-28 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: escape_utils
|