terminal 1.0.2 → 2.0.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 7d9969578830c35e3587d7eb183a5ddca80faf78
4
- data.tar.gz: 9c18bf8cc1e40b0b02a50d153291ddd678cce02e
3
+ metadata.gz: b8ff0192c84e2fe3da5e33be6c1e7c0e8abded70
4
+ data.tar.gz: 4b5dafa0764496c4810b0d505e3c55dfe6076e2f
5
5
  SHA512:
6
- metadata.gz: f84f5c8f4b3a26e5ca5c49d05d78ffdc99879e2e3087494f140054bfcac10f76b8c34ec3458a94161a0ebaed6504b09f31a8caa5e92718582a8bea1cb72a4db2
7
- data.tar.gz: 7897b30eb970b80ec2cd72c212ef190eeb538f2c023b629e671168078f8dfab9f0e72ef6a665d531a8f1314efcaf32311a2e4526b8f1381c5b8df783e457d86d
6
+ metadata.gz: 1136373e0556d6a0bbde37f1e4630c89a38d3dd470fa59151bc5048fc37b2234e999c21432f7b6b3245b47cda146b7bef70cae08a23e4492828ea34cb1cab695
7
+ data.tar.gz: 1038c20539c1a2c6574b5facfe98903ae9dffdf4c0789d02e34c148bd3d5e26407893467158ac2304900708e910f068c347a4108628d0e042d6c192f7fc2d3f7
@@ -1,9 +1,8 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- terminal (1.0.2)
4
+ terminal (2.0.0)
5
5
  escape_utils (~> 1.0)
6
- gemoji (~> 2.1)
7
6
 
8
7
  GEM
9
8
  remote: https://rubygems.org/
@@ -11,7 +10,6 @@ GEM
11
10
  benchmark-ips (2.1.1)
12
11
  diff-lcs (1.2.5)
13
12
  escape_utils (1.0.1)
14
- gemoji (2.1.0)
15
13
  hirb (0.7.3)
16
14
  memory_profiler (0.0.4)
17
15
  method_profiler (2.0.1)
data/Readme.md CHANGED
@@ -51,15 +51,6 @@ Now in your views:
51
51
  <div class="term-container"><%= Terminal.render(output) %></div>
