terminal 0.3.beta1 → 0.3

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: a4b4dd150fe6a6cfcad302893bdd602885b6dffd
4
- data.tar.gz: f2caa188722eca09b14e8f404ff96b837b6b9652
3
+ metadata.gz: b7b151475b60fc04b00cc33d7aa7b5248d3b3cbc
4
+ data.tar.gz: 9f6f38830a8df2fbd617dac67c18d8c363eb2c35
5
5
  SHA512:
6
- metadata.gz: c658ae729a6ef14725497173d11eb8169aaaa0f04387e8a84a32c0461447a805b6d08cbb5b71a1f6fd78292d841ee4b30f0f54f853fbd36aa83f6d4fa8929634
7
- data.tar.gz: 35e07c07b55db481be848513ee9838d529e8dfc12e7b5b22d44da79078994284e9f039c4704e788dc965bd0a47e5de5ba012192a9c2298506f0dc7934b562401
6
+ metadata.gz: 742af5d46b76221b4555dc0ce42c44bdf68cc35367cd164f682aec455888b19f87a40afe195e1fe7abe310ce8750570646d389ecc44771394abff6dad1c7f7f0
7
+ data.tar.gz: e33305bb8f16ffc673e48dcf4c90393727c27fd19e1832e174823573b6b07e15dcb0b58d1b4e64a2cfd2e28ad00ae29df8627e46d71e72eba6c0e97efe8f35cf
@@ -1,8 +1,9 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- terminal (0.2)
4
+ terminal (0.3)
5
5
  escape_utils (~> 1.0)
6
+ gemoji (~> 2.0)
6
7
 
7
8
  GEM
8
9
  remote: https://rubygems.org/
@@ -10,6 +11,7 @@ GEM
10
11
  benchmark-ips (2.0.0)
11
12
  diff-lcs (1.2.5)
12
13
  escape_utils (1.0.1)
14
+ gemoji (2.0.0)
13
15
  hirb (0.7.2)
14
16
  method_profiler (2.0.1)
15
17
  hirb (>= 0.6.0)
data/Readme.md CHANGED
@@ -30,6 +30,36 @@ gem install terminal
30
30
  Terminal.render("...")
