epitools 0.5.12 → 0.5.13
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/VERSION +1 -1
- data/epitools.gemspec +2 -2
- data/lib/epitools/core_ext/numbers.rb +23 -0
- data/lib/epitools/core_ext/object.rb +0 -49
- data/lib/epitools/minimal.rb +49 -0
- data/lib/epitools/term.rb +21 -8
- data/lib/epitools/wm.rb +4 -4
- data/spec/core_ext_spec.rb +7 -0
- data/spec/term_spec.rb +3 -0
- metadata +2 -2
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.5.
|
1
|
+
0.5.13
|
data/epitools.gemspec
CHANGED
@@ -5,11 +5,11 @@
|
|
5
5
|
|
6
6
|
Gem::Specification.new do |s|
|
7
7
|
s.name = "epitools"
|
8
|
-
s.version = "0.5.
|
8
|
+
s.version = "0.5.13"
|
9
9
|
|
10
10
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
11
|
s.authors = ["epitron"]
|
12
|
-
s.date = "2012-11-
|
12
|
+
s.date = "2012-11-13"
|
13
13
|
s.description = "Miscellaneous utility libraries to make my life easier."
|
14
14
|
s.email = "chris@ill-logic.com"
|
15
15
|
s.extra_rdoc_files = [
|
@@ -99,6 +99,29 @@ class Numeric
|
|
99
99
|
Math.log(self, n)
|
100
100
|
end
|
101
101
|
|
102
|
+
|
103
|
+
BYTE_SIZE_TABLE = {
|
104
|
+
# power # units
|
105
|
+
0 => "",
|
106
|
+
1 => "KB",
|
107
|
+
2 => "MB",
|
108
|
+
3 => "GB",
|
109
|
+
4 => "TB",
|
110
|
+
5 => "PB",
|
111
|
+
6 => "EB",
|
112
|
+
7 => "ZB",
|
113
|
+
8 => "YB",
|
114
|
+
}
|
115
|
+
|
116
|
+
def human_bytes(decimals=0)
|
117
|
+
power = self.log(1024).floor
|
118
|
+
base = 1024.0 ** power
|
119
|
+
units = BYTE_SIZE_TABLE[power]
|
120
|
+
"#{(self / base).round(decimals)}#{units}"
|
121
|
+
end
|
122
|
+
|
123
|
+
alias_method :human_size, :human_bytes
|
124
|
+
|
102
125
|
end
|
103
126
|
|
104
127
|
|
@@ -44,55 +44,6 @@ class Object
|
|
44
44
|
end
|
45
45
|
end
|
46
46
|
|
47
|
-
#
|
48
|
-
# Turns block-accepting iterator methods (eg: each) into methods that return an
|
49
|
-
# Enumerator when they're called called without a block.
|
50
|
-
#
|
51
|
-
# It can transform many methods at once (eg: `enumerable :each, :all_people`).
|
52
|
-
#
|
53
|
-
# Example:
|
54
|
-
#
|
55
|
-
# def lots_of_stuff
|
56
|
-
# @stuff.each { |thing| yield thing }
|
57
|
-
# end
|
58
|
-
#
|
59
|
-
# enumerable :lots_of_stuff
|
60
|
-
#
|
61
|
-
# Now you can use it like an Enumerator: object.lots_of_stuff.with_index.sort.zip(99..1000)
|
62
|
-
#
|
63
|
-
def self.enumerable *meths
|
64
|
-
meths.each do |meth|
|
65
|
-
alias_method "#{meth}_without_enumerator", meth
|
66
|
-
class_eval %{
|
67
|
-
def #{meth}(*args, &block)
|
68
|
-
return Enum.new(self, #{meth.inspect}, *args, &block) unless block_given?
|
69
|
-
#{meth}_without_enumerator(*args, &block)
|
70
|
-
end
|
71
|
-
}
|
72
|
-
end
|
73
|
-
end
|
74
|
-
alias_class_method :enumerator, :enumerable
|
75
|
-
|
76
|
-
#
|
77
|
-
# Instead of:
|
78
|
-
# if cookie_jar.include? cookie
|
79
|
-
# Now you can do:
|
80
|
-
# if cookie.in? cookie_jar
|
81
|
-
#
|
82
|
-
def in?(enum)
|
83
|
-
enum.include? self
|
84
|
-
end
|
85
|
-
|
86
|
-
#
|
87
|
-
# Instead of:
|
88
|
-
# @person ? @person.name : nil
|
89
|
-
# Now you can do:
|
90
|
-
# @person.try(:name)
|
91
|
-
#
|
92
|
-
def try(method, *args, &block)
|
93
|
-
send(method, *args, &block) if respond_to? method
|
94
|
-
end
|
95
|
-
|
96
47
|
#
|
97
48
|
# Serialize this object to a binary String, using Marshal.dump.
|
98
49
|
#
|
data/lib/epitools/minimal.rb
CHANGED
@@ -100,6 +100,55 @@ class Object
|
|
100
100
|
metaclass.send(:alias_method, dest, src)
|
101
101
|
end
|
102
102
|
|
103
|
+
#
|
104
|
+
# Turns block-accepting iterator methods (eg: each) into methods that return an
|
105
|
+
# Enumerator when they're called called without a block.
|
106
|
+
#
|
107
|
+
# It can transform many methods at once (eg: `enumerable :each, :all_people`).
|
108
|
+
#
|
109
|
+
# Example:
|
110
|
+
#
|
111
|
+
# def lots_of_stuff
|
112
|
+
# @stuff.each { |thing| yield thing }
|
113
|
+
# end
|
114
|
+
#
|
115
|
+
# enumerable :lots_of_stuff
|
116
|
+
#
|
117
|
+
# Now you can use it like an Enumerator: object.lots_of_stuff.with_index.sort.zip(99..1000)
|
118
|
+
#
|
119
|
+
def self.enumerable *meths
|
120
|
+
meths.each do |meth|
|
121
|
+
alias_method "#{meth}_without_enumerator", meth
|
122
|
+
class_eval %{
|
123
|
+
def #{meth}(*args, &block)
|
124
|
+
return Enum.new(self, #{meth.inspect}, *args, &block) unless block_given?
|
125
|
+
#{meth}_without_enumerator(*args, &block)
|
126
|
+
end
|
127
|
+
}
|
128
|
+
end
|
129
|
+
end
|
130
|
+
alias_class_method :enumerator, :enumerable
|
131
|
+
|
132
|
+
#
|
133
|
+
# Instead of:
|
134
|
+
# if cookie_jar.include? cookie
|
135
|
+
# Now you can do:
|
136
|
+
# if cookie.in? cookie_jar
|
137
|
+
#
|
138
|
+
def in?(enum)
|
139
|
+
enum.include? self
|
140
|
+
end
|
141
|
+
|
142
|
+
#
|
143
|
+
# Instead of:
|
144
|
+
# @person ? @person.name : nil
|
145
|
+
# Now you can do:
|
146
|
+
# @person.try(:name)
|
147
|
+
#
|
148
|
+
def try(method, *args, &block)
|
149
|
+
send(method, *args, &block) if respond_to? method
|
150
|
+
end
|
151
|
+
|
103
152
|
end
|
104
153
|
|
105
154
|
#
|
data/lib/epitools/term.rb
CHANGED
@@ -1,11 +1,24 @@
|
|
1
1
|
#require 'epitools'
|
2
2
|
|
3
|
+
require 'epitools/minimal'
|
4
|
+
require 'epitools/core_ext/string'
|
5
|
+
require 'io/console'
|
6
|
+
|
3
7
|
#
|
4
8
|
# Example usage:
|
5
9
|
# puts Term::Table[ (1..100).to_a ].horizontally #=> prints all the numbers, ordered across rows
|
6
10
|
# puts Term::Table[ (1..100).to_a ].vertically #=> prints all the numbers, ordered across columns
|
7
11
|
# puts Term::Table[ [[1,2], [3,4]] ] #=> prints the table that was supplied
|
8
12
|
#
|
13
|
+
# Term::Table.new do |t|
|
14
|
+
# t.row [...]
|
15
|
+
# t.rows[5] = [...]
|
16
|
+
# t.rows << [...]
|
17
|
+
# t.col []
|
18
|
+
# end.to_s
|
19
|
+
#
|
20
|
+
# table.compact.to_s #=> minimize the table's columns
|
21
|
+
#
|
9
22
|
module Term
|
10
23
|
|
11
24
|
extend self
|
@@ -16,10 +29,7 @@ module Term
|
|
16
29
|
# Return the [width,height] of the terminal.
|
17
30
|
#
|
18
31
|
def size
|
19
|
-
|
20
|
-
result = [Curses.cols, Curses.lines]
|
21
|
-
Curses.close_screen
|
22
|
-
result
|
32
|
+
STDIN.winsize.reverse
|
23
33
|
end
|
24
34
|
|
25
35
|
def width; size[0]; end
|
@@ -52,7 +62,7 @@ module Term
|
|
52
62
|
# eg: Table.new(elements, :sort=>:vertical).to_s
|
53
63
|
#
|
54
64
|
|
55
|
-
attr_accessor :border, :columns, :padding, :strip_color, :indent
|
65
|
+
attr_accessor :border, :columns, :padding, :strip_color, :indent, :width, :height
|
56
66
|
|
57
67
|
def self.[](data)
|
58
68
|
self.new(data)
|
@@ -72,13 +82,16 @@ module Term
|
|
72
82
|
@border = options[:border]
|
73
83
|
@columns = options[:columns]
|
74
84
|
@padding = options[:padding] || 1
|
85
|
+
|
86
|
+
# Update the terminal size
|
87
|
+
@width, @height = Term.size
|
75
88
|
end
|
76
89
|
|
77
90
|
def num_columns
|
78
91
|
return @columns if @columns
|
79
|
-
|
80
|
-
|
81
|
-
(
|
92
|
+
w = @width
|
93
|
+
w -= indent
|
94
|
+
(w-2) / (@max_size + @padding)
|
82
95
|
end
|
83
96
|
|
84
97
|
def num_rows
|
data/lib/epitools/wm.rb
CHANGED
@@ -363,16 +363,16 @@ module WM
|
|
363
363
|
temp = Tempfile.new("xse")
|
364
364
|
events = keys_to_events(keys)
|
365
365
|
|
366
|
-
p events
|
367
|
-
|
366
|
+
# p events
|
367
|
+
eventstring = events.map { |e| e + "\n" }.join("")
|
368
368
|
|
369
369
|
temp.write eventstring
|
370
370
|
temp.flush
|
371
371
|
temp.seek 0
|
372
|
-
p [:temp, temp.read]
|
372
|
+
# p [:temp, temp.read]
|
373
373
|
|
374
374
|
cmd = "xse", "-window", window_id, "-file", temp.path
|
375
|
-
p [:cmd, cmd]
|
375
|
+
# p [:cmd, cmd]
|
376
376
|
unless system(*cmd)
|
377
377
|
raise "Error: couldn't send key commands to 'xse'. (Is xsendevents installed?)"
|
378
378
|
end
|
data/spec/core_ext_spec.rb
CHANGED
@@ -165,6 +165,13 @@ describe Numeric do
|
|
165
165
|
(2**(4212.log(2))).round.should == 4212.0
|
166
166
|
end
|
167
167
|
|
168
|
+
it "human_sizes" do
|
169
|
+
1024.human_size.should == "1KB"
|
170
|
+
23984.human_size.should == "23KB"
|
171
|
+
12983128.human_size.should == "12MB"
|
172
|
+
32583128.human_size(2).should == "31.07MB"
|
173
|
+
end
|
174
|
+
|
168
175
|
end
|
169
176
|
|
170
177
|
describe String do
|
data/spec/term_spec.rb
CHANGED
@@ -16,6 +16,8 @@ describe Term do
|
|
16
16
|
#puts table.by_columns :border=>true
|
17
17
|
#puts "rows"
|
18
18
|
#puts table.by_rows
|
19
|
+
puts table.by_rows
|
20
|
+
|
19
21
|
table.by_columns.should_not be_nil
|
20
22
|
table.by_rows.should_not be_nil
|
21
23
|
|
@@ -23,6 +25,7 @@ describe Term do
|
|
23
25
|
|
24
26
|
table.by_columns.should_not be_nil
|
25
27
|
table.by_rows.should_not be_nil
|
28
|
+
|
26
29
|
end
|
27
30
|
|
28
31
|
it "tables nothing" do
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: epitools
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.5.
|
4
|
+
version: 0.5.13
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2012-11-
|
12
|
+
date: 2012-11-13 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: rspec
|