mutter 0.5.0 → 0.5.1
Sign up to get free protection for your applications and to get access to all the features.
- data/VERSION +1 -1
- data/lib/mutter.rb +13 -13
- data/lib/mutter/table.rb +19 -16
- data/mutter.gemspec +2 -2
- metadata +2 -2
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.5.
|
1
|
+
0.5.1
|
data/lib/mutter.rb
CHANGED
@@ -2,20 +2,20 @@
|
|
2
2
|
# Mutter — the tiny command-line interface library with lots of style~
|
3
3
|
#
|
4
4
|
|
5
|
-
require 'yaml'
|
5
|
+
require 'yaml'
|
6
6
|
|
7
|
-
$:.unshift File.dirname(__FILE__)
|
7
|
+
$:.unshift File.dirname(__FILE__)
|
8
8
|
|
9
|
-
require 'mutterer'
|
10
|
-
require 'indenter'
|
11
|
-
require 'table'
|
9
|
+
require 'mutter/mutterer'
|
10
|
+
require 'mutter/indenter'
|
11
|
+
require 'mutter/table'
|
12
12
|
require 'ext'
|
13
13
|
|
14
14
|
module Mutter
|
15
15
|
#
|
16
16
|
# ANSI color & transform codes
|
17
17
|
#
|
18
|
-
# If the value's an array,
|
18
|
+
# If the value's an array,
|
19
19
|
# [0] is the start code
|
20
20
|
# and [1] is the end code.
|
21
21
|
#
|
@@ -38,27 +38,27 @@ module Mutter
|
|
38
38
|
:reset => 39
|
39
39
|
}
|
40
40
|
}
|
41
|
-
|
41
|
+
|
42
42
|
def self.indenter tab
|
43
43
|
Indenter.new tab
|
44
44
|
end
|
45
|
-
|
45
|
+
|
46
46
|
def self.say *args
|
47
47
|
new.say *args
|
48
48
|
end
|
49
|
-
|
49
|
+
|
50
50
|
def self.stylize *args
|
51
51
|
new.stylize *args
|
52
52
|
end
|
53
|
-
|
53
|
+
|
54
54
|
def self.process *args
|
55
55
|
new.process *args
|
56
56
|
end
|
57
|
-
|
57
|
+
|
58
58
|
def self.new *args
|
59
59
|
Mutterer.new(*args)
|
60
60
|
end
|
61
|
-
|
61
|
+
|
62
62
|
#
|
63
63
|
# Utility function, to make a block interruptible
|
64
64
|
#
|
@@ -71,4 +71,4 @@ module Mutter
|
|
71
71
|
end
|
72
72
|
end
|
73
73
|
alias :oo watch
|
74
|
-
end
|
74
|
+
end
|
data/lib/mutter/table.rb
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
module Mutter
|
2
2
|
class Table
|
3
3
|
attr_accessor :rows, :columns
|
4
|
-
|
4
|
+
|
5
5
|
DefaultTable = {
|
6
6
|
:delimiter => " ",
|
7
7
|
:truncater => ".."
|
@@ -10,43 +10,46 @@ module Mutter
|
|
10
10
|
:align => :left,
|
11
11
|
:style => []
|
12
12
|
}
|
13
|
-
|
13
|
+
|
14
14
|
def initialize options = {}, &blk
|
15
15
|
@columns, @rows = [], []
|
16
16
|
@options = DefaultTable.merge options
|
17
|
-
|
17
|
+
|
18
|
+
instance_eval(&blk) if (@fixed = block_given?)
|
18
19
|
end
|
19
|
-
|
20
|
+
|
21
|
+
def fixed?; @fixed end
|
22
|
+
|
20
23
|
def column options = {}
|
21
24
|
@columns << DefaultColumn.merge(options)
|
22
25
|
end
|
23
|
-
|
26
|
+
|
24
27
|
def << row
|
25
|
-
if row.size > @columns.size
|
26
|
-
raise ArgumentError,
|
28
|
+
if row.size > @columns.size && fixed?
|
29
|
+
raise ArgumentError,
|
27
30
|
"row size is #{row.size} but I only have #{@columns.size} columns"
|
28
31
|
else
|
29
32
|
@rows << row
|
30
33
|
end
|
31
34
|
end
|
32
|
-
|
35
|
+
|
33
36
|
def render
|
34
37
|
# Create missing columns as needed
|
35
38
|
(@rows.map {|r| r.size }.max - @columns.size).times do
|
36
39
|
self.column
|
37
40
|
end
|
38
|
-
|
41
|
+
|
39
42
|
# Compute max column width
|
40
|
-
@columns.each_with_index do |col, i|
|
43
|
+
@columns.each_with_index do |col, i|
|
41
44
|
col[:_width] = @rows.map do |r|
|
42
45
|
r[i].to_s.length
|
43
46
|
end.max if @rows[i]
|
44
47
|
end
|
45
|
-
|
48
|
+
|
46
49
|
# print table
|
47
50
|
@rows.map do |row|
|
48
51
|
@columns.zip(row).map do |col, cell|
|
49
|
-
process(cell.to_s || "",
|
52
|
+
process(cell.to_s || "",
|
50
53
|
col[:width] || col[:_width],
|
51
54
|
col[:align],
|
52
55
|
col[:style])
|
@@ -54,18 +57,18 @@ module Mutter
|
|
54
57
|
end
|
55
58
|
end
|
56
59
|
alias :to_a render
|
57
|
-
|
60
|
+
|
58
61
|
def to_s
|
59
62
|
render.join("\n")
|
60
63
|
end
|
61
|
-
|
64
|
+
|
62
65
|
def print
|
63
66
|
puts render
|
64
67
|
end
|
65
|
-
|
68
|
+
|
66
69
|
def process str, length = nil, align = :left, style = []
|
67
70
|
length ||= str.length
|
68
|
-
|
71
|
+
|
69
72
|
if str.length > length
|
70
73
|
str[0...(length - @options[:truncater].length)] + @options[:truncater]
|
71
74
|
else
|
data/mutter.gemspec
CHANGED
@@ -5,11 +5,11 @@
|
|
5
5
|
|
6
6
|
Gem::Specification.new do |s|
|
7
7
|
s.name = %q{mutter}
|
8
|
-
s.version = "0.5.
|
8
|
+
s.version = "0.5.1"
|
9
9
|
|
10
10
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
11
|
s.authors = ["cloudhead"]
|
12
|
-
s.date = %q{2009-11-
|
12
|
+
s.date = %q{2009-11-25}
|
13
13
|
s.description = %q{the tiny command-line interface library with lots of style}
|
14
14
|
s.email = %q{self@cloudhead.net}
|
15
15
|
s.extra_rdoc_files = [
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: mutter
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.5.
|
4
|
+
version: 0.5.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- cloudhead
|
@@ -9,7 +9,7 @@ autorequire:
|
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
11
|
|
12
|
-
date: 2009-11-
|
12
|
+
date: 2009-11-25 00:00:00 -05:00
|
13
13
|
default_executable:
|
14
14
|
dependencies: []
|
15
15
|
|