iterm2-viewer 0.0.1 → 0.0.2

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: ccff73049e227591a8c3d14530eff86568e37fe2
4
- data.tar.gz: 205d136a5841881bbcde2fa32dfb32f7c8023a2d
3
+ metadata.gz: 6d63bfeab1ba076032eca30e3f2a884292e7fbc6
4
+ data.tar.gz: 4642bcdfc73f99e8fbdfd853535f51b8c6ae247a
5
5
  SHA512:
6
- metadata.gz: d6868efca98878a2a225c5d74e90faff3b4c1e77f8b57c85e45c88db202fd59a47593526f620a2f29f61def3b6d43ecb414e35063bb516467270c7d3ec06e71a
7
- data.tar.gz: 2bc81c79effc8ff5a96c01f49d5458c6991f8674332385cfaa5a02677946f96ae144758cee592875e0adacba3116acfa690e85bf6ad91de0b57c49d6f358d845
6
+ metadata.gz: 303ec9563abcbedb0c7a0efe484600646e9aea5e1395c4beb648f9c57b3a18790a8b68e509cb882f81c2b53e4d1246312488eedb6ba1ad498402763c610c585f
7
+ data.tar.gz: 7379c8a12eef52c0a37d33b93a7e0e2d1b1a4aeef2896d082805903e7b84201abedd00951d6875a243249e4339af9928c9d6d50062a38d0a569c322dcff13f30
data/.gitignore CHANGED
@@ -12,3 +12,4 @@
12
12
  *.o
13
13
  *.a
14
14
  mkmf.log
15
+ *.gem
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
@@ -1,5 +1,5 @@
1
1
  module Iterm2
2
2
  module Viewer
3
- VERSION = "0.0.1"
3
+ VERSION = "0.0.2"
4
4
  end
5
5
  end
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.1
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