terminal-size 0.0.1
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.
- data/Gemfile +5 -0
- data/Gemfile.lock +156 -0
- data/Guardfile +2 -0
- data/LICENSE.txt +1 -0
- data/README.md +30 -0
- data/Rakefile +6 -0
- data/lib/terminal-size.rb +59 -0
- data/terminal-size.gemspec +15 -0
- data/test/real-life-ioctl-return-value +0 -0
- data/test/terminal-size_test.rb +51 -0
- data/test/test_helper.rb +28 -0
- metadata +61 -0
data/Gemfile
ADDED
data/Gemfile.lock
ADDED
@@ -0,0 +1,156 @@
|
|
1
|
+
GIT
|
2
|
+
remote: git://github.com/ConradIrwin/pry-rescue.git
|
3
|
+
revision: 6a31294b730f8caab8b0998eb1e9ee0211909f48
|
4
|
+
branch: feature/kill-pry-rescue
|
5
|
+
specs:
|
6
|
+
pry-rescue (0.14)
|
7
|
+
interception (>= 0.3)
|
8
|
+
pry
|
9
|
+
|
10
|
+
GEM
|
11
|
+
remote: http://rubygems.org/
|
12
|
+
specs:
|
13
|
+
ansi (1.4.3)
|
14
|
+
awesome_print (1.1.0)
|
15
|
+
beg (0.0.3)
|
16
|
+
guard
|
17
|
+
binding_of_caller (0.6.8)
|
18
|
+
bond (0.4.3)
|
19
|
+
childprocess (0.3.6)
|
20
|
+
ffi (~> 1.0, >= 1.0.6)
|
21
|
+
coderay (1.0.8)
|
22
|
+
columnize (0.3.6)
|
23
|
+
debugger (1.2.3)
|
24
|
+
columnize (>= 0.3.1)
|
25
|
+
debugger-linecache (~> 1.1.1)
|
26
|
+
debugger-ruby_core_source (~> 1.1.5)
|
27
|
+
debugger-linecache (1.1.2)
|
28
|
+
debugger-ruby_core_source (>= 1.1.1)
|
29
|
+
debugger-ruby_core_source (1.1.6)
|
30
|
+
diff-lcs (1.1.3)
|
31
|
+
diffy (2.1.0)
|
32
|
+
eventmachine (1.0.0)
|
33
|
+
ffi (1.2.0)
|
34
|
+
grit (2.5.0)
|
35
|
+
diff-lcs (~> 1.1)
|
36
|
+
mime-types (~> 1.15)
|
37
|
+
posix-spawn (~> 0.3.6)
|
38
|
+
guard (1.6.1)
|
39
|
+
listen (>= 0.6.0)
|
40
|
+
lumberjack (>= 1.0.2)
|
41
|
+
pry (>= 0.9.10)
|
42
|
+
thor (>= 0.14.6)
|
43
|
+
guard-bundler (1.0.0)
|
44
|
+
bundler (~> 1.0)
|
45
|
+
guard (~> 1.1)
|
46
|
+
guard-spork (1.4.0)
|
47
|
+
childprocess (>= 0.2.3)
|
48
|
+
guard (>= 1.1)
|
49
|
+
spork (>= 0.8.4)
|
50
|
+
guard-sporkminitest (0.0.1)
|
51
|
+
guard
|
52
|
+
guard-spork
|
53
|
+
rb-fsevent
|
54
|
+
rb-inotify
|
55
|
+
spork-minitest
|
56
|
+
highline (1.6.15)
|
57
|
+
interception (0.3)
|
58
|
+
jist (1.3.0)
|
59
|
+
json
|
60
|
+
json (1.7.5)
|
61
|
+
listen (0.6.0)
|
62
|
+
lumberjack (1.0.2)
|
63
|
+
method_source (0.8.1)
|
64
|
+
mime-types (1.19)
|
65
|
+
minitest (4.3.3)
|
66
|
+
nokogiri (1.5.6)
|
67
|
+
posix-spawn (0.3.6)
|
68
|
+
pry (0.9.10)
|
69
|
+
coderay (~> 1.0.5)
|
70
|
+
method_source (~> 0.8)
|
71
|
+
slop (~> 3.3.1)
|
72
|
+
pry-awesome_print (9.6.5)
|
73
|
+
awesome_print (~> 1.1.0)
|
74
|
+
pry-de (0.1.0)
|
75
|
+
guard
|
76
|
+
pry-full
|
77
|
+
pry-debugger (0.2.1)
|
78
|
+
debugger (~> 1.2.0)
|
79
|
+
pry (~> 0.9.10)
|
80
|
+
pry-developer_tools (0.1.1)
|
81
|
+
pry (>= 0.9.8.pre, < 0.11)
|
82
|
+
pry-doc (0.4.4)
|
83
|
+
pry (>= 0.9.9.6)
|
84
|
+
yard (~> 0.8.1)
|
85
|
+
pry-docmore (0.0.3)
|
86
|
+
pry
|
87
|
+
pry-doc
|
88
|
+
pry-editline (1.1.1)
|
89
|
+
pry-exception_explorer (0.1.9)
|
90
|
+
pry-stack_explorer (>= 0.3.9)
|
91
|
+
pry-full (1.0)
|
92
|
+
bond
|
93
|
+
jist
|
94
|
+
pry-awesome_print
|
95
|
+
pry-debugger
|
96
|
+
pry-developer_tools
|
97
|
+
pry-doc
|
98
|
+
pry-docmore
|
99
|
+
pry-editline
|
100
|
+
pry-exception_explorer (= 0.1.9)
|
101
|
+
pry-git
|
102
|
+
pry-highlight
|
103
|
+
pry-pretty-numeric
|
104
|
+
pry-remote-em
|
105
|
+
pry-rescue
|
106
|
+
pry-stack_explorer
|
107
|
+
pry-syntax-hacks
|
108
|
+
pry-theme
|
109
|
+
pry-git (0.2.3)
|
110
|
+
diffy
|
111
|
+
grit
|
112
|
+
pry (>= 0.9.8)
|
113
|
+
pry-highlight (0.0.1)
|
114
|
+
coderay
|
115
|
+
json
|
116
|
+
nokogiri
|
117
|
+
pry
|
118
|
+
pry-pretty-numeric (0.1.1)
|
119
|
+
pry
|
120
|
+
pry-remote-em (0.7.3)
|
121
|
+
eventmachine
|
122
|
+
highline
|
123
|
+
pry (~> 0.9)
|
124
|
+
pry-stack_explorer (0.4.7)
|
125
|
+
binding_of_caller (~> 0.6.8)
|
126
|
+
pry-syntax-hacks (0.0.6)
|
127
|
+
pry (>= 0.9.8)
|
128
|
+
pry-theme (0.1.3)
|
129
|
+
json
|
130
|
+
rake (10.0.3)
|
131
|
+
rb-fsevent (0.9.2)
|
132
|
+
rb-inotify (0.8.8)
|
133
|
+
ffi (>= 0.5.0)
|
134
|
+
slop (3.3.3)
|
135
|
+
spork (0.9.2)
|
136
|
+
spork-minitest (0.0.3)
|
137
|
+
spork
|
138
|
+
thor (0.16.0)
|
139
|
+
turn (0.9.6)
|
140
|
+
ansi
|
141
|
+
working (0.0.4)
|
142
|
+
beg
|
143
|
+
guard-bundler
|
144
|
+
guard-sporkminitest
|
145
|
+
minitest
|
146
|
+
pry-de
|
147
|
+
rake
|
148
|
+
turn
|
149
|
+
yard (0.8.3)
|
150
|
+
|
151
|
+
PLATFORMS
|
152
|
+
ruby
|
153
|
+
|
154
|
+
DEPENDENCIES
|
155
|
+
pry-rescue!
|
156
|
+
working
|
data/Guardfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
Copyleft (ↄ) 2012 ☈king — Absolutely CC0 / Public Domain / Whateverness.
|
data/README.md
ADDED
@@ -0,0 +1,30 @@
|
|
1
|
+
# Terminal.size
|
2
|
+
|
3
|
+
A tiny gem to accomplish a simple task: Determining the terminal size.
|
4
|
+
|
5
|
+
One of the guarantees of this project is that it will always be exactly one
|
6
|
+
file: `lib/terminal-size/terminal.rb`
|
7
|
+
|
8
|
+
So, if you want to come up with some automated way to slurp that into your
|
9
|
+
codebase, it shouldn't break (and this would be better than a
|
10
|
+
not-easily-updated Copy & Paste). I'm kicking around the idea of using this as
|
11
|
+
an example of an automatic, namespaced fat-pack trick, but we'll see if that's
|
12
|
+
really necessary.
|
13
|
+
|
14
|
+
## Installation
|
15
|
+
|
16
|
+
Add this line to your application's Gemfile:
|
17
|
+
|
18
|
+
gem 'terminal-size'
|
19
|
+
|
20
|
+
And then execute:
|
21
|
+
|
22
|
+
$ bundle
|
23
|
+
|
24
|
+
Or install it yourself as:
|
25
|
+
|
26
|
+
$ gem install terminal-size
|
27
|
+
|
28
|
+
## Usage
|
29
|
+
|
30
|
+
p Terminal.size
|
data/Rakefile
ADDED
@@ -0,0 +1,59 @@
|
|
1
|
+
class Terminal
|
2
|
+
class Size; VERSION = '0.0.1' end
|
3
|
+
class << self
|
4
|
+
def size
|
5
|
+
size_via_low_level_ioctl or size_via_stty or nil
|
6
|
+
end
|
7
|
+
def size!; size or _height_width_hash_from 25, 80 end
|
8
|
+
|
9
|
+
# These are experimental
|
10
|
+
def resize direction, magnitude
|
11
|
+
tmux 'resize-pane', "-#{direction}", magnitude
|
12
|
+
end
|
13
|
+
|
14
|
+
def tmux *cmd
|
15
|
+
system 'tmux', *(cmd.map &:to_s)
|
16
|
+
end
|
17
|
+
|
18
|
+
IOCTL_INPUT_BUF = "\x00"*8
|
19
|
+
def size_via_low_level_ioctl
|
20
|
+
# Thanks to runpaint for the general approach to this
|
21
|
+
return unless $stdin.respond_to? :ioctl
|
22
|
+
code = tiocgwinsz_value_for RUBY_PLATFORM
|
23
|
+
return unless code
|
24
|
+
buf = IOCTL_INPUT_BUF.dup
|
25
|
+
return unless $stdout.ioctl(code, buf).zero?
|
26
|
+
return if IOCTL_INPUT_BUF == buf
|
27
|
+
got = buf.unpack('S4')[0..1]
|
28
|
+
_height_width_hash_from *got
|
29
|
+
rescue
|
30
|
+
nil
|
31
|
+
end
|
32
|
+
|
33
|
+
# This is as reported by <sys/ioctl.h>
|
34
|
+
# Hard-coding because it seems like overkll to acutally involve C for this.
|
35
|
+
TIOCGWINSZ = {
|
36
|
+
/linux/ => 0x5413,
|
37
|
+
/darwin/ => 0x40087468, # thanks to brandon@brandon.io for the lookup!
|
38
|
+
}
|
39
|
+
def tiocgwinsz_value_for platform
|
40
|
+
TIOCGWINSZ.each do |k,v|
|
41
|
+
return v if platform[k]
|
42
|
+
end
|
43
|
+
nil
|
44
|
+
end
|
45
|
+
|
46
|
+
def size_via_stty
|
47
|
+
ints = `stty size`.scan(/\d+/).map &:to_i
|
48
|
+
_height_width_hash_from *ints
|
49
|
+
rescue
|
50
|
+
nil
|
51
|
+
end
|
52
|
+
|
53
|
+
private
|
54
|
+
def _height_width_hash_from *dimensions
|
55
|
+
{ height: dimensions[0], width: dimensions[1] }
|
56
|
+
end
|
57
|
+
|
58
|
+
end
|
59
|
+
end
|
@@ -0,0 +1,15 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
$:.unshift './lib'
|
3
|
+
require 'terminal-size'
|
4
|
+
|
5
|
+
Gem::Specification.new do |gem|
|
6
|
+
gem.name = 'terminal-size'
|
7
|
+
gem.version = Terminal::Size::VERSION
|
8
|
+
gem.authors = %w(☈king Norrin)
|
9
|
+
gem.email = ['rking-terminal-size@sharpsaw.org']
|
10
|
+
gem.description = gem.summary = %q{Terminal.size ⇒ {columns: 80, rows: 25}}
|
11
|
+
gem.homepage = 'https://github.com/rking/terminal-size'
|
12
|
+
gem.files = `git ls-files`.split($/)
|
13
|
+
gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
|
14
|
+
gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
|
15
|
+
end
|
Binary file
|
@@ -0,0 +1,51 @@
|
|
1
|
+
require './test/test_helper'
|
2
|
+
require 'terminal-size'
|
3
|
+
class TerminalTest < MiniTest::Unit::TestCase
|
4
|
+
DEFAULT_SIZE = {width: 80, height: 25}
|
5
|
+
def test_simulating_windows
|
6
|
+
class << $stdout
|
7
|
+
alias_method :actual_respond_to?, :respond_to?
|
8
|
+
end
|
9
|
+
brb_path = ENV['PATH']
|
10
|
+
$stdin.stub :respond_to?, -> m { :ioctl != m and actual_respond_to m } do
|
11
|
+
refute Terminal.size_via_low_level_ioctl
|
12
|
+
ENV['PATH'] = ''
|
13
|
+
refute Terminal.size_via_stty
|
14
|
+
refute Terminal.size
|
15
|
+
assert_equal DEFAULT_SIZE, Terminal.size!
|
16
|
+
end
|
17
|
+
ensure
|
18
|
+
ENV['PATH'] = brb_path
|
19
|
+
end
|
20
|
+
|
21
|
+
# This junky thing is an in-real-life result of a TIOCGWINSZ call
|
22
|
+
FAKE_IOCTL_RESULT = File.read 'test/real-life-ioctl-return-value'
|
23
|
+
def test_ioctl_for_unix
|
24
|
+
refute_equal \
|
25
|
+
Terminal.tiocgwinsz_value_for('linux'),
|
26
|
+
Terminal.tiocgwinsz_value_for('darwin')
|
27
|
+
expected = {width: 133, height: 80}
|
28
|
+
$stdout.stub :ioctl, -> num, buf { buf.replace FAKE_IOCTL_RESULT; 0 } do
|
29
|
+
assert_equal expected, Terminal.size_via_low_level_ioctl
|
30
|
+
end
|
31
|
+
Terminal.stub :`, '80 133' do
|
32
|
+
assert_equal expected, Terminal.size_via_stty
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
36
|
+
def test_integration_using_tmux
|
37
|
+
skip 'This test must be run from within tmux (with a split-window -h)' \
|
38
|
+
unless ENV['TMUX']
|
39
|
+
# TODO: figure out how to get this to work if not already in a horizontal
|
40
|
+
# split, e.g.:
|
41
|
+
# system 'tmux split-window -h'
|
42
|
+
# Or maybe: tmux list-panes
|
43
|
+
before = Terminal.size
|
44
|
+
Terminal.resize :L, 1
|
45
|
+
after = Terminal.size
|
46
|
+
assert_equal before[:width]-1, after[:width]
|
47
|
+
assert_equal before[:width]-1, after[:width]
|
48
|
+
ensure
|
49
|
+
Terminal.resize :R, 1
|
50
|
+
end
|
51
|
+
end
|
data/test/test_helper.rb
ADDED
@@ -0,0 +1,28 @@
|
|
1
|
+
# If on Rails:
|
2
|
+
# ENV['RAILS_ENV'] = 'test'
|
3
|
+
# require File.expand_path('../../config/environment', __FILE_)
|
4
|
+
# def reload!
|
5
|
+
# puts "[Performing .reload!]"
|
6
|
+
# ActionDispatch::Reloader.cleanup!
|
7
|
+
# ActionDispatch::Reloader.prepare!
|
8
|
+
# end
|
9
|
+
|
10
|
+
require 'spork'
|
11
|
+
require 'minitest/autorun'
|
12
|
+
require 'pry-rescue/minitest'
|
13
|
+
$:.unshift './lib'
|
14
|
+
|
15
|
+
require 'turn'
|
16
|
+
Turn.config do |c|
|
17
|
+
c.format = :pretty
|
18
|
+
end
|
19
|
+
|
20
|
+
puts "[test_helper.rb toplevel running]"
|
21
|
+
Spork.prefork do
|
22
|
+
puts "[Spork.prefork running]"
|
23
|
+
end
|
24
|
+
Spork.each_run do
|
25
|
+
puts "[Spork.each_run running]"
|
26
|
+
# TODO: verify that this helps (Rails)
|
27
|
+
# reload!
|
28
|
+
end
|
metadata
ADDED
@@ -0,0 +1,61 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: terminal-size
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
prerelease:
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- ☈king
|
9
|
+
- Norrin
|
10
|
+
autorequire:
|
11
|
+
bindir: bin
|
12
|
+
cert_chain: []
|
13
|
+
date: 2012-12-29 00:00:00.000000000 Z
|
14
|
+
dependencies: []
|
15
|
+
description: ! 'Terminal.size ⇒ {columns: 80, rows: 25}'
|
16
|
+
email:
|
17
|
+
- rking-terminal-size@sharpsaw.org
|
18
|
+
executables: []
|
19
|
+
extensions: []
|
20
|
+
extra_rdoc_files: []
|
21
|
+
files:
|
22
|
+
- Gemfile
|
23
|
+
- Gemfile.lock
|
24
|
+
- Guardfile
|
25
|
+
- LICENSE.txt
|
26
|
+
- README.md
|
27
|
+
- Rakefile
|
28
|
+
- lib/terminal-size.rb
|
29
|
+
- terminal-size.gemspec
|
30
|
+
- test/real-life-ioctl-return-value
|
31
|
+
- test/terminal-size_test.rb
|
32
|
+
- test/test_helper.rb
|
33
|
+
homepage: https://github.com/rking/terminal-size
|
34
|
+
licenses: []
|
35
|
+
post_install_message:
|
36
|
+
rdoc_options: []
|
37
|
+
require_paths:
|
38
|
+
- lib
|
39
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
40
|
+
none: false
|
41
|
+
requirements:
|
42
|
+
- - ! '>='
|
43
|
+
- !ruby/object:Gem::Version
|
44
|
+
version: '0'
|
45
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
46
|
+
none: false
|
47
|
+
requirements:
|
48
|
+
- - ! '>='
|
49
|
+
- !ruby/object:Gem::Version
|
50
|
+
version: '0'
|
51
|
+
requirements: []
|
52
|
+
rubyforge_project:
|
53
|
+
rubygems_version: 1.8.24
|
54
|
+
signing_key:
|
55
|
+
specification_version: 3
|
56
|
+
summary: ! 'Terminal.size ⇒ {columns: 80, rows: 25}'
|
57
|
+
test_files:
|
58
|
+
- test/real-life-ioctl-return-value
|
59
|
+
- test/terminal-size_test.rb
|
60
|
+
- test/test_helper.rb
|
61
|
+
has_rdoc:
|