iterm2-viewer 0.0.4 → 0.0.5
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.travis.yml +11 -0
- data/Gemfile +5 -0
- data/README.md +12 -4
- data/Rakefile +8 -1
- data/bin/iterm2-viewer +4 -1
- data/lib/iterm2/viewer/media.rb +57 -0
- data/lib/iterm2/viewer/render.rb +14 -0
- data/lib/iterm2/viewer/version.rb +1 -1
- data/test/coverage/.last_run.json +5 -0
- data/test/coverage/.resultset.json +7 -0
- data/test/coverage/.resultset.json.lock +0 -0
- data/test/lib/iterm2/viewer/test_media.rb +13 -0
- data/test/lib/iterm2/viewer/test_render.rb +21 -0
- data/test/lib/iterm2/viewer/test_version.rb +7 -0
- data/test/test_helper.rb +8 -0
- metadata +19 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: e669b5969e6184f423ac372b5fc2dec5d8a29f40
|
4
|
+
data.tar.gz: ce0019766d06fc9b4f263ed531033e252268df0c
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 3645f7d37581fd296342db543c593b2d31e6787b3894951db07097657167ef454a11f37ae3449bb514b1cdecd649a6ebc493410dd8d1c1f49f4be45e7d49556b
|
7
|
+
data.tar.gz: 56e3b46fd2d1455445f6d0179e2679f4b6dd89f5db3abe42b56751143d3130f628c3b01b250c9bf47476d591482922983b32da6b44921d952174b36d582d31d6
|
data/.travis.yml
ADDED
data/Gemfile
CHANGED
data/README.md
CHANGED
@@ -1,11 +1,19 @@
|
|
1
1
|
[![Code Climate](https://codeclimate.com/github/AndreyAntipov/iterm2-viewer/badges/gpa.svg)](https://codeclimate.com/github/AndreyAntipov/iterm2-viewer)
|
2
2
|
[![Dependency Status](https://gemnasium.com/AndreyAntipov/iterm2-viewer.svg)](https://gemnasium.com/AndreyAntipov/iterm2-viewer)
|
3
3
|
[![Gem Version](https://badge.fury.io/rb/iterm2-viewer.svg)](http://badge.fury.io/rb/iterm2-viewer)
|
4
|
+
[![Build Status](https://travis-ci.org/AndreyAntipov/iterm2-viewer.svg?branch=master)](https://travis-ci.org/AndreyAntipov/iterm2-viewer)
|
5
|
+
[![Test Coverage](https://codeclimate.com/github/AndreyAntipov/iterm2-viewer/badges/coverage.svg)](https://codeclimate.com/github/AndreyAntipov/iterm2-viewer)
|
4
6
|
|
5
7
|
# iterm2-viewer
|
6
8
|
|
7
9
|
Display media files in terminal. iTerm2-nightly is required
|
8
10
|
|
11
|
+
## Supported types
|
12
|
+
- png
|
13
|
+
- jpeg
|
14
|
+
- tiff
|
15
|
+
- gif
|
16
|
+
|
9
17
|
## Installation
|
10
18
|
|
11
19
|
Add this line to your application's Gemfile:
|
@@ -25,11 +33,11 @@ Or install it yourself as:
|
|
25
33
|
## Usage
|
26
34
|
|
27
35
|
```ruby
|
28
|
-
iterm2-viewer
|
36
|
+
iterm2-viewer IMAGE_FILE_PATH
|
29
37
|
```
|
30
|
-
|
38
|
+
display multiple images
|
31
39
|
```ruby
|
32
|
-
iterm2-viewer
|
40
|
+
iterm2-viewer IMAGE_FILE_1_PATH IMAGE_FILE_2_PATH
|
33
41
|
```
|
34
42
|
---
|
35
43
|
|
@@ -47,7 +55,7 @@ Permission is hereby granted, free of charge, to any person obtaining a copy of
|
|
47
55
|
|
48
56
|
## Contributing
|
49
57
|
|
50
|
-
1. Fork it ( https://github.com/
|
58
|
+
1. Fork it ( https://github.com/AndreyAntipov/iterm2-viewer/fork )
|
51
59
|
2. Create your feature branch (`git checkout -b my-new-feature`)
|
52
60
|
3. Commit your changes (`git commit -am 'Add some feature'`)
|
53
61
|
4. Push to the branch (`git push origin my-new-feature`)
|
data/Rakefile
CHANGED
data/bin/iterm2-viewer
CHANGED
@@ -12,10 +12,13 @@ module Iterm2
|
|
12
12
|
# @param [String, #arguments] routes to files
|
13
13
|
class << self
|
14
14
|
def show(arguments)
|
15
|
+
# show current version
|
16
|
+
puts VERSION if arguments[0].to_s == "--version" || arguments[0].to_s == "-v"
|
17
|
+
|
15
18
|
# initialize whenever application called from iTerm2
|
16
19
|
if ENV['TERM_PROGRAM'] == 'iTerm.app'
|
17
20
|
arguments.each do |route|
|
18
|
-
Render.new
|
21
|
+
Render.new(Media.new route) if File.file? route
|
19
22
|
end
|
20
23
|
end
|
21
24
|
end
|
@@ -0,0 +1,57 @@
|
|
1
|
+
module Iterm2
|
2
|
+
module Viewer
|
3
|
+
# Create a new media object
|
4
|
+
class Media
|
5
|
+
# Dependency
|
6
|
+
require 'mime/types'
|
7
|
+
require 'base64'
|
8
|
+
|
9
|
+
def initialize(object)
|
10
|
+
@mime ||= MIME::Types.of(object).first
|
11
|
+
|
12
|
+
# Raise error an error if file type isn't supported
|
13
|
+
raise TypeError unless renderable?
|
14
|
+
|
15
|
+
@data ||= renderable? ? construct(object) : nil
|
16
|
+
end
|
17
|
+
|
18
|
+
# @return [Symbol] data return base64 string of file
|
19
|
+
attr_reader :data
|
20
|
+
|
21
|
+
# Construct base64 blob from binary
|
22
|
+
# @param [String] file which are need to open
|
23
|
+
# @return [String] base64 data of binary file
|
24
|
+
def construct(object)
|
25
|
+
Base64.encode64(open(object).read)
|
26
|
+
end
|
27
|
+
|
28
|
+
# Helper method.
|
29
|
+
# Detect current kind such as (application, image, document) and so on of selected file
|
30
|
+
# @return [String] current kind of file
|
31
|
+
def kind
|
32
|
+
@mime.media_type.to_sym
|
33
|
+
end
|
34
|
+
|
35
|
+
# Helper method.
|
36
|
+
# Detect current type such as (.png, .pdf, .txt) and so on of se
|
37
|
+
# @return [String] current type of file
|
38
|
+
def type
|
39
|
+
@mime.sub_type
|
40
|
+
end
|
41
|
+
|
42
|
+
# Determine whether type is renderable
|
43
|
+
# @note Renderable Types and MIME's listed below in supported_types method
|
44
|
+
# @return [Boolean]
|
45
|
+
def renderable?
|
46
|
+
supported_types.key?(kind) && supported_types[kind].include?(type)
|
47
|
+
end
|
48
|
+
|
49
|
+
# Renderable types and kinds
|
50
|
+
def supported_types
|
51
|
+
{
|
52
|
+
image: %w(jpeg jpg png tiff gif)
|
53
|
+
}
|
54
|
+
end
|
55
|
+
end
|
56
|
+
end
|
57
|
+
end
|
@@ -0,0 +1,14 @@
|
|
1
|
+
module Iterm2
|
2
|
+
module Viewer
|
3
|
+
# Render new object in terminal
|
4
|
+
# @param object [Iterm2::Viewer::Entity]
|
5
|
+
class Render
|
6
|
+
def initialize(object)
|
7
|
+
raise ArgumentError, "incorrect media file" unless object.is_a? Iterm2::Viewer::Media
|
8
|
+
# @see http://iterm2.com/images.html
|
9
|
+
# @note based on https://raw.githubusercontent.com/gnachman/iTerm2/master/tests/imgcat
|
10
|
+
puts "\033]1337;File=;inline=1:#{object.data}\a\n"
|
11
|
+
end
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
File without changes
|
@@ -0,0 +1,21 @@
|
|
1
|
+
require 'test_helper'
|
2
|
+
|
3
|
+
class Render < Minitest::Test
|
4
|
+
|
5
|
+
def test_that_object_will_not_render_until_argument_isnt_set
|
6
|
+
assert_raises ArgumentError do
|
7
|
+
Render.new
|
8
|
+
end
|
9
|
+
end
|
10
|
+
|
11
|
+
def test_that_object_will_not_rendered_with_wrong_type_of_object
|
12
|
+
assert_raises ArgumentError do
|
13
|
+
Render.new "wrong type of object"
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
def test_that_object_will_render_with_correct_type_of_object
|
18
|
+
skip "this test will pass later"
|
19
|
+
end
|
20
|
+
|
21
|
+
end
|
data/test/test_helper.rb
ADDED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: iterm2-viewer
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.5
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Andrey
|
@@ -257,6 +257,7 @@ extensions: []
|
|
257
257
|
extra_rdoc_files: []
|
258
258
|
files:
|
259
259
|
- ".gitignore"
|
260
|
+
- ".travis.yml"
|
260
261
|
- Gemfile
|
261
262
|
- Guardfile
|
262
263
|
- LICENSE.txt
|
@@ -265,7 +266,16 @@ files:
|
|
265
266
|
- bin/iterm2-viewer
|
266
267
|
- iterm2-viewer.gemspec
|
267
268
|
- lib/iterm2/viewer.rb
|
269
|
+
- lib/iterm2/viewer/media.rb
|
270
|
+
- lib/iterm2/viewer/render.rb
|
268
271
|
- lib/iterm2/viewer/version.rb
|
272
|
+
- test/coverage/.last_run.json
|
273
|
+
- test/coverage/.resultset.json
|
274
|
+
- test/coverage/.resultset.json.lock
|
275
|
+
- test/lib/iterm2/viewer/test_media.rb
|
276
|
+
- test/lib/iterm2/viewer/test_render.rb
|
277
|
+
- test/lib/iterm2/viewer/test_version.rb
|
278
|
+
- test/test_helper.rb
|
269
279
|
homepage: https://github.com/AndreyAntipov/iterm2-viewer
|
270
280
|
licenses:
|
271
281
|
- MIT
|
@@ -290,5 +300,12 @@ rubygems_version: 2.2.2
|
|
290
300
|
signing_key:
|
291
301
|
specification_version: 4
|
292
302
|
summary: Display media files in iTerm2.
|
293
|
-
test_files:
|
303
|
+
test_files:
|
304
|
+
- test/coverage/.last_run.json
|
305
|
+
- test/coverage/.resultset.json
|
306
|
+
- test/coverage/.resultset.json.lock
|
307
|
+
- test/lib/iterm2/viewer/test_media.rb
|
308
|
+
- test/lib/iterm2/viewer/test_render.rb
|
309
|
+
- test/lib/iterm2/viewer/test_version.rb
|
310
|
+
- test/test_helper.rb
|
294
311
|
has_rdoc:
|