iterm2-protocol 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 3f68add32491bd9b05616013a4f4577f7442ff20
4
+ data.tar.gz: 71b87bc1064f370df81ea6eecf05cf9f66a0159c
5
+ SHA512:
6
+ metadata.gz: 43d03d1fbe9238d24a2cd433cf0892b8fb1e48e9eb3bd13feb7e8dff3a25d9185c184a7ead36de176a9f2cd71fe1cd74a59f68ce56d2273fc7f1bae995fdd6da
7
+ data.tar.gz: aca4e5074d4dc3c7fcf87045adc2440d393752693bd3c95d863e31ed6f68560a2d24d56840db2763fb3b74ac516bf7a80c51805434f8f41406286695ae460b99
data/.gitignore ADDED
@@ -0,0 +1,9 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
data/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --format documentation
2
+ --color
data/.travis.yml ADDED
@@ -0,0 +1,5 @@
1
+ sudo: false
2
+ language: ruby
3
+ rvm:
4
+ - 2.3.0
5
+ before_install: gem install bundler -v 1.12.4
data/Gemfile ADDED
@@ -0,0 +1,3 @@
1
+ source "https://rubygems.org"
2
+
3
+ gemspec
data/Guardfile ADDED
@@ -0,0 +1,14 @@
1
+ guard :rspec, cmd: "bundle exec rspec" do
2
+ require "guard/rspec/dsl"
3
+ dsl = Guard::RSpec::Dsl.new(self)
4
+
5
+ # RSpec files
6
+ rspec = dsl.rspec
7
+ watch(rspec.spec_helper) { rspec.spec_dir }
8
+ watch(rspec.spec_support) { rspec.spec_dir }
9
+ watch(rspec.spec_files)
10
+
11
+ # Ruby files
12
+ ruby = dsl.ruby
13
+ dsl.watch_spec_files_for(ruby.lib_files)
14
+ end
data/README.md ADDED
@@ -0,0 +1,36 @@
1
+ # ITerm2::Protocol
2
+
3
+ Welcome to your new gem! In this directory, you'll find the files you need to be able to package up your Ruby library into a gem. Put your Ruby code in the file `lib/iterm2/protocol`. To experiment with that code, run `bin/console` for an interactive prompt.
4
+
5
+ TODO: Delete this and the text above, and describe your gem
6
+
7
+ ## Installation
8
+
9
+ Add this line to your application's Gemfile:
10
+
11
+ ```ruby
12
+ gem 'iterm2-protocol'
13
+ ```
14
+
15
+ And then execute:
16
+
17
+ $ bundle
18
+
19
+ Or install it yourself as:
20
+
21
+ $ gem install iterm2-protocol
22
+
23
+ ## Usage
24
+
25
+ TODO: Write usage instructions here
26
+
27
+ ## Development
28
+
29
+ After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
30
+
31
+ To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
32
+
33
+ ## Contributing
34
+
35
+ Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/iterm2-protocol.
36
+
data/Rakefile ADDED
@@ -0,0 +1,6 @@
1
+ require "bundler/gem_tasks"
2
+ require "rspec/core/rake_task"
3
+
4
+ RSpec::Core::RakeTask.new(:spec)
5
+
6
+ task :default => :spec
data/TODO.md ADDED
@@ -0,0 +1,3 @@
1
+ # TODO
2
+
3
+ * Specs!
data/bin/console ADDED
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "iterm2/protocol"
5
+
6
+ # You can add fixtures and/or initialization code here to make experimenting
7
+ # with your gem easier. You can also use a different console, if you like.
8
+
9
+ # (If you use this, don't forget to add pry to your Gemfile!)
10
+ # require "pry"
11
+ # Pry.start
12
+
13
+ require "irb"
14
+ IRB.start
data/bin/setup ADDED
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+ set -vx
5
+
6
+ bundle install
7
+
8
+ # Do any other automated setup that you need to do here
data/exe/imgcat ADDED
@@ -0,0 +1,5 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "iterm2/protocol"
4
+
5
+ ARGV.each { |path| puts ITerm2::Protocol.image(path: path) }
@@ -0,0 +1,27 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'iterm2/protocol/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "iterm2-protocol"
8
+ spec.version = ITerm2::Protocol::VERSION
9
+ spec.authors = ["Ryan Scott Lewis"]
10
+ spec.email = ["ryan@rynet.us"]
11
+
12
+ spec.summary = %q{A wrapper for the iTerm2 xterm protocol extensions.}
13
+ spec.description = %q{Allows for easier generation of iTerm2 escape sequences.}
14
+ spec.homepage = "https://github.com/RyanScottLewis/iterm2-protocol"
15
+
16
+ spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
17
+ spec.bindir = "exe"
18
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
19
+ spec.require_paths = ["lib"]
20
+
21
+ spec.add_dependency "aspect", "~> 0.0.3"
22
+
23
+ spec.add_development_dependency "bundler", "~> 1.12"
24
+ spec.add_development_dependency "rake", "~> 10.0"
25
+ spec.add_development_dependency "rspec", "~> 3.0"
26
+ spec.add_development_dependency "guard-rspec", "~> 4.7.2"
27
+ end
@@ -0,0 +1,88 @@
1
+ require "aspect/has_attributes"
2
+
3
+ require "iterm2/protocol/formatter"
4
+
5
+ module ITerm2
6
+ module Protocol
7
+
8
+ # Escape sequence for use file downloads.
9
+ class FileSequence
10
+
11
+ class << self
12
+
13
+ def format(attributes={})
14
+ new(attributes).to_s
15
+ end
16
+
17
+ end
18
+
19
+ include Aspect::HasAttributes
20
+
21
+ def initialize(attributes={})
22
+ @inline = false
23
+
24
+ update_attributes(attributes)
25
+
26
+ raise ArgumentError, "path must be given" if @path.nil?
27
+ end
28
+
29
+ # @method path
30
+ # Get the path.
31
+ #
32
+ # @return [String]
33
+
34
+ # @method path=
35
+ # Set the path.
36
+ #
37
+ # @param [#to_s] value
38
+ # @return [String]
39
+ attribute(:path) { |value| value.is_a?(Pathname) ? value : Pathname.new(value.to_s) }
40
+
41
+ # @method inline
42
+ # Get whether the file will be displayed inline.
43
+ #
44
+ # @return [Boolean]
45
+
46
+ # @method inline=
47
+ # Set whether the file will be displayed inline.
48
+ #
49
+ # @param [Boolean] value
50
+ # @return [Boolean]
51
+ attribute(:inline, query: true)
52
+
53
+ # Return the arguments to this escape sequence.
54
+ #
55
+ # @param [nil, Symbol] output
56
+ # The output format to return the Hash for.
57
+ #
58
+ # Set to `:terminal` to format for an escape sequence.
59
+ # @return [Hash]
60
+ def to_h(output=nil)
61
+ result = {
62
+ name: Base64.encode64(@path.to_s),
63
+ size: @path.size
64
+ }
65
+
66
+ result[:inline] = output == :terminal ? (@inline ? 1 : 0) : @inline
67
+
68
+ result
69
+ end
70
+
71
+ # Get the escape sequence.
72
+ #
73
+ # @param [#to_h] attributes The attributes to pass to the `Formatter`.
74
+ # @return [String]
75
+ def to_s(attributes={})
76
+ attributes = {
77
+ key: "File",
78
+ value: to_h(:terminal),
79
+ content: Base64.encode64(@path.read)
80
+ }.merge(attributes)
81
+
82
+ Formatter.format(attributes)
83
+ end
84
+
85
+ end
86
+
87
+ end
88
+ end
@@ -0,0 +1,109 @@
1
+ require "aspect/has_attributes"
2
+
3
+ module ITerm2
4
+ module Protocol
5
+
6
+ class Formatter
7
+
8
+ class << self
9
+
10
+ def format(attributes={})
11
+ new(attributes).to_s
12
+ end
13
+
14
+ end
15
+
16
+ include Aspect::HasAttributes
17
+
18
+ def initialize(attributes={})
19
+ @tmux = ENV["TERM"] =~ /^screen/
20
+
21
+ update_attributes(attributes)
22
+ end
23
+
24
+ # @method key
25
+ # Get the key.
26
+ #
27
+ # @return [String]
28
+
29
+ # @method key=
30
+ # Set the key.
31
+ #
32
+ # @param [#to_s] value
33
+ # @return [String]
34
+ attribute(:key) { |value| value.to_s }
35
+
36
+ # @method value
37
+ # Get the value.
38
+ #
39
+ # @return [Hash, String]
40
+
41
+ # @method value=
42
+ # Set the value.
43
+ #
44
+ # @param [#to_h, #to_s] value
45
+ # @return [Hash, String]
46
+ attribute(:value) { |value| value.respond_to?(:to_h) ? value.to_h : value.to_s }
47
+
48
+ # @method content
49
+ # Get the content.
50
+ #
51
+ # @return [nil, String]
52
+
53
+ # @method content=
54
+ # Set the content.
55
+ #
56
+ # @param [nil, #to_s] value
57
+ # @return [nil, String]
58
+ attribute(:content) { |value| value.nil? ? nil : value.to_s }
59
+
60
+ # @method tmux
61
+ # Get whether to format for tmux output.
62
+ #
63
+ # @return [Boolean]
64
+
65
+ # @method tmux=
66
+ # Set whether to format for tmux output.
67
+ #
68
+ # @param [Boolean] value
69
+ # @return [Boolean]
70
+ attribute(:tmux, query: true)
71
+
72
+ # Get the key-value pair formatted as an iTerm2 escape sequence.
73
+ #
74
+ # If the value is a Hash, it will be formatted as `key=value` with each pair being delimited
75
+ # by a semicolon (`;`).
76
+ #
77
+ # @return [String]
78
+ def to_s
79
+ [].tap do |segments|
80
+ segments << escape_sequence
81
+ segments << "1337;"
82
+ segments << @key
83
+ segments << "="
84
+ segments << format_value(@value)
85
+ segments << ":#{@content}" unless @content.nil?
86
+ segments << st_sequence
87
+ end.join
88
+ end
89
+
90
+ protected
91
+
92
+ def escape_sequence
93
+ @tmux ? "\033Ptmux;\033\033]" : "\033]"
94
+ end
95
+
96
+ def st_sequence
97
+ @tmux ? "\a\033\\" : "\a"
98
+ end
99
+
100
+ def format_value(value)
101
+ return value unless value.is_a?(Hash)
102
+
103
+ value.collect { |k,v| "#{k}=#{v}" }.join(";")
104
+ end
105
+
106
+ end
107
+
108
+ end
109
+ end
@@ -0,0 +1,94 @@
1
+ require "iterm2/protocol/file_sequence"
2
+
3
+ module ITerm2
4
+ module Protocol
5
+
6
+ # Escape sequence for use with inline images.
7
+ class ImageSequence < FileSequence
8
+
9
+ def initialize(attributes={})
10
+ @width = "auto"
11
+ @height = "auto"
12
+ @preserve_aspect_ratio = true
13
+
14
+ super
15
+
16
+ @inline = true
17
+ end
18
+
19
+ # @method width
20
+ # Get the width.
21
+ #
22
+ # @return [String]
23
+
24
+ # @method width=
25
+ # Set the width.
26
+ #
27
+ # Given as a number followed by a unit, or the word "auto":
28
+ #
29
+ # N: N character cells.
30
+ # Npx: N pixels.
31
+ # N%: N percent of the session's width or height.
32
+ # auto: The image's inherent size will be used to determine an appropriate dimension.
33
+ #
34
+ # @param [#to_s] value
35
+ # @return [String]
36
+ attribute(:width) { |value| value.to_s }
37
+
38
+ # @method height
39
+ # Get the height.
40
+ #
41
+ # @return [String]
42
+
43
+ # @method height=
44
+ # Set the height.
45
+ #
46
+ # Given as a number followed by a unit, or the word "auto":
47
+ #
48
+ # N: N character cells.
49
+ # Npx: N pixels.
50
+ # N%: N percent of the session's width or height.
51
+ # auto: The image's inherent size will be used to determine an appropriate dimension.
52
+ #
53
+ # @param [#to_s] value
54
+ # @return [String]
55
+ attribute(:height) { |value| value.to_s }
56
+
57
+ # @method preserve_aspect_ratio
58
+ # Get whether to preserve the aspect ratio.
59
+ #
60
+ # @return [Boolean]
61
+
62
+ # @method preserve_aspect_ratio=
63
+ # Set whether to preserve the aspect ratio.
64
+ #
65
+ # @param [Boolean] value
66
+ # @return [Boolean]
67
+ attribute(:preserve_aspect_ratio, query: true)
68
+
69
+ # Return the arguments to this escape sequence.
70
+ #
71
+ # @param [nil, Symbol] output
72
+ # The output format to return the Hash for.
73
+ #
74
+ # Set to `:terminal` to format for an escape sequence.
75
+ # @return [Hash]
76
+ def to_h(output=nil)
77
+ result = {
78
+ width: @width,
79
+ height: @height
80
+ }
81
+
82
+ if output == :terminal
83
+ result[:preserveAspectRatio] = @preserve_aspect_ratio ? 1 : 0
84
+ else
85
+ result[:preserve_aspect_ratio] = @preserve_aspect_ratio
86
+ end
87
+
88
+ super(output).merge(result)
89
+ end
90
+
91
+ end
92
+
93
+ end
94
+ end
@@ -0,0 +1,5 @@
1
+ module ITerm2
2
+ module Protocol
3
+ VERSION = "0.1.0"
4
+ end
5
+ end
@@ -0,0 +1,26 @@
1
+ require "base64"
2
+
3
+ require "iterm2/protocol/version"
4
+ require "iterm2/protocol/formatter"
5
+ require "iterm2/protocol/file_sequence"
6
+ require "iterm2/protocol/image_sequence"
7
+
8
+ module ITerm2
9
+ module Protocol
10
+ class << self
11
+
12
+ def format(attributes={})
13
+ Formatter.format(attributes)
14
+ end
15
+
16
+ def file(attributes={})
17
+ FileSequence.format(attributes)
18
+ end
19
+
20
+ def image(attributes={})
21
+ ImageSequence.format(attributes)
22
+ end
23
+
24
+ end
25
+ end
26
+ end
metadata ADDED
@@ -0,0 +1,131 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: iterm2-protocol
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Ryan Scott Lewis
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2016-06-21 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: aspect
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: 0.0.3
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: 0.0.3
27
+ - !ruby/object:Gem::Dependency
28
+ name: bundler
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '1.12'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '1.12'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rake
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '10.0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '10.0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: rspec
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '3.0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '3.0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: guard-rspec
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - "~>"
74
+ - !ruby/object:Gem::Version
75
+ version: 4.7.2
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - "~>"
81
+ - !ruby/object:Gem::Version
82
+ version: 4.7.2
83
+ description: Allows for easier generation of iTerm2 escape sequences.
84
+ email:
85
+ - ryan@rynet.us
86
+ executables:
87
+ - imgcat
88
+ extensions: []
89
+ extra_rdoc_files: []
90
+ files:
91
+ - ".gitignore"
92
+ - ".rspec"
93
+ - ".travis.yml"
94
+ - Gemfile
95
+ - Guardfile
96
+ - README.md
97
+ - Rakefile
98
+ - TODO.md
99
+ - bin/console
100
+ - bin/setup
101
+ - exe/imgcat
102
+ - iterm2-protocol.gemspec
103
+ - lib/iterm2/protocol.rb
104
+ - lib/iterm2/protocol/file_sequence.rb
105
+ - lib/iterm2/protocol/formatter.rb
106
+ - lib/iterm2/protocol/image_sequence.rb
107
+ - lib/iterm2/protocol/version.rb
108
+ homepage: https://github.com/RyanScottLewis/iterm2-protocol
109
+ licenses: []
110
+ metadata: {}
111
+ post_install_message:
112
+ rdoc_options: []
113
+ require_paths:
114
+ - lib
115
+ required_ruby_version: !ruby/object:Gem::Requirement
116
+ requirements:
117
+ - - ">="
118
+ - !ruby/object:Gem::Version
119
+ version: '0'
120
+ required_rubygems_version: !ruby/object:Gem::Requirement
121
+ requirements:
122
+ - - ">="
123
+ - !ruby/object:Gem::Version
124
+ version: '0'
125
+ requirements: []
126
+ rubyforge_project:
127
+ rubygems_version: 2.5.1
128
+ signing_key:
129
+ specification_version: 4
130
+ summary: A wrapper for the iTerm2 xterm protocol extensions.
131
+ test_files: []