iterm2-viewer 0.0.1 → 0.0.2
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/.gitignore +1 -0
- data/bin/iterm2-viewer +111 -0
- data/lib/iterm2/viewer/version.rb +1 -1
- metadata +4 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 6d63bfeab1ba076032eca30e3f2a884292e7fbc6
|
4
|
+
data.tar.gz: 4642bcdfc73f99e8fbdfd853535f51b8c6ae247a
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 303ec9563abcbedb0c7a0efe484600646e9aea5e1395c4beb648f9c57b3a18790a8b68e509cb882f81c2b53e4d1246312488eedb6ba1ad498402763c610c585f
|
7
|
+
data.tar.gz: 7379c8a12eef52c0a37d33b93a7e0e2d1b1a4aeef2896d082805903e7b84201abedd00951d6875a243249e4339af9928c9d6d50062a38d0a569c322dcff13f30
|
data/.gitignore
CHANGED
data/bin/iterm2-viewer
ADDED
@@ -0,0 +1,111 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
# encoding: UTF-8
|
3
|
+
|
4
|
+
require 'base64'
|
5
|
+
require 'mime/types'
|
6
|
+
|
7
|
+
module Viewer
|
8
|
+
|
9
|
+
class << self
|
10
|
+
attr_accessor :configuration, :show
|
11
|
+
end
|
12
|
+
|
13
|
+
def self.configure
|
14
|
+
self.configuration ||= Configuration.new
|
15
|
+
yield(configuration)
|
16
|
+
end
|
17
|
+
|
18
|
+
class Configuration
|
19
|
+
attr_accessor :viewport
|
20
|
+
|
21
|
+
#defaults
|
22
|
+
def initialize
|
23
|
+
@viewport =
|
24
|
+
{
|
25
|
+
width: "auto",
|
26
|
+
height: "auto",
|
27
|
+
keep_aspect_ratio: true
|
28
|
+
}
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
32
|
+
# interface class
|
33
|
+
def self.show(arguments)
|
34
|
+
Base.new arguments if arguments.any?
|
35
|
+
end
|
36
|
+
|
37
|
+
class Base
|
38
|
+
|
39
|
+
def initialize(routes)
|
40
|
+
# display objects
|
41
|
+
routes.each do |object|
|
42
|
+
if exist? object
|
43
|
+
display Media.new object
|
44
|
+
end
|
45
|
+
end
|
46
|
+
end
|
47
|
+
|
48
|
+
def exist?(object)
|
49
|
+
File.file? object
|
50
|
+
end
|
51
|
+
|
52
|
+
class Media < String
|
53
|
+
|
54
|
+
attr_reader :renderable, :data
|
55
|
+
|
56
|
+
def initialize(data)
|
57
|
+
super(data)
|
58
|
+
@data ||= construct
|
59
|
+
end
|
60
|
+
|
61
|
+
def construct
|
62
|
+
if renderable?
|
63
|
+
source = open self
|
64
|
+
Base64.encode64(source.read)
|
65
|
+
else
|
66
|
+
nil
|
67
|
+
end
|
68
|
+
end
|
69
|
+
|
70
|
+
def kind
|
71
|
+
MIME::Types.of(self).first.media_type
|
72
|
+
end
|
73
|
+
|
74
|
+
def type
|
75
|
+
MIME::Types.of(self).first.sub_type
|
76
|
+
end
|
77
|
+
|
78
|
+
def type_renderable?
|
79
|
+
Type.const_get kind.capitalize
|
80
|
+
rescue NameError
|
81
|
+
false
|
82
|
+
end
|
83
|
+
|
84
|
+
def kind_renderable?
|
85
|
+
type_renderable? ? (Type.const_get(kind.capitalize)::MIME.include? type) : false
|
86
|
+
end
|
87
|
+
alias_method :renderable?, :kind_renderable?
|
88
|
+
|
89
|
+
module Type
|
90
|
+
module Image
|
91
|
+
MIME = ['jpeg','jpg','png','tiff','gif']
|
92
|
+
end
|
93
|
+
end
|
94
|
+
end
|
95
|
+
|
96
|
+
# TODO: Add options support
|
97
|
+
def display(object)
|
98
|
+
# http://iterm2.com/images.html
|
99
|
+
# based on https://raw.githubusercontent.com/gnachman/iTerm2/master/tests/imgcat
|
100
|
+
puts "\033]1337;File=;inline=1:#{object.data}\a\n" if object.renderable?
|
101
|
+
end
|
102
|
+
end
|
103
|
+
end
|
104
|
+
|
105
|
+
# override defaults
|
106
|
+
Viewer.configure do |config|
|
107
|
+
config.viewport[:width] = 10
|
108
|
+
end
|
109
|
+
|
110
|
+
# run application with shell parameters
|
111
|
+
Viewer.show ARGV
|
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.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- " Andrey"
|
@@ -41,7 +41,8 @@ dependencies:
|
|
41
41
|
description: Display media files in terminal. iTerm2 is required
|
42
42
|
email:
|
43
43
|
- andrey@antipov.me
|
44
|
-
executables:
|
44
|
+
executables:
|
45
|
+
- iterm2-viewer
|
45
46
|
extensions: []
|
46
47
|
extra_rdoc_files: []
|
47
48
|
files:
|
@@ -50,6 +51,7 @@ files:
|
|
50
51
|
- LICENSE.txt
|
51
52
|
- README.md
|
52
53
|
- Rakefile
|
54
|
+
- bin/iterm2-viewer
|
53
55
|
- iterm2-viewer.gemspec
|
54
56
|
- lib/iterm2/viewer.rb
|
55
57
|
- lib/iterm2/viewer/version.rb
|