52
52
  ```
53
53
 
54
- ### Emojis :+1:
55
-
56
- Terminal converts unicode to proper `<img>` tags. We use the [gemoji](https://github.com/github/gemoji)
57
- gem to do this. The path to the assets can be customized by passing the `:emoji_asset_path` option to `Terminal.render`
58
-
59
- ```ruby
60
- Terminal.render(output, emoji_asset_path: "https://your.cdn.com/images/emoji")
61
- ```
62
-
63
54
  ### Command Line
64
55
 
65
56
  Terminal ships with a command line utility. For example, you can pipe `rspec` output to it:
@@ -6,8 +6,7 @@ $:.unshift(File.join(File.expand_path(File.dirname(__FILE__)), '..', 'lib'))
6
6
  require 'terminal'
7
7
  require 'optparse'
8
8
 
9
- options = Struct.new(:preview,
10
- :emoji_asset_path).new
9
+ options = Struct.new(:preview).new
11
10
 
12
11
  option_parser = OptionParser.new do |opts|
13
12
  opts.banner = "Usage: #{opts.program_name} [options] <input file>"
@@ -16,10 +15,6 @@ option_parser = OptionParser.new do |opts|
16
15
  options.preview = true
17
16
  end
18
17
 
19
- opts.on("--emoji-asset-path=PATH", "Path or URL to emoji image files") do |path|
20
- options.emoji_asset_path = path
21
- end
22
-
23
18
  opts.on_tail("-h", "--help", "Show this help documentation") do
24
19
  puts opts
25
20
  exit
@@ -36,7 +31,7 @@ if ($stdin.tty? && ARGV.empty?)
36
31
  end
37
32
 
38
33
  raw = ARGF.read
39
- rendered = Terminal.render(raw, emoji_asset_path: options[:emoji_asset_path])
34
+ rendered = Terminal.render(raw)
40
35
 
41
36
  if options[:preview]
42
37
  require 'tempfile'
@@ -1,16 +1,12 @@
1
1
  # encoding: UTF-8
2
2
 
3
3
  require 'escape_utils'
4
- require 'emoji'
5
4
  require 'strscan'
6
5
 
7
6
  module Terminal
8
7
  class Renderer
9
8
  MEGABYTES = 1024 * 1024
10
9
 
11
- EMOJI_UNICODE_REGEXP = /[\u{1f600}-\u{1f64f}]|[\u{2702}-\u{27b0}]|[\u{1f680}-\u{1f6ff}]|[\u{24C2}-\u{1F251}]|[\u{1f300}-\u{1f5ff}]/
12
- EMOJI_IGNORE = [ "heavy_check_mark".freeze, "heavy_multiplication_x".freeze ]
13
-
14
10
  ESCAPE_CONTROL_CHARACTERS = "qQmKGgKAaBbCcDd".freeze
15
11
  ESCAPE_CAPTURE_REGEX = /\e\[(.*)([#{ESCAPE_CONTROL_CHARACTERS}])/
16
12
 
@@ -18,23 +14,15 @@ module Terminal
18
14
 
19
15
  def initialize(output, options = {})
20
16
  @output = output
21
-
22
17
  @options = options
23
- @options[:emoji_asset_path] ||= "/assets/emojis"
24
-
25
18
  @screen = Screen.new
26
19
  end
27
20
 
28
21
  def render
29
22
  return "" if @output.nil?
30
23
 
31
- # Don't allow parsing of outputs longer than 4 meg
32
- output = dup_check_and_chomp_length(@output)
24
+ output = @output.dup
33
25
 
34
- # Force encoding on the output first
35
- force_encoding!(output)
36
-
37
- # Now do the render the output to the screen
38
26
  render_to_screen(output)
39
27
 
40
28
  # Convert the screen to a string
@@ -46,36 +34,11 @@ module Terminal
46
34
  # Now convert the colors to HTML
47
35
  convert_to_html!(escaped_html)
48
36
 
49
- # And emojify
50
- replace_unicode_with_emoji!(escaped_html)
51
-
52
37
  escaped_html
53
38
  end
54
39
 
55
40
  private
56
41
 
57
- def dup_check_and_chomp_length(output)
58
- # Limit the entire size of the output to 4 meg
59
- max_total_size = 4 * MEGABYTES
60
- if output.bytesize > max_total_size
61
- new_output = output.byteslice(0, max_total_size)
62
- new_output << "\n\nWarning: Terminal has chopped off the rest of the build as it's over the allowed 4 megabyte limit for logs."
63
- new_output
64
- else
65
- output.dup
66
- end
67
- end
68
-
69
- def force_encoding!(string)
70
- string.force_encoding('UTF-8')
71
-
72
- if string.valid_encoding?
73
- string
74
- else
75
- string.force_encoding('ASCII-8BIT').encode!('UTF-8', invalid: :replace, undef: :replace)
76
- end
77
- end
78
-
79
42
  def render_to_screen(string)
80
43
  scanner = StringScanner.new(string)
81
44
 
@@ -147,27 +110,5 @@ module Terminal
147
110
  # Replace empty lines with a non breaking space.
148
111
  string.gsub!(/$^/, "&nbsp;")
149
112
  end
150
-
151
- def replace_unicode_with_emoji!(string)
152
- string.gsub!(EMOJI_UNICODE_REGEXP) do |match|
153
- Terminal::Cache.cache(:emoji, match) { emoji_image_from_unicode(match) }
154
- end
155
- end
156
-
157
- # The Emoji API will be transitioning to a nil-based find API, at the
158
- # moment it raies exceptions for Emojis that can't be found:
159
- # https://github.com/github/gemoji/commit/b1736a387c7c1c2af300506fea5603e2e1fb89d8
160
- # Will support both for now.
161
- def emoji_image_from_unicode(unicode)
162
- emoji = Emoji.find_by_unicode(unicode)
163
-
164
- if emoji && !EMOJI_IGNORE.include?(emoji.name)
165
- path = File.join(@options[:emoji_asset_path], emoji.image_filename)
166
-
167
- %(<img alt="#{emoji.name}" title="#{emoji.name}" src="#{path}" class="emoji" width="20" height="20" />)
168
- else
169
- unicode
170
- end
171
- end
172
113
  end
173
114
  end
@@ -1,3 +1,3 @@
1
1
  module Terminal
2
- VERSION = "1.0.2"
2
+ VERSION = "2.0.0"
3
3
  end
@@ -20,13 +20,6 @@ describe Terminal::Renderer do
20
20
  end
21
21
 
22
22
  describe "#render" do
23
- it "chops off logs longer than 4 megabytes" do
24
- long_string = "x" * 5 * 1024 * 1024
25
- last_part_of_long_string = render(long_string).split("").last(1000).join("")
26
-
27
- expect(last_part_of_long_string).to end_with("Warning: Terminal has chopped off the rest of the build as it&#39;s over the allowed 4 megabyte limit for logs.")
28
- end
29
-
30
23
  it "closes colors that get opened" do
31
24
  raw = "he\033[32mllo"
32
25
 
@@ -196,31 +189,6 @@ describe Terminal::Renderer do
196
189
  expect(render(raw)).to eql("hi amazing \e[12 nom nom nom friends")
197
190
  end
198
191
 
199
- it "renders unicode emoji" do
200
- raw = "this is great 👍"
201
-
202
- expect(render(raw)).to eql(%{this is great <img alt="+1" title="+1" src="/assets/emojis/unicode/1f44d.png" class="emoji" width="20" height="20" />})
203
- end
204
-
205
- it "returns nothing if the unicode emoji can't be found" do
206
- expect(Emoji).to receive(:unicodes_index) { {} }
207
- raw = "this is great 😎"
208
-
209
- expect(render(raw)).to eql(%{this is great 😎})
210
- end
211
-
212
- it "leaves the tick emoji alone (it looks better and is colored)" do
213
- raw = "works ✔"
214
-
215
- expect(render(raw)).to eql(%{works ✔})
216
- end
217
-
218
- it "leaves the ✖ emoji alone as well" do
219
- raw = "broke ✖"
220
-
221
- expect(render(raw)).to eql(%{broke ✖})
222
- end
223
-
224
192
  it "handles colors with 3 attributes" do
225
193
  raw = "\e[0;10;4m\e[1m\e[34mgood news\e[0;10m\n\neveryone"
226
194
 
@@ -19,7 +19,6 @@ Gem::Specification.new do |spec|
19
19
  spec.require_paths = ["lib"]
20
20
 
21
21
  spec.add_dependency "escape_utils", "~> 1.0"
22
- spec.add_dependency "gemoji", "~> 2.1"
23
22
 
24
23
  spec.add_development_dependency "bundler", "~> 1.6"
25
24
  spec.add_development_dependency "rake"
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: 1.0.2
4
+ version: 2.0.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Keith Pitt
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-02-22 00:00:00.000000000 Z
11
+ date: 2015-02-23 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: escape_utils
@@ -24,20 +24,6 @@ dependencies:
24
24
  - - "~>"
25
25
  - !ruby/object:Gem::Version
26
26
  version: '1.0'
27
- - !ruby/object:Gem::Dependency
28
- name: gemoji
29
- requirement: !ruby/object:Gem::Requirement
30
- requirements:
31
- - - "~>"
32
- - !ruby/object:Gem::Version
33
- version: '2.1'
34
- type: :runtime
35
- prerelease: false
36
- version_requirements: !ruby/object:Gem::Requirement
37
- requirements:
38
- - - "~>"
39
- - !ruby/object:Gem::Version
40
- version: '2.1'
41
27
  - !ruby/object:Gem::Dependency
42
28
  name: bundler
43
29
  requirement: !ruby/object:Gem::Requirement