iterm2_escape 1.0.0

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 ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: c7bdf76a379df15ad8ca81c9a56d42bf7fd6ff3e
4
+ data.tar.gz: 4a7f80ce8687c1a88eddecf2e5e24688ef2e9fe7
5
+ SHA512:
6
+ metadata.gz: a0ee772746dc60a32f212b6d768b72c7748945b608e1697ebd1569810b035702bc4416cc3739926915d945b7d01cf1f9a1a28814d8a93d361506ccf01eaf5751
7
+ data.tar.gz: 47f8004d0a7ea58a9a78750e626dcf16cf44ce56fdbb37281a4e5be535a0c760385c68e72de6ee526a85c0ec47fd07abb65045332a20b22e393f38fe04b7a497
data/.gitignore ADDED
@@ -0,0 +1,18 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ Gemfile.lock
7
+ InstalledFiles
8
+ _yardoc
9
+ coverage
10
+ doc/
11
+ lib/bundler/man
12
+ pkg
13
+ rdoc
14
+ spec/reports
15
+ test/tmp
16
+ test/version_tmp
17
+ tmp
18
+ .rvmrc
data/.travis.yml ADDED
@@ -0,0 +1,7 @@
1
+ before_install: gem install bundler -v 1.3.2
2
+ language: ruby
3
+ rvm:
4
+ - "1.9.3"
5
+ - "2.0.0"
6
+ notifications:
7
+ email: false
data/Gemfile ADDED
@@ -0,0 +1,9 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in iterm2_escape.gemspec
4
+ gemspec
5
+
6
+ group :development, :test do
7
+ gem 'rspec', '~> 2.13'
8
+ gem 'rake'
9
+ end
data/LICENSE.txt ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2013 Mark Rushakoff
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,32 @@
1
+ # Iterm2Escape
2
+
3
+ [![Build Status](https://travis-ci.org/mark-rushakoff/iterm2_escape.png)](https://travis-ci.org/mark-rushakoff/iterm2_escape)
4
+ [![Code Climate](https://codeclimate.com/github/mark-rushakoff/iterm2_escape.png)](https://codeclimate.com/github/mark-rushakoff/iterm2_escape)
5
+
6
+ TODO: Write a gem description
7
+
8
+ ## Installation
9
+
10
+ Add this line to your application's Gemfile:
11
+
12
+ gem 'iterm2_escape'
13
+
14
+ And then execute:
15
+
16
+ $ bundle
17
+
18
+ Or install it yourself as:
19
+
20
+ $ gem install iterm2_escape
21
+
22
+ ## Usage
23
+
24
+ See the examples directory.
25
+
26
+ ## Contributing
27
+
28
+ 1. Fork it
29
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
30
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
31
+ 4. Push to the branch (`git push origin my-new-feature`)
32
+ 5. Create new Pull Request
data/Rakefile ADDED
@@ -0,0 +1,9 @@
1
+ require "bundler/gem_tasks"
2
+ require 'rspec/core/rake_task'
3
+
4
+ RSpec::Core::RakeTask.new(:spec) do |t|
5
+ t.pattern = 'spec/**/*_spec.rb'
6
+ t.rspec_opts = %w(--format documentation --color)
7
+ end
8
+
9
+ task :default => :spec
@@ -0,0 +1,5 @@
1
+ require 'iterm2_escape'
2
+
3
+ abort "Usage: #{$0} RED GREEN BLUE" unless ARGV.size == 3
4
+
5
+ Iterm2Escape::Tab.set_color(*(ARGV.map(&:to_i)))
@@ -0,0 +1,21 @@
1
+ require 'iterm2_escape'
2
+ require 'getoptlong'
3
+
4
+ abort "Usage: #{$0} [--tab TABTITLE] [--window WINDOWTITLE] [--all ALLTITLE]" if ARGV.size == 0
5
+
6
+ opts = GetoptLong.new(
7
+ ['--tab', '-t', GetoptLong::REQUIRED_ARGUMENT],
8
+ ['--window', '-w', GetoptLong::REQUIRED_ARGUMENT],
9
+ ['--all', '-a', GetoptLong::REQUIRED_ARGUMENT]
10
+ )
11
+
12
+ opts.each do |opt, arg|
13
+ case opt
14
+ when '--tab'
15
+ Iterm2Escape::Tab.title = arg
16
+ when '--window'
17
+ Iterm2Escape::Tab.window_title = arg
18
+ when '--all'
19
+ Iterm2Escape::Tab.all_titles = arg
20
+ end
21
+ end
@@ -0,0 +1,28 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'iterm2_escape/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "iterm2_escape"
8
+ spec.version = Iterm2Escape::VERSION
9
+ spec.authors = ["Mark Rushakoff"]
10
+ spec.email = ["mark.rushakoff@gmail.com"]
11
+ spec.description = %q{A simple interface to iTerm2 proprietary escape codes.}
12
+ spec.summary = <<-SUMMARY
13
+ iterm2_escape provides a simple API to set:
14
+ * tab chrome color
15
+ * tab title
16
+ * window title
17
+ SUMMARY
18
+ spec.homepage = "https://github.com/mark-rushakoff/iterm2_escape"
19
+ spec.license = "MIT"
20
+
21
+ spec.files = `git ls-files`.split($/)
22
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
23
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
24
+ spec.require_paths = ["lib"]
25
+
26
+ spec.add_development_dependency "bundler", "~> 1.3"
27
+ spec.add_development_dependency "rake"
28
+ end
@@ -0,0 +1,42 @@
1
+ require 'iterm2_escape/writer'
2
+
3
+ module Iterm2Escape
4
+ module Tab
5
+ class << self
6
+ # Sets the red level of the tab's chrome
7
+ #
8
+ # @param [Integer] red Red level (0-255) of the tab's chrome
9
+ def red=(red)
10
+ raise ArgumentError, "Value must be in range 0-255" unless (0..255).include?(red)
11
+ Writer.write "\033]6;1;bg;red;brightness;#{red}\a"
12
+ end
13
+
14
+ # Sets the green level of the tab's chrome
15
+ #
16
+ # @param [Integer] green Green level (0-255) of the tab's chrome
17
+ def green=(green)
18
+ raise ArgumentError, "Value must be in range 0-255" unless (0..255).include?(green)
19
+ Writer.write "\033]6;1;bg;green;brightness;#{green}\a"
20
+ end
21
+
22
+ # Sets the blue level of the tab's chrome
23
+ #
24
+ # @param [Integer] blue Blue level (0-255) of the tab's chrome
25
+ def blue=(blue)
26
+ raise ArgumentError, "Value must be in range 0-255" unless (0..255).include?(blue)
27
+ Writer.write "\033]6;1;bg;blue;brightness;#{blue}\a"
28
+ end
29
+
30
+ # Sets all the color levels of the tab's chrome
31
+ #
32
+ # @param [Integer] red Red level (0-255) of the tab's chrome
33
+ # @param [Integer] green Green level (0-255) of the tab's chrome
34
+ # @param [Integer] blue Blue level (0-255) of the tab's chrome
35
+ def set_color(red, green, blue)
36
+ self.red = red
37
+ self.green = green
38
+ self.blue = blue
39
+ end
40
+ end
41
+ end
42
+ end
@@ -0,0 +1,28 @@
1
+ require 'iterm2_escape/writer'
2
+
3
+ module Iterm2Escape
4
+ module Tab
5
+ class << self
6
+ # Sets the tab title
7
+ #
8
+ # @param [String] title What to use for the tab title
9
+ def title=(title)
10
+ Writer.write "\033]1;#{title}\a"
11
+ end
12
+
13
+ # Sets the window title
14
+ #
15
+ # @param [String] title What to use for the window title
16
+ def window_title=(title)
17
+ Writer.write "\033]2;#{title}\a"
18
+ end
19
+
20
+ # Sets both the tab and window titles
21
+ #
22
+ # @param [String] title What to use for the titles
23
+ def all_titles=(title)
24
+ Writer.write "\033]0;#{title}\a"
25
+ end
26
+ end
27
+ end
28
+ end
@@ -0,0 +1,3 @@
1
+ module Iterm2Escape
2
+ VERSION = "1.0.0"
3
+ end
@@ -0,0 +1,30 @@
1
+ module Iterm2Escape
2
+ module Writer
3
+ class << self
4
+ # Writes the given message if appropriate
5
+ #
6
+ # @param [String] message to print to the target
7
+ # @param [IO] target where to write the message
8
+ def write(message, target = $stdout)
9
+ target.write(message) if should_write?(target)
10
+ end
11
+
12
+ # Identifies whether the environment says we should print control messages
13
+ #
14
+ # @param [IO] target where to check regarding writing the message
15
+ def should_write?(target = $stdout)
16
+ !is_suppressed? && is_iterm? && target.tty?
17
+ end
18
+
19
+ private
20
+ def is_suppressed?
21
+ !(ENV['SUPPRESS_ITERM2_ESCAPE_GEM'].nil? || ENV['SUPPRESS_ITERM2_ESCAPE_GEM'].empty?)
22
+ end
23
+
24
+ def is_iterm?
25
+ # seems like it doesn't *really* matter if we're on iTerm2 -- but let's play it safe
26
+ ENV['TERM_PROGRAM'] == 'iTerm.app'
27
+ end
28
+ end
29
+ end
30
+ end
@@ -0,0 +1,6 @@
1
+ require "iterm2_escape/version"
2
+ require "iterm2_escape/tab_color"
3
+ require "iterm2_escape/tab_title"
4
+
5
+ module Iterm2Escape
6
+ end
@@ -0,0 +1,8 @@
1
+ require 'iterm2_escape'
2
+ require 'rspec'
3
+
4
+ RSpec.configure do |config|
5
+ config.expect_with :rspec do |c|
6
+ c.syntax = :expect
7
+ end
8
+ end
@@ -0,0 +1,52 @@
1
+ require 'spec_helper'
2
+
3
+ describe Iterm2Escape::Tab do
4
+ shared_examples_for 'a color' do
5
+ let(:method) { (color.to_s + '=').to_sym }
6
+ it 'rejects values less than 0' do
7
+ expect {
8
+ Iterm2Escape::Tab.public_send(method, -1)
9
+ }.to raise_error(ArgumentError, /0-255/)
10
+ end
11
+
12
+ it 'rejects values more than 255' do
13
+ expect {
14
+ Iterm2Escape::Tab.public_send(method, 256)
15
+ }.to raise_error(ArgumentError, /0-255/)
16
+ end
17
+
18
+ it 'accepts values in between 0-255' do
19
+ Iterm2Escape::Writer.should_receive(:write).with(color_128_message)
20
+
21
+ Iterm2Escape::Tab.public_send(method, 128)
22
+ end
23
+ end
24
+
25
+ let(:color_128_message) { "\033]6;1;bg;#{color};brightness;128\a" }
26
+
27
+ describe '.red=' do
28
+ let(:color) { :red }
29
+ it_should_behave_like 'a color'
30
+ end
31
+
32
+ describe '.green=' do
33
+ let(:color) { :green }
34
+ it_should_behave_like 'a color'
35
+ end
36
+
37
+ describe '.blue=' do
38
+ let(:color) { :blue }
39
+ it_should_behave_like 'a color'
40
+ end
41
+
42
+ describe '.set_color' do
43
+ it 'delegates to red=, green=, blue=' do
44
+ # papayawhip, a particularly strange-named HTML color
45
+ Iterm2Escape::Tab.should_receive(:red=).with(255)
46
+ Iterm2Escape::Tab.should_receive(:green=).with(238)
47
+ Iterm2Escape::Tab.should_receive(:blue=).with(221)
48
+
49
+ Iterm2Escape::Tab.set_color(255, 238, 221)
50
+ end
51
+ end
52
+ end
@@ -0,0 +1,18 @@
1
+ require 'spec_helper'
2
+
3
+ describe Iterm2Escape::Tab do
4
+ it 'uses the right escape code for the tab title' do
5
+ Iterm2Escape::Writer.should_receive(:write).with("\033]1;my tab\a")
6
+ Iterm2Escape::Tab.title = 'my tab'
7
+ end
8
+
9
+ it 'uses the right escape code for the window title' do
10
+ Iterm2Escape::Writer.should_receive(:write).with("\033]2;my window\a")
11
+ Iterm2Escape::Tab.window_title = 'my window'
12
+ end
13
+
14
+ it 'uses the right escape code for setting all titles' do
15
+ Iterm2Escape::Writer.should_receive(:write).with("\033]0;everywhere\a")
16
+ Iterm2Escape::Tab.all_titles = 'everywhere'
17
+ end
18
+ end
@@ -0,0 +1,7 @@
1
+ require 'spec_helper'
2
+
3
+ describe Iterm2Escape do
4
+ it "has a version" do
5
+ expect(Iterm2Escape::VERSION).not_to be_nil
6
+ end
7
+ end
@@ -0,0 +1,61 @@
1
+ require 'spec_helper'
2
+
3
+ describe Iterm2Escape::Writer do
4
+ describe '.should_write?' do
5
+ let(:subject) { Iterm2Escape::Writer.should_write? }
6
+
7
+ before do
8
+ ENV.stub(:[]).with('SUPPRESS_ITERM2_ESCAPE_GEM').and_return(nil)
9
+ ENV.stub(:[]).with('TERM_PROGRAM').and_return('iTerm.app')
10
+ end
11
+
12
+ shared_examples "will not write", will_write: false do
13
+ it "will not write" do
14
+ expect(subject).to eq(false)
15
+ end
16
+ end
17
+
18
+ describe 'when everything is lined up' do
19
+ it 'will write' do
20
+ expect(subject).to eq(true)
21
+ end
22
+ end
23
+
24
+ describe 'when it is not iTerm2', will_write: false do
25
+ before { ENV.stub(:[]).with('TERM_PROGRAM').and_return('Apple_Terminal') }
26
+ end
27
+
28
+ describe 'when $SUPPRESS_ITERM2_ESCAPE_GEM is set', will_write: false do
29
+ before { ENV.stub(:[]).with('SUPPRESS_ITERM2_ESCAPE_GEM').and_return('1') }
30
+ end
31
+
32
+ describe 'when $stdout is not a TTY', will_write: false do
33
+ before { $stdout.stub(:tty?).and_return(false) }
34
+ end
35
+ end
36
+
37
+ describe '.write' do
38
+ describe 'when .should_write? is true' do
39
+ before { Iterm2Escape::Writer.stub(:should_write?).and_return(true) }
40
+ it 'writes to $stdout by default' do
41
+ $stdout.should_receive(:write).with('Hi')
42
+ Iterm2Escape::Writer.write('Hi')
43
+ end
44
+
45
+ it 'writes to the target arg if provided' do
46
+ target = double('target')
47
+ target.should_receive(:write).with('Hello')
48
+ Iterm2Escape::Writer.write('Hello', target)
49
+ end
50
+ end
51
+
52
+ describe 'when .should_write? is false' do
53
+ before { Iterm2Escape::Writer.stub(:should_write?).and_return(false) }
54
+ it 'does not write' do
55
+ target = double('target')
56
+ target.should_not_receive(:write)
57
+ Iterm2Escape::Writer.write('Hi', target)
58
+ end
59
+ end
60
+ end
61
+ end
metadata ADDED
@@ -0,0 +1,97 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: iterm2_escape
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.0.0
5
+ platform: ruby
6
+ authors:
7
+ - Mark Rushakoff
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2013-03-11 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ~>
18
+ - !ruby/object:Gem::Version
19
+ version: '1.3'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ~>
25
+ - !ruby/object:Gem::Version
26
+ version: '1.3'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - '>='
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - '>='
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ description: A simple interface to iTerm2 proprietary escape codes.
42
+ email:
43
+ - mark.rushakoff@gmail.com
44
+ executables: []
45
+ extensions: []
46
+ extra_rdoc_files: []
47
+ files:
48
+ - .gitignore
49
+ - .travis.yml
50
+ - Gemfile
51
+ - LICENSE.txt
52
+ - README.md
53
+ - Rakefile
54
+ - examples/set_tab_color.rb
55
+ - examples/set_titles.rb
56
+ - iterm2_escape.gemspec
57
+ - lib/iterm2_escape.rb
58
+ - lib/iterm2_escape/tab_color.rb
59
+ - lib/iterm2_escape/tab_title.rb
60
+ - lib/iterm2_escape/version.rb
61
+ - lib/iterm2_escape/writer.rb
62
+ - spec/spec_helper.rb
63
+ - spec/tab_color_spec.rb
64
+ - spec/tab_title_spec.rb
65
+ - spec/version_spec.rb
66
+ - spec/writer_spec.rb
67
+ homepage: https://github.com/mark-rushakoff/iterm2_escape
68
+ licenses:
69
+ - MIT
70
+ metadata: {}
71
+ post_install_message:
72
+ rdoc_options: []
73
+ require_paths:
74
+ - lib
75
+ required_ruby_version: !ruby/object:Gem::Requirement
76
+ requirements:
77
+ - - '>='
78
+ - !ruby/object:Gem::Version
79
+ version: '0'
80
+ required_rubygems_version: !ruby/object:Gem::Requirement
81
+ requirements:
82
+ - - '>='
83
+ - !ruby/object:Gem::Version
84
+ version: '0'
85
+ requirements: []
86
+ rubyforge_project:
87
+ rubygems_version: 2.0.2
88
+ signing_key:
89
+ specification_version: 4
90
+ summary: 'iterm2_escape provides a simple API to set: * tab chrome color * tab title
91
+ * window title'
92
+ test_files:
93
+ - spec/spec_helper.rb
94
+ - spec/tab_color_spec.rb
95
+ - spec/tab_title_spec.rb
96
+ - spec/version_spec.rb
97
+ - spec/writer_spec.rb