hirb 0.3.3 → 0.3.4
Sign up to get free protection for your applications and to get access to all the features.
- data/CHANGELOG.rdoc +5 -0
- data/lib/bond/completions/hirb.rb +2 -1
- data/lib/hirb/formatter.rb +2 -2
- data/lib/hirb/menu.rb +5 -1
- data/lib/hirb/util.rb +5 -3
- data/lib/hirb/version.rb +1 -1
- data/lib/hirb/view.rb +2 -2
- data/test/console_test.rb +19 -2
- data/test/formatter_test.rb +9 -2
- data/test/menu_test.rb +10 -0
- metadata +4 -4
data/CHANGELOG.rdoc
CHANGED
@@ -1,3 +1,8 @@
|
|
1
|
+
== 0.3.4
|
2
|
+
* Added auto format of array-like objects i.e. ActiveRecord::Relation and Set.
|
3
|
+
* Fixed bug when Hirb::Console#table is used without Hirb enabled.
|
4
|
+
* Fixed bug when hirb is running within cron and uses tput.
|
5
|
+
|
1
6
|
== 0.3.3
|
2
7
|
* Added ignore_errors option to ignore view errors and continue with original view.
|
3
8
|
* Added support for array menu items.
|
@@ -10,5 +10,6 @@ complete(:method=>"Hirb::Helpers::Tree.render") {
|
|
10
10
|
%w{type validate indent limit description multi_line_nodes value_method children_method}
|
11
11
|
}
|
12
12
|
complete(:methods=>%w{Hirb::Menu.render menu}) {
|
13
|
-
%w{helper_class prompt ask directions readline two_d default_field action multi_action
|
13
|
+
%w{helper_class prompt ask directions readline two_d default_field action multi_action} +
|
14
|
+
%w{action_object command reopen}
|
14
15
|
}
|
data/lib/hirb/formatter.rb
CHANGED
@@ -75,7 +75,7 @@ module Hirb
|
|
75
75
|
end
|
76
76
|
|
77
77
|
def determine_output_class(output)
|
78
|
-
output.
|
78
|
+
output.respond_to?(:to_a) ? Array(output)[0].class : output.class
|
79
79
|
end
|
80
80
|
|
81
81
|
def call_output_method(output_method, output)
|
@@ -113,4 +113,4 @@ module Hirb
|
|
113
113
|
end
|
114
114
|
#:startdoc:
|
115
115
|
end
|
116
|
-
end
|
116
|
+
end
|
data/lib/hirb/menu.rb
CHANGED
@@ -32,6 +32,8 @@ module Hirb
|
|
32
32
|
# [*:multi_action*] Execute action menu multiple times iterating over the menu choices. Default is false.
|
33
33
|
# [*:action_object*] Object that takes method/command calls. Default is main.
|
34
34
|
# [*:command*] Default method/command to call when no command given.
|
35
|
+
# [*:reopen*] Reopens $stdin with given file or with /dev/tty when set to true. Use when
|
36
|
+
# $stdin is already reading in piped data.
|
35
37
|
# Examples:
|
36
38
|
# >> extend Hirb::Console
|
37
39
|
# => self
|
@@ -47,6 +49,7 @@ module Hirb
|
|
47
49
|
def initialize(options={})
|
48
50
|
@options = {:helper_class=>Hirb::Helpers::AutoTable, :prompt=>"Choose: ", :ask=>true,
|
49
51
|
:directions=>true}.merge options
|
52
|
+
@options[:reopen] = '/dev/tty' if @options[:reopen] == true
|
50
53
|
end
|
51
54
|
|
52
55
|
def render(output, &block)
|
@@ -60,6 +63,7 @@ module Hirb
|
|
60
63
|
def get_input
|
61
64
|
prompt = pre_prompt + @options[:prompt]
|
62
65
|
prompt = DIRECTIONS+"\n"+prompt if @options[:directions]
|
66
|
+
$stdin.reopen @options[:reopen] if @options[:reopen]
|
63
67
|
|
64
68
|
if @options[:readline] && readline_loads?
|
65
69
|
get_readline_input(prompt)
|
@@ -214,4 +218,4 @@ module Hirb
|
|
214
218
|
end
|
215
219
|
#:startdoc:
|
216
220
|
end
|
217
|
-
end
|
221
|
+
end
|
data/lib/hirb/util.rb
CHANGED
@@ -61,10 +61,12 @@ module Hirb
|
|
61
61
|
def detect_terminal_size
|
62
62
|
if (ENV['COLUMNS'] =~ /^\d+$/) && (ENV['LINES'] =~ /^\d+$/)
|
63
63
|
[ENV['COLUMNS'].to_i, ENV['LINES'].to_i]
|
64
|
-
elsif (RUBY_PLATFORM =~ /java/ || !STDIN.tty?) && command_exists?('tput')
|
64
|
+
elsif (RUBY_PLATFORM =~ /java/ || (!STDIN.tty? && ENV['TERM'])) && command_exists?('tput')
|
65
65
|
[`tput cols`.to_i, `tput lines`.to_i]
|
66
|
+
elsif STDIN.tty? && command_exists?('stty')
|
67
|
+
`stty size`.scan(/\d+/).map { |s| s.to_i }.reverse
|
66
68
|
else
|
67
|
-
|
69
|
+
nil
|
68
70
|
end
|
69
71
|
rescue
|
70
72
|
nil
|
@@ -91,4 +93,4 @@ module Hirb
|
|
91
93
|
File::ALT_SEPARATOR ? "C:/" : "/"
|
92
94
|
end
|
93
95
|
end
|
94
|
-
end
|
96
|
+
end
|
data/lib/hirb/version.rb
CHANGED
data/lib/hirb/view.rb
CHANGED
@@ -154,12 +154,12 @@ module Hirb
|
|
154
154
|
|
155
155
|
# Current console width
|
156
156
|
def width
|
157
|
-
config ? config[:width] : DEFAULT_WIDTH
|
157
|
+
config && config[:width] ? config[:width] : DEFAULT_WIDTH
|
158
158
|
end
|
159
159
|
|
160
160
|
# Current console height
|
161
161
|
def height
|
162
|
-
config ? config[:height] : DEFAULT_HEIGHT
|
162
|
+
config && config[:height] ? config[:height] : DEFAULT_HEIGHT
|
163
163
|
end
|
164
164
|
|
165
165
|
# Current formatter config, storing a hash of all static views
|
data/test/console_test.rb
CHANGED
@@ -1,7 +1,24 @@
|
|
1
1
|
require File.join(File.dirname(__FILE__), 'test_helper')
|
2
2
|
|
3
|
-
describe "
|
4
|
-
it "
|
3
|
+
describe "Console" do
|
4
|
+
it "#table is called without Hirb enabled" do
|
5
|
+
extend Hirb::Console
|
6
|
+
reset_config
|
7
|
+
expected_table = <<-TABLE.unindent
|
8
|
+
+-------+
|
9
|
+
| value |
|
10
|
+
+-------+
|
11
|
+
| 5 |
|
12
|
+
| 3 |
|
13
|
+
+-------+
|
14
|
+
2 rows in set
|
15
|
+
TABLE
|
16
|
+
capture_stdout {
|
17
|
+
table([5,3], :fields=>[:to_s])
|
18
|
+
}.should == expected_table +"\n"
|
19
|
+
end
|
20
|
+
|
21
|
+
it ".render_output sets config if it wasn't before" do
|
5
22
|
reset_config
|
6
23
|
View.expects(:render_output)
|
7
24
|
Console.render_output('blah')
|
data/test/formatter_test.rb
CHANGED
@@ -84,7 +84,7 @@ describe "Formatter" do
|
|
84
84
|
before_all {
|
85
85
|
eval %[module ::Commify
|
86
86
|
def self.render(strings)
|
87
|
-
strings =
|
87
|
+
strings = Array(strings)
|
88
88
|
strings.map {|e| e.split('').join(',')}.join("\n")
|
89
89
|
end
|
90
90
|
end]
|
@@ -112,11 +112,18 @@ describe "Formatter" do
|
|
112
112
|
view_output('dude')
|
113
113
|
end
|
114
114
|
|
115
|
-
it "formats
|
115
|
+
it "formats arrays" do
|
116
116
|
enable_with_output "String"=>{:class=>"Commify"}
|
117
117
|
render_method.expects(:call).with('d,u,d,e')
|
118
118
|
view_output(['dude'])
|
119
119
|
end
|
120
|
+
|
121
|
+
it "formats array-like objects" do
|
122
|
+
enable_with_output "String"=>{:class=>"Commify"}
|
123
|
+
render_method.expects(:call).with('d,u,d,e')
|
124
|
+
require 'set'
|
125
|
+
view_output Set.new(['dude'])
|
126
|
+
end
|
120
127
|
|
121
128
|
it "formats with options option" do
|
122
129
|
eval "module ::Blahify; def self.render(*args); end; end"
|
data/test/menu_test.rb
CHANGED
@@ -98,6 +98,16 @@ describe "Menu" do
|
|
98
98
|
menu_input('blah')
|
99
99
|
capture_stdout { menu([1], :directions=>false) }.should.not =~ /range.*all/
|
100
100
|
end
|
101
|
+
|
102
|
+
it "with true reopen option reopens" do
|
103
|
+
$stdin.expects(:reopen).with('/dev/tty')
|
104
|
+
basic_menu [1], :reopen=>true
|
105
|
+
end
|
106
|
+
|
107
|
+
it "with string reopen option reopens" do
|
108
|
+
$stdin.expects(:reopen).with('/dev/blah')
|
109
|
+
basic_menu [1], :reopen=>'/dev/blah'
|
110
|
+
end
|
101
111
|
end
|
102
112
|
|
103
113
|
def two_d_menu(options={})
|
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: hirb
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
4
|
+
hash: 27
|
5
5
|
prerelease: false
|
6
6
|
segments:
|
7
7
|
- 0
|
8
8
|
- 3
|
9
|
-
-
|
10
|
-
version: 0.3.
|
9
|
+
- 4
|
10
|
+
version: 0.3.4
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- Gabriel Horner
|
@@ -15,7 +15,7 @@ autorequire:
|
|
15
15
|
bindir: bin
|
16
16
|
cert_chain: []
|
17
17
|
|
18
|
-
date: 2010-
|
18
|
+
date: 2010-09-13 00:00:00 -04:00
|
19
19
|
default_executable:
|
20
20
|
dependencies:
|
21
21
|
- !ruby/object:Gem::Dependency
|