terminal 0.0.1.alpha.3 → 0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: a2a0074192ba83af5ba05e56242ba68423254d87
4
- data.tar.gz: df0a7b8db3e1db4dd26b95f4b13fbc9bfba55019
3
+ metadata.gz: d516a6b1b58bab0cc47218e13a03e77ad2cf00e0
4
+ data.tar.gz: 5cbcd3804c846cc919e4e5c3cb043fd8a4239164
5
5
  SHA512:
6
- metadata.gz: 834c6b10127a1c3f040f0a611b8da5276e546f6b2b83b3d9b38f7dd7add2bd7ee05d804aee29426a345db8a36ac3ae610a4a37fa9229feb03e81f5a017f964f8
7
- data.tar.gz: b93a742431b08e4af2087e19903e0f97840056cdf939746ee6755575230a7be639a3821932cf6be22332d4b118d96367979f156a717fa303b71ba3b2add29ffa
6
+ metadata.gz: 2972ffd87796ed75c73ed8f72e54864c0d6d092c5d658ea0b36f58f8c1fb90251867c786977e8e2916df83398d2b3dddaac6f24f352e192dc7b1aa979887eb42
7
+ data.tar.gz: 00807d190ecb2c6c194e6bad44700e60591e5eb00e6b23277b734d8dafe600132341063afddc5c8823f96fc0a41cb59fe25a02412c505b58259506ab838aafd6
data/.gitignore CHANGED
@@ -3,7 +3,6 @@
3
3
  .bundle
4
4
  .config
5
5
  .yardoc
6
- Gemfile.lock
7
6
  InstalledFiles
8
7
  _yardoc
9
8
  coverage
@@ -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.png)
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 takes any arbitrary crazy shell output (ASCII), and turns it into beautifully rendered HTML.
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
 
@@ -13,6 +13,9 @@ Usage:
13
13
  Help:
14
14
  $ terminal -h
15
15
 
16
+ Preview in the browser:
17
+ $ terminal --preview
18
+
16
19
  See https://buildboxhq.github.io/terminal for more information.
17
20
  usage
18
21
  end
@@ -0,0 +1,5 @@
1
+ #!/bin/bash
2
+
3
+ ASCII=`cat homer.txt`
4
+
5
+ echo -e "\033[33m$ASCII\033[0m"
@@ -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<-
@@ -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|[^\n\r\b\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 > 0
72
+ while pointer >= 0
72
73
  char_at_pointer = line[pointer]
73
- break unless char_at_pointer.kind_of?(Terminal::Color)
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
- cursor -= (cursor - pointer)
79
- when "\e"
80
- # Seek the next few characters to tell if theres a color present
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
- index += 3 + color_code.length
105
- cursor += 1
89
+ colors_opened = 0
90
+ else
91
+ line[cursor] = Terminal::Color.new(color_code)
106
92
 
107
- next
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("")
@@ -6,7 +6,7 @@
6
6
  background: #171717;
7
7
  border-radius: 5px;
8
8
  color: white;
9
- padding: 30px;
9
+ padding: 15px;
10
10
  margin-bottom: 15px;
11
11
  word-break: break-word;
12
12
  white-space: pre-wrap;
@@ -1,3 +1,3 @@
1
1
  module Terminal
2
- VERSION = "0.0.1.alpha.3"
2
+ VERSION = "0.1"
3
3
  end
@@ -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<-
@@ -0,0 +1,18 @@
1
+ <span class='c33'> ___ _____
2
+ .&#39;&#47;,-Y&quot; &quot;~-.
3
+ l.Y ^.
4
+ &#47;\ _\_
5
+ i ___&#47;&quot; &quot;\
6
+ | &#47;&quot; &quot;\ o !
7
+ l ] o !__.&#47;
8
+ \ _ _ \.___.&#47; &quot;~\
9
+ X \&#47; \ ___.&#47;
10
+ ( \ ___. _..--~~&quot; ~`-.
11
+ ` Z,-- &#47; \
12
+ \__. ( &#47; ______)
13
+ \ l &#47;-----~~&quot; &#47;
14
+ Y \ &#47;
15
+ | &quot;x______.^
16
+ | \
17
+ j Y
18
+ -&gt;Homer&lt;-</span>
@@ -3,22 +3,14 @@ Bundler.setup
3
3
 
4
4
  require 'terminal'
5
5
 
6
- class Fixture
7
- def self.path
8
- File.join(File.expand_path(File.dirname(__FILE__)), 'fixtures')
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
- 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
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 "#render" do
15
- let(:hello_output) { "he\e[81mllo" }
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\e[81mllo"
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 "backspaces colors" do
24
- raw = "he\e[81m\e[90m\bllo"
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("hello")
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.0.1.alpha.3
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-09 00:00:00.000000000 Z
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: 1.3.1
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