31
31
  ```
32
32
 
33
+ ### Rails Integration
34
+
35
+ You can use Terminal directly within your Ruby on Rails application. First require the gem
36
+ in your Gemfile:
37
+
38
+ ```ruby
39
+ gem "terminal"
40
+ ```
41
+
42
+ Then in your `app/assets/application.css` file:
43
+
44
+ ```css
45
+ /* require "terminal" */
46
+ ```
47
+
48
+ Now in your views:
49
+
50
+ ```
51
+ <div class="code"><%= Terminal.render(output)</div>
52
+ ```
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
+
33
63
  ### Command Line
34
64
 
35
65
  Terminal ships with a command line utility. For example, you can pipe `rspec` output to it:
@@ -5,10 +5,10 @@
5
5
  .term-fg34 { color: #8db7e0; } /* blue */
6
6
  .term-fg35 { color: #ceacde; } /* magenta */
7
7
  .term-fg36 { color: #00cdd9; } /* cyan */
8
- .term-fg90 { color: #838887; } /* grey */
9
8
 
10
9
  /* high intense colors */
11
10
  .term-fgi1 { color: #5ef765; }
11
+ .term-fgi90 { color: #838887; } /* grey */
12
12
 
13
13
  /* background colors */
14
14
  .term-bg42 { background: #99ff5f; }
@@ -6,7 +6,7 @@ require "terminal/preview"
6
6
  require "terminal/engine" if defined?(Rails)
7
7
 
8
8
  module Terminal
9
- def self.render(output)
10
- Terminal::Renderer.new(output).render
9
+ def self.render(output, options = {})
10
+ Terminal::Renderer.new(output, options).render
11
11
  end
12
12
  end
@@ -1,12 +1,18 @@
1
1
  require 'escape_utils'
2
+ require 'emoji'
2
3
 
3
4
  module Terminal
4
5
  class Renderer
6
+ EMOJI_UNICODE_REGEXP = /[\u{1f600}-\u{1f64f}]|[\u{2702}-\u{27b0}]|[\u{1f680}-\u{1f6ff}]|[\u{24C2}-\u{1F251}]|[\u{1f300}-\u{1f5ff}]/
5
7
  ESCAPE_CONTROL_CHARACTERS = "qQmKGgKAaBbCcDd"
6
8
  MEGABYTES = 1024 * 1024
7
9
 
8
- def initialize(output)
10
+ def initialize(output, options = {})
9
11
  @output = output
12
+
13
+ @options = options
14
+ @options[:emoji_asset_path] ||= "/assets/emojis"
15
+
10
16
  @screen = Screen.new
11
17
  end
12
18
 
@@ -49,7 +55,10 @@ module Terminal
49
55
  output = escape_html(output)
50
56
 
51
57
  # Now convert the colors to HTML
52
- convert_to_html(output)
58
+ output = convert_to_html(output)
59
+
60
+ # And emojify
61
+ replace_unicode_with_emoji(output)
53
62
  end
54
63
 
55
64
  private
@@ -156,5 +165,24 @@ module Terminal
156
165
  def split_by_escape_character(string)
157
166
  string.scan(/[\n\r\b]|\e\[[\d;]*[#{ESCAPE_CONTROL_CHARACTERS}]|./)
158
167
  end
168
+
169
+ def replace_unicode_with_emoji(string)
170
+ string.gsub(EMOJI_UNICODE_REGEXP) do |match|
171
+ emoji_image_from_unicode(match)
172
+ end
173
+ end
174
+
175
+ def emoji_image_from_unicode(unicode)
176
+ emoji = Emoji.find_by_unicode(unicode)
177
+
178
+ if emoji
179
+ name = ":#{emoji.name}:"
180
+ path = File.join(@options[:emoji_asset_path], emoji.image_filename)
181
+
182
+ %(<img alt="#{name}" title="#{name}" src="#{path}" class="emoji" width="20" height="20" />)
183
+ else
184
+ unicode
185
+ end
186
+ end
159
187
  end
160
188
  end
@@ -1,3 +1,3 @@
1
1
  module Terminal
2
- VERSION = "0.3.beta1"
2
+ VERSION = "0.3"
3
3
  end
@@ -1,3 +1,5 @@
1
+ # encoding: UTF-8
2
+
1
3
  require 'spec_helper'
2
4
 
3
5
  describe Terminal::Renderer do
@@ -192,6 +194,12 @@ describe Terminal::Renderer do
192
194
 
193
195
  expect(render(raw)).to eql("hi amazing \e[12 nom nom nom friends")
194
196
  end
197
+
198
+ it "renders unicode emoji" do
199
+ raw = "this is great 👍"
200
+
201
+ 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" />})
202
+ end
195
203
  end
196
204
 
197
205
  private
@@ -1,3 +1,5 @@
1
+ # encoding: UTF-8
2
+
1
3
  require 'spec_helper'
2
4
 
3
5
  describe Terminal::Screen do
@@ -19,6 +19,7 @@ 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.0"
22
23
 
23
24
  spec.add_development_dependency "bundler", "~> 1.6"
24
25
  spec.add_development_dependency "rake"
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.3.beta1
4
+ version: '0.3'
5
5
  platform: ruby
6
6
  authors:
7
7
  - Keith Pitt
@@ -24,6 +24,20 @@ 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.0'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '2.0'
27
41
  - !ruby/object:Gem::Dependency
28
42
  name: bundler
29
43
  requirement: !ruby/object:Gem::Requirement
@@ -155,9 +169,9 @@ required_ruby_version: !ruby/object:Gem::Requirement
155
169
  version: '0'
156
170
  required_rubygems_version: !ruby/object:Gem::Requirement
157
171
  requirements:
158
- - - ">"
172
+ - - ">="
159
173
  - !ruby/object:Gem::Version
160
- version: 1.3.1
174
+ version: '0'
161
175
  requirements: []
162
176
  rubyforge_project:
163
177
  rubygems_version: 2.3.0