iterm2-viewer 0.0.6 → 0.0.7
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 +4 -4
- data/.travis.yml +0 -1
- data/Guardfile +0 -1
- data/Rakefile +2 -1
- data/bin/iterm2-viewer +32 -9
- data/iterm2-viewer.gemspec +1 -1
- data/lib/iterm2/viewer/media.rb +12 -9
- data/lib/iterm2/viewer/render.rb +6 -1
- data/lib/iterm2/viewer/version.rb +1 -1
- data/test/lib/iterm2/viewer/test_media.rb +16 -8
- data/test/lib/iterm2/viewer/test_render.rb +17 -12
- data/test/media/{supported → supported.png} +0 -0
- data/test/media/{unsupported → unsupported.txt} +0 -0
- metadata +6 -6
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 0e417f4367b8b80c7902713896212183aa1e99c9
|
4
|
+
data.tar.gz: 91b35f01b824c186f706177764fd88d4b9dfde6a
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: f7dc4efb0b686d4a762cea57338bb603545095f5c54d8aa80767b872938347008451a4fe0a86c4afa75209b102a818a5c50555611cbe1e879221c6db37203fb2
|
7
|
+
data.tar.gz: d602b0322a57604665cea12f58f36151b80c5f361e549d51e01a8ff6ed73f95db07be2f2c28715d9662d1a05b17d77e2058d00baf7536f5c89a227e146739906
|
data/.travis.yml
CHANGED
data/Guardfile
CHANGED
data/Rakefile
CHANGED
data/bin/iterm2-viewer
CHANGED
@@ -1,30 +1,53 @@
|
|
1
1
|
#!/usr/bin/env ruby
|
2
2
|
# encoding: utf-8
|
3
3
|
|
4
|
+
# Setup patches
|
4
5
|
lib = File.expand_path(File.dirname(__FILE__) + '/../lib')
|
5
6
|
$LOAD_PATH.unshift(lib) if File.directory?(lib) && !$LOAD_PATH.include?(lib)
|
6
7
|
|
7
8
|
require 'iterm2/viewer'
|
8
9
|
|
9
10
|
module Iterm2
|
10
|
-
#
|
11
|
+
# CLI interface for view images in terminal
|
11
12
|
module Viewer
|
12
|
-
#
|
13
|
+
# Common methods
|
13
14
|
# @param [String, #arguments] routes to files
|
15
|
+
# @todo write tests
|
14
16
|
class << self
|
15
17
|
def show(arguments)
|
16
|
-
# initialize whenever application called from iTerm2
|
17
|
-
return unless ENV['TERM_PROGRAM'] == 'iTerm.app'
|
18
|
+
# initialize whenever application called from iTerm2 with arguments
|
19
|
+
return unless ENV['TERM_PROGRAM'] == 'iTerm.app' || arguments.nil?
|
18
20
|
|
19
|
-
#
|
20
|
-
|
21
|
+
# catch options
|
22
|
+
if arguments[0] =~ /^(-\w|--\w{2,}?)$/
|
23
|
+
# @todo refactoring
|
24
|
+
# @todo add notification — command not found
|
25
|
+
version if arguments[0].to_s == '--version' || arguments[0].to_s == '-v'
|
26
|
+
# switch to renders
|
27
|
+
else
|
28
|
+
# clean entire screen
|
29
|
+
# todo: optimize (fit to enitre screen)
|
30
|
+
print "\e[2J\e[f"
|
21
31
|
|
22
|
-
|
23
|
-
|
32
|
+
# reveal media files
|
33
|
+
arguments.each do |route|
|
34
|
+
begin
|
35
|
+
Render.new(Media.new route).reveal
|
36
|
+
# skip incorrect routes
|
37
|
+
rescue ArgumentError
|
38
|
+
next
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|
24
42
|
end
|
43
|
+
|
44
|
+
def version
|
45
|
+
abort VERSION
|
46
|
+
end
|
47
|
+
|
25
48
|
end
|
26
49
|
end
|
27
50
|
end
|
28
51
|
|
29
|
-
# Run application with shell
|
52
|
+
# Run application with shell arguments
|
30
53
|
Iterm2::Viewer.show ARGV
|
data/iterm2-viewer.gemspec
CHANGED
@@ -14,7 +14,7 @@ Gem::Specification.new do |spec|
|
|
14
14
|
spec.homepage = 'https://github.com/AndreyAntipov/iterm2-viewer'
|
15
15
|
spec.license = 'MIT'
|
16
16
|
|
17
|
-
spec.files = `git ls-files
|
17
|
+
spec.files = `git ls-files`.split($/)
|
18
18
|
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
19
19
|
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
20
20
|
spec.require_paths = ['lib']
|
data/lib/iterm2/viewer/media.rb
CHANGED
@@ -1,26 +1,29 @@
|
|
1
1
|
module Iterm2
|
2
2
|
module Viewer
|
3
3
|
# Create a new media object
|
4
|
-
class Media
|
4
|
+
class Media < String
|
5
5
|
# Dependency
|
6
6
|
require 'mime/types'
|
7
7
|
require 'base64'
|
8
8
|
|
9
9
|
# Validate and construct media object
|
10
10
|
#
|
11
|
-
# @param object [String]
|
11
|
+
# @param object [String] need to prepare to render
|
12
12
|
def initialize(object)
|
13
|
+
|
14
|
+
# Raise error if file doesn't exist
|
15
|
+
fail ArgumentError, 'file doesn\'t exist' unless File.file? object
|
16
|
+
|
17
|
+
# Get file MIME
|
13
18
|
@mime ||= MIME::Types.of(object).first
|
14
19
|
|
15
|
-
# Raise error
|
16
|
-
fail TypeError unless renderable?
|
20
|
+
# Raise error if file type isn't supported
|
21
|
+
fail TypeError, 'file type isn\'t supported' unless renderable?
|
17
22
|
|
18
|
-
|
23
|
+
# construct object and inject blob into parent class
|
24
|
+
super(construct object)
|
19
25
|
end
|
20
26
|
|
21
|
-
# @return [Symbol] data return base64 string of file
|
22
|
-
attr_reader :data
|
23
|
-
|
24
27
|
# Construct base64 blob from binary
|
25
28
|
#
|
26
29
|
# @param object [String] file path which are need to open
|
@@ -38,7 +41,7 @@ module Iterm2
|
|
38
41
|
end
|
39
42
|
|
40
43
|
# Helper method.
|
41
|
-
# Detect current type such as (.png, .pdf, .txt)
|
44
|
+
# Detect current type such as (.png, .pdf, .txt)
|
42
45
|
#
|
43
46
|
# @return [String] current type of file
|
44
47
|
def type
|
data/lib/iterm2/viewer/render.rb
CHANGED
@@ -5,9 +5,14 @@ module Iterm2
|
|
5
5
|
class Render
|
6
6
|
def initialize(object)
|
7
7
|
fail ArgumentError, 'incorrect media file' unless object.is_a? Iterm2::Viewer::Media
|
8
|
+
@data ||= object
|
9
|
+
end
|
10
|
+
|
11
|
+
# Display media file
|
12
|
+
def reveal
|
8
13
|
# @see http://iterm2.com/images.html
|
9
14
|
# @note https://raw.githubusercontent.com/gnachman/iTerm2/master/tests/imgcat
|
10
|
-
puts "\033]1337;File=;inline=1:#{
|
15
|
+
puts "\033]1337;File=;inline=1:#{@data}\a\n"
|
11
16
|
end
|
12
17
|
end
|
13
18
|
end
|
@@ -1,12 +1,20 @@
|
|
1
1
|
require 'test_helper'
|
2
2
|
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
3
|
+
describe Iterm2::Viewer::Media do
|
4
|
+
it 'media will not be created without route argument' do
|
5
|
+
assert_raises ArgumentError do
|
6
|
+
Iterm2::Viewer::Media.new
|
7
|
+
end
|
8
|
+
end
|
8
9
|
|
9
|
-
|
10
|
-
|
11
|
-
|
10
|
+
it 'media will not be created with incorrect route argument' do
|
11
|
+
assert_raises ArgumentError do
|
12
|
+
Iterm2::Viewer::Media.new 'String'
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
16
|
+
it 'media will be created if route and mime argument is correct' do
|
17
|
+
file = File.absolute_path(__dir__ + '/../../../media/supported.png')
|
18
|
+
Iterm2::Viewer::Media.new(file).wont_be_empty
|
19
|
+
end
|
12
20
|
end
|
@@ -1,18 +1,23 @@
|
|
1
1
|
require 'test_helper'
|
2
2
|
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
3
|
+
|
4
|
+
describe Iterm2::Viewer::Render do
|
5
|
+
it 'renderer will not be created without media object as argument' do
|
6
|
+
assert_raises ArgumentError do
|
7
|
+
Iterm2::Viewer::Render.new
|
8
|
+
end
|
9
|
+
end
|
10
|
+
|
11
|
+
it 'renderer will not be initialized with incorrect object argument' do
|
12
|
+
assert_raises ArgumentError do
|
13
|
+
Iterm2::Viewer::Render.new 'String'
|
14
|
+
end
|
8
15
|
end
|
9
|
-
end
|
10
16
|
|
11
|
-
|
12
|
-
|
13
|
-
|
17
|
+
it 'render will be initialized if object type will be correct' do
|
18
|
+
file = File.absolute_path(__dir__ + '/../../../media/supported.png')
|
19
|
+
media = Iterm2::Viewer::Media.new(file)
|
14
20
|
|
15
|
-
|
16
|
-
|
17
|
-
end
|
21
|
+
Iterm2::Viewer::Render.new(media).wont_be_nil
|
22
|
+
end
|
18
23
|
end
|
File without changes
|
File without changes
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
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.7
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Andrey Antipov
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-11-
|
11
|
+
date: 2014-11-23 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -277,8 +277,8 @@ files:
|
|
277
277
|
- test/lib/iterm2/viewer/test_media.rb
|
278
278
|
- test/lib/iterm2/viewer/test_render.rb
|
279
279
|
- test/lib/iterm2/viewer/test_version.rb
|
280
|
-
- test/media/supported
|
281
|
-
- test/media/unsupported
|
280
|
+
- test/media/supported.png
|
281
|
+
- test/media/unsupported.txt
|
282
282
|
- test/test_helper.rb
|
283
283
|
homepage: https://github.com/AndreyAntipov/iterm2-viewer
|
284
284
|
licenses:
|
@@ -308,7 +308,7 @@ test_files:
|
|
308
308
|
- test/lib/iterm2/viewer/test_media.rb
|
309
309
|
- test/lib/iterm2/viewer/test_render.rb
|
310
310
|
- test/lib/iterm2/viewer/test_version.rb
|
311
|
-
- test/media/supported
|
312
|
-
- test/media/unsupported
|
311
|
+
- test/media/supported.png
|
312
|
+
- test/media/unsupported.txt
|
313
313
|
- test/test_helper.rb
|
314
314
|
has_rdoc:
|