tree.rb 0.3.7 → 0.3.8

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.
@@ -0,0 +1,22 @@
1
+
2
+ <!DOCTYPE html>
3
+ <html lang="en">
4
+ <head>
5
+ <meta charset="utf-8">
6
+ <title>D3 Test</title>
7
+ <script type="text/javascript" src="../../d3/d3.v2.js"></script>
8
+ </head>
9
+ <body>
10
+ <script type="text/javascript">
11
+
12
+ var dataset = [ 5, 10, 15, 20, 25 ];
13
+
14
+ d3.select("body").selectAll("p")
15
+ .data(dataset)
16
+ .enter()
17
+ .append("p")
18
+ .text("New paragraph!");
19
+
20
+ </script>
21
+ </body>
22
+ </html>
data/lib/colors.rb ADDED
@@ -0,0 +1,39 @@
1
+ # Below are the color init strings for the basic file types. A color init
2
+ # string consists of one or more of the following numeric codes:
3
+ # Attribute codes:
4
+ # 00=none 01=bold 04=underscore 05=blink 07=reverse 08=concealed
5
+ # Text color codes:
6
+ # 30=black 31=red 32=green 33=yellow 34=blue 35=magenta 36=cyan 37=white
7
+ # Background color codes:
8
+ # 40=black 41=red 42=green 43=yellow 44=blue 45=magenta 46=cyan 47=white
9
+
10
+
11
+ m = { }
12
+ ENV['LS_COLORS'].split(":").each do |e|
13
+ k, v = e.split('=')
14
+ m[k] = v
15
+ end
16
+
17
+ puts m
18
+
19
+
20
+ ## ANSIname => ANSIcode LUT
21
+ #ANSINAME2CODE= { "reset" => "\e[0m", "bold" => "\e[1m",
22
+ # "underline" => "\e[4m", "blink" => "\e[5m",
23
+ # "reverse" => "\e[7m", "invisible" => "\e[8m",
24
+ # "black" => "\e[0;30m", "darkgrey" => "\e[1;30m",
25
+ # "red" => "\e[0;31m", "lightred" => "\e[1;31m",
26
+ # "green" => "\e[0;32m", "lightgreen" => "\e[1;32m",
27
+ # "brown" => "\e[0;33m", "yellow" => "\e[1;33m",
28
+ # "blue" => "\e[0;34m", "lightblue" => "\e[1;34m",
29
+ # "purple" => "\e[0;35m", "magenta" => "\e[1;35m",
30
+ # "cyan" => "\e[1;36m", "lightcyan" => "\e[1;36m",
31
+ # "grey" => "\e[0;37m", "white" => "\e[1;37m",
32
+ # "bgblack" => "\e[40m", "bgred" => "\e[41m",
33
+ # "bggreen" => "\e[42m", "bgyellow" => "\e[43m",
34
+ # "bgblue" => "\e[44m", "bgmagenta" => "\e[45m",
35
+ # "bgcyan" => "\e[46m", "bgwhite" => "\e[47m"
36
+ i,e= m['*.tga'].split(';')
37
+
38
+ puts "\e[#{i}m\e[1;#{e}m prova.tga \e[0m"
39
+
@@ -17,9 +17,22 @@ module TreeRb
17
17
  parser.separator "this is a almost :-) a clone of tree unix command written in ruby"
18
18
  parser.separator "Code https://github.com/tokiro/treevisitor. Feedback to tokiro.oyama@gmail.com"
19
19
 
20
+ #
21
+ # Generic
22
+ #
20
23
  parser.separator ""
21
24
  parser.separator "Generic options: "
22
25
 
26
+ parser.on_tail("--help", "Show this message") do
27
+ puts parser
28
+ options[:exit] = 1
29
+ end
30
+
31
+ parser.on_tail("--version", "Show the version") do
32
+ puts "tree.rb version #{TreeRb::VERSION}"
33
+ options[:exit] = 1
34
+ end
35
+
23
36
  parser.on("-v", "--[no-]verbose", "Run verbosely") do |v|
24
37
  options[:verbose] = v
25
38
  end
@@ -41,6 +54,9 @@ module TreeRb
41
54
  options[:force_overwrite_output] = true
42
55
  end
43
56
 
57
+ #
58
+ # Filters
59
+ #
44
60
  parser.separator ""
45
61
  parser.separator "Filter options: "
46
62
 
@@ -66,6 +82,14 @@ module TreeRb
66
82
  options[:algo] = algo
67
83
  end
68
84
 
85
+ options[:max_level] = nil
86
+ parser.on("-L [LEVEL]", Integer, "Max display depth of the directory tree.") do |l|
87
+ options[:max_level] = l
88
+ end
89
+
90
+ #
91
+ # Presentation options
92
+ #
69
93
  parser.separator ""
70
94
  parser.separator "print options:"
71
95
 
@@ -84,14 +108,13 @@ module TreeRb
84
108
  " Useful to colorize output to a pipe.") do
85
109
  options[:colorize_force] = true
86
110
  end
87
-
88
111
  #
89
112
  # end colorize
90
113
  #
91
114
 
92
- options[:max_level] = nil
93
- parser.on("-L [LEVEL]", Integer, "Max display depth of the directory tree.") do |l|
94
- options[:max_level] = l
115
+ options[:ansi_line_graphics] = false
116
+ parser.on("-A", "Turn on ANSI line graphics hack when printing the indentation lines.") do
117
+ options[:ansi_line_graphics] = true
95
118
  end
96
119
 
97
120
  options[:show_full_path] = false
@@ -151,18 +174,6 @@ module TreeRb
151
174
  options[:show_report] = false
152
175
  end
153
176
 
154
- parser.separator ""
155
- parser.separator "Other options:"
156
-
157
- parser.on_tail("--help", "Show this message") do
158
- puts parser
159
- options[:exit] = 1
160
- end
161
-
162
- parser.on_tail("--version", "Show the version") do
163
- puts "tree.rb version #{TreeRb::VERSION}"
164
- options[:exit] = 1
165
- end
166
177
 
167
178
  parser
168
179
  end
@@ -248,12 +259,20 @@ module TreeRb
248
259
  when 'json'
249
260
  visitor = DirectoryToHashVisitor.new(dirname)
250
261
  root = dtw.run(visitor).root
251
- output.puts JSON.pretty_generate(root)
262
+ begin
263
+ output.puts JSON.pretty_generate(root)
264
+ rescue JSON::NestingError => e
265
+ $stderr.puts "#{File.basename(__FILE__)}:#{__LINE__} #{e.to_s}"
266
+ end
252
267
 
253
268
  when 'json2'
254
269
  visitor = DirectoryToHash2Visitor.new(dirname)
255
270
  root = dtw.run(visitor).root
256
- output.puts JSON.pretty_generate(root)
271
+ begin
272
+ output.puts JSON.pretty_generate(root)
273
+ rescue JSON::NestingError => e
274
+ $stderr.puts "#{File.basename(__FILE__)}:#{__LINE__} #{e.to_s}"
275
+ end
257
276
 
258
277
  when 'yaml'
259
278
  visitor = DirectoryToHashVisitor.new(dirname)
@@ -149,7 +149,7 @@ module TreeRb
149
149
  #
150
150
  # Test directory ignore pattern
151
151
  #
152
- # @param [String] directory name
152
+ # @param [String] dirname directory name
153
153
  # @return [boolean] if dirname match almost one pattern
154
154
  #
155
155
  def ignore_dir?(dirname)
@@ -159,7 +159,7 @@ module TreeRb
159
159
  #
160
160
  # Test file ignore pattern
161
161
  #
162
- # @param [String] file name
162
+ # @param [String] filename
163
163
  # @return [boolean] if filename match almost one pattern
164
164
  #
165
165
  def ignore_file?(filename)
@@ -169,7 +169,7 @@ module TreeRb
169
169
  #
170
170
  # Test common ignore pattern
171
171
  #
172
- # @param [String] file name
172
+ # @param [String] filename
173
173
  # @return [boolean] if filename match almost one pattern
174
174
  #
175
175
  def match?(filename)
@@ -263,14 +263,18 @@ module TreeRb
263
263
  #
264
264
  # recurse on other directories
265
265
  #
266
- def process_directory(dirname, level=0)
266
+ def process_directory(dirname, level=1)
267
267
  begin
268
268
  entries = Dir.entries(dirname).sort
269
269
  rescue Errno::EACCES => e
270
270
  $stderr.puts e
271
271
  @visitor.cannot_enter_node(dirname, e)
272
272
  return
273
- rescue Errno::EPERM => e
273
+ rescue Errno::EPERM => e
274
+ $stderr.puts e
275
+ @visitor.cannot_enter_node(dirname, e)
276
+ return
277
+ rescue Errno::ENOENT => e
274
278
  $stderr.puts e
275
279
  @visitor.cannot_enter_node(dirname, e)
276
280
  return
@@ -278,26 +282,28 @@ module TreeRb
278
282
 
279
283
 
280
284
  @visitor.enter_node(dirname)
281
- entries.each do |basename|
282
- begin
285
+ entries.each do |basename|
286
+ begin
283
287
  next if basename == "." or basename == ".." # ignore always "." and ".."
284
288
  pathname = File.join(dirname, basename)
285
289
 
286
290
  if File.directory?(pathname)
287
291
  if not ignore_dir?(basename) and (@max_level.nil? or @max_level > level)
288
- process_directory(pathname, level+1)
292
+ process_directory(pathname, level+1)
289
293
  end
290
294
  else
291
295
  if !!@visit_file && match?(basename) && !ignore_file?(basename)
292
296
  @visitor.visit_leaf(pathname)
293
297
  end
294
298
  end
295
- rescue Errno::EACCES => e
296
- $stderr.puts e
297
- rescue Errno::EPERM
298
- $stderr.puts e
299
- end
299
+ rescue Errno::EACCES => e
300
+ $stderr.puts e
301
+ rescue Errno::EPERM => e
302
+ $stderr.puts e
303
+ rescue Errno::ENOENT => e
304
+ $stderr.puts e
300
305
  end
306
+ end
301
307
 
302
308
  @visitor.exit_node(dirname)
303
309
  end
@@ -6,6 +6,7 @@ module TreeRb
6
6
  #
7
7
  # TreeNode @children -1---n-> TreeNode
8
8
  # @leaves -1---n-> LeafNode
9
+ # @children_leaves -1---n-> AbsNode (to preserve insert order)
9
10
  #
10
11
  # define dsl to create Tree
11
12
  #
@@ -22,9 +23,19 @@ module TreeRb
22
23
 
23
24
  class << self
24
25
 
25
- # DSL create a root node
26
+ # DSL create a root node:
26
27
  #
27
- # tree = TreeNode.create do ... end
28
+ # tree = TreeNode.create do
29
+ # ...
30
+ # end
31
+ #
32
+ # tree = TreeNode.create(LeafDerivedClass) do
33
+ # ...
34
+ # end
35
+ #
36
+ # tree = TreeNode.create(TreeNodeDerivedClass, LeafDerivedClass) do
37
+ # ...
38
+ # end
28
39
  #
29
40
  # @param [Class] class1 Subclass of TreeNode default TreeNode
30
41
  # @param [Class] class2 Subclass of LeafNode default LeafNode
@@ -39,7 +50,7 @@ module TreeRb
39
50
  end
40
51
 
41
52
  if @tree_node_class.nil? || @leaf_node_class.nil?
42
- raise "Must be specified class derived from TreeNode and LeafNode"
53
+ raise "Must be specified classes derived from TreeNode and LeafNode"
43
54
  end
44
55
 
45
56
  @scope_stack = []
@@ -48,15 +59,18 @@ module TreeRb
48
59
 
49
60
  private
50
61
 
51
- # DSL node add a child to the surrounding node
52
- # TreeNode.create do
53
- # node "..."
54
- # end
62
+ # DSL 'node' adds a child (TreeClass) to the current node
63
+ #
64
+ # TreeNode.create do
65
+ # node "..."
66
+ # end
55
67
  def node(*args, &block)
56
68
  parent_node = @scope_stack.length > 0 ? @scope_stack[-1] : nil
57
69
  args << parent_node
58
70
  tree_node = @tree_node_class.new(*args)
59
71
  @scope_stack.push tree_node
72
+
73
+ # evaluate block if any
60
74
  if block
61
75
  if block.arity == 0 || block.arity == -1
62
76
  class_eval(&block)
@@ -67,17 +81,21 @@ module TreeRb
67
81
  raise "block take too much arguments #{block.arity}"
68
82
  end
69
83
  end
84
+
70
85
  @scope_stack.pop
71
86
  end
72
87
 
73
- # DSL node add a leaf to the surround node
74
- # TreeNode.create do
75
- # leaf "..."
76
- # end
88
+ # DSL 'leaf' add a leaf (LeafClass) to the surround node
89
+ #
90
+ # TreeNode.create do
91
+ # leaf "..."
92
+ # end
77
93
  def leaf(*args, &block)
78
94
  tree_node = @scope_stack[-1]
79
95
  args << tree_node
80
96
  leaf_node = @leaf_node_class.new(*args)
97
+
98
+ # evaluate block if any
81
99
  if block
82
100
  if block.arity == 0 || block.arity == -1
83
101
  class_eval(&block)
@@ -98,12 +116,17 @@ module TreeRb
98
116
  # children i.e. other tree node
99
117
  attr_reader :children
100
118
 
119
+ # leaves and children to preserve insert order
120
+ attr_reader :leaves_and_children
121
+
101
122
  #
102
123
  # @param [Object] content of this node
103
124
  # @param [Object] parent of this node. If parent is nil, it is a root
125
+ #
104
126
  def initialize(content, parent = nil)
105
- @leaves = []
106
- @children = []
127
+ @leaves = []
128
+ @children = []
129
+ @leaves_and_children = []
107
130
  super(content)
108
131
  parent.add_child(self) if parent
109
132
  end
@@ -150,15 +173,13 @@ module TreeRb
150
173
 
151
174
  #
152
175
  # Add a Leaf
153
- # @param [LeafNode]
176
+ # @param [LeafNode] leaf
154
177
  #
155
178
  # @return self
156
179
  #
157
180
  def add_leaf(leaf)
158
181
  return if leaf.parent == self
159
- if not leaf.parent.nil?
160
- leaf.remove_from_parent
161
- end
182
+ leaf.remove_from_parent if leaf.parent
162
183
  leaf.parent = self
163
184
  if @leaves.length > 0
164
185
  @leaves.last.next = leaf
@@ -169,12 +190,13 @@ module TreeRb
169
190
  leaf.next = nil
170
191
  leaf.invalidate
171
192
  @leaves << leaf
193
+ @leaves_and_children << leaf
172
194
  self
173
195
  end
174
196
 
175
197
  #
176
198
  # Add a Tree
177
- # @param [LeafNode]
199
+ # @param [LeafNode] tree_node
178
200
  #
179
201
  # @return self
180
202
  #
@@ -195,6 +217,7 @@ module TreeRb
195
217
  end
196
218
  tree_node.next = nil
197
219
  @children << tree_node
220
+ @leaves_and_children << tree_node
198
221
  self
199
222
  end
200
223
 
@@ -228,7 +251,8 @@ module TreeRb
228
251
  end
229
252
 
230
253
  #
231
- # return the visitor
254
+ # @param [Visitor] visitor
255
+ # @return the visitor
232
256
  #
233
257
  def accept(visitor)
234
258
  visitor.enter_node(self)
@@ -255,32 +279,16 @@ module TreeRb
255
279
  # puts "aaaa \033[7;31;40m ciao \033[0m"
256
280
 
257
281
 
258
- #
259
- # check console character encoding
260
- # altre variabili LC_CTYPE
261
- # LC_ALL
262
- # comando locale
263
- # puts "enconding: #{ENV['LANG']}"
264
- #
265
-
266
-
267
- # │ (ascii 179)
268
- # ├ (ascii 195)
269
- # └ (ascii 192)
270
- # ─ (ascii 196)
271
-
272
-
273
- BRANCH = '|-- '
274
- LAST_BRANCH = '`-- '
275
- CONT_1 = "| "
276
- CONT_2 = " "
277
-
278
282
  def to_str(prefix= "", options = { })
279
283
  #TODO: find a more idiomatic mode to assign an array of options
284
+
280
285
  tty_color = options[:colorize].nil? ? false : options[:colorize]
281
286
  show_indentation = options[:show_indentation].nil? ? true : options[:show_indentation]
282
287
  str = ""
283
288
 
289
+ prepare_color_map if tty_color
290
+ prepare_prefix_map(options)
291
+
284
292
  # print node itself
285
293
  if root?
286
294
  unless options[:only_files]
@@ -291,16 +299,16 @@ module TreeRb
291
299
  if show_indentation
292
300
  str << prefix
293
301
  if self.next
294
- str << BRANCH
302
+ str << @prefix[:BRANCH]
295
303
  else
296
- str << LAST_BRANCH
304
+ str << @prefix[:LAST_BRANCH]
297
305
  end
298
306
  end
299
307
 
300
308
  unless options[:only_files]
301
309
  str << node_content_to_str(content, options)
302
310
  if show_indentation
303
- prefix += self.next ? CONT_1 : CONT_2
311
+ prefix += self.next ? @prefix[:CONT_1] : @prefix[:CONT_2]
304
312
  end
305
313
  end
306
314
  end
@@ -311,9 +319,9 @@ module TreeRb
311
319
  if show_indentation
312
320
  str << prefix
313
321
  if !leaf.next.nil? or !@children.empty?
314
- str << BRANCH
322
+ str << @prefix[:BRANCH]
315
323
  else
316
- str << LAST_BRANCH
324
+ str << @prefix[:LAST_BRANCH]
317
325
  end
318
326
  end
319
327
 
@@ -347,12 +355,62 @@ module TreeRb
347
355
 
348
356
  def leaf_content_to_str(content, options)
349
357
  if options[:colorize]
350
- "#{ANSI.green { content.to_str }}\n"
358
+ # "#{ANSI.green { content.to_str }}\n"
359
+ color_file(content.to_str)
351
360
  else
352
361
  "#{content.to_str }\n"
353
362
  end
354
363
  end
355
364
 
365
+ def prepare_color_map
366
+ @fileToColor = { }
367
+ ENV['LS_COLORS'].split(":").each do |e|
368
+ k, v = e.split('=')
369
+ @fileToColor[k] = v
370
+ end
371
+ end
372
+
373
+ def color_file(filename)
374
+ k = "*.#{File.extname(filename)}"
375
+ v = @fileToColor[k]
376
+ if v
377
+ attribute, color= v.split(';')
378
+ "\e[#{attribute}m\e[1;#{color}m #{filename}tr \e[0m\n"
379
+ else
380
+ "#{filename}\n"
381
+ end
382
+ end
383
+
384
+ def prepare_prefix_map(options)
385
+ #
386
+ # check console character encoding
387
+ # altre variabili LC_CTYPE
388
+ # LC_ALL
389
+ # comando locale
390
+ # puts "enconding: #{ENV['LANG']}"
391
+ #
392
+
393
+
394
+ # │ (ascii 179)
395
+ # ├ (ascii 195)
396
+ # └ (ascii 192)
397
+ # ─ (ascii 196)
398
+
399
+
400
+ @prefix = { }
401
+
402
+ if options[:ansi_line_graphics]
403
+ @prefix[:BRANCH] = '├── '
404
+ @prefix[:LAST_BRANCH] = '└── '
405
+ @prefix[:CONT_1] = "│ "
406
+ @prefix[:CONT_2] = " "
407
+ else
408
+ @prefix[:BRANCH] = '|-- '
409
+ @prefix[:LAST_BRANCH] = '`-- '
410
+ @prefix[:CONT_1] = "| "
411
+ @prefix[:CONT_2] = " "
412
+ end
413
+ end
356
414
 
357
415
  end # end class
358
416
  end # end module TreeRb
@@ -1,4 +1,4 @@
1
1
  # -*- coding: utf-8 -*-
2
2
  module TreeRb
3
- VERSION="0.3.7"
3
+ VERSION="0.3.8"
4
4
  end
@@ -7,16 +7,14 @@ module TreeRb
7
7
  class ContentDir
8
8
  def initialize(pathname, options)
9
9
  if options[:show_full_path]
10
- file_name = pathname
10
+ @contents = pathname
11
11
  else
12
- file_name = File.basename(pathname)
12
+ @contents = File.basename(pathname)
13
13
  end
14
-
15
- @str = file_name
16
14
  end
17
15
 
18
16
  def to_str
19
- @basename
17
+ @contents
20
18
  end
21
19
  end
22
20
 
@@ -384,9 +384,9 @@ module TreeRb
384
384
  #}
385
385
  #
386
386
 
387
- #
388
- # Build hash with directory structure
389
- #
387
+ #
388
+ # Build hash with directory structure
389
+ #
390
390
  class DirectoryToHash2Visitor < BasicTreeNodeVisitor
391
391
 
392
392
  attr_reader :root
@@ -397,8 +397,8 @@ module TreeRb
397
397
 
398
398
  def enter_node(pathname)
399
399
  @root = @node if @root.nil?
400
- @node = {name: File.basename(pathname), children: []}
401
- @stack.last[:children] << @node unless @stack.empty?
400
+ @node = { name: File.basename(pathname), children: [] }
401
+ @stack.last[:children] << @node unless @stack.empty?
402
402
  @stack.push(@node)
403
403
  end
404
404
 
@@ -407,7 +407,11 @@ module TreeRb
407
407
  end
408
408
 
409
409
  def visit_leaf(pathname)
410
- @node[:children] << {name: File.basename(pathname), size: File.stat(pathname).size}
410
+ begin
411
+ @node[:children] << { name: File.basename(pathname), size: File.stat(pathname).size }
412
+ rescue Errno::ENOENT => e
413
+ $stderr.puts e.to_s
414
+ end
411
415
  end
412
416
 
413
417
  end
@@ -3,6 +3,7 @@ module TreeRb
3
3
 
4
4
  class SqliteDirTreeVisitor < BasicTreeNodeVisitor
5
5
 
6
+
6
7
  def initialize(filename)
7
8
  @db = SQLite3::Database.new(filename)
8
9
  @db.execute("create table files(path varchar(1024), size integer, digest varchar(40))")
@@ -24,10 +25,10 @@ module TreeRb
24
25
  # sec = Time.now - start
25
26
  # print "#{CR}bytes: #{bytes.to_human} time: #{sec} bytes/sec #{bytes/sec} #{CLEAR}"
26
27
  # end
27
- #content = ContentFile.new(pathname, @options)
28
+ # content = ContentFile.new(pathname, @options)
28
29
  # connect the leaf_node created to the last tree_node on the stack
29
- #@nr_files += 1
30
- #LeafNode.new(content, @stack.last)
30
+ # nr_files += 1
31
+ # LeafNode.new(content, @stack.last)
31
32
  end
32
33
 
33
34
  def find_duplicates
@@ -26,7 +26,8 @@ describe CliTree do
26
26
  args << File.join(FIXTURES, "test_dir_1")
27
27
  CliTree.new.parse_args(args)
28
28
  end
29
- # puts captured
29
+ expected = "test_dir_1\n|-- dir.1\n| `-- dir.1.2\n`-- dir.2\n\n4 directories, 0 files\n"
30
+ captured.out.should == expected
30
31
  captured.out.split("\n").length.should == 6
31
32
  end
32
33
 
@@ -36,7 +37,8 @@ describe CliTree do
36
37
  args << File.join(FIXTURES, "test_dir_1")
37
38
  CliTree.new.parse_args(args)
38
39
  end
39
- # puts captured
40
+ expected = "test_dir_1\n|-- .dir_with_dot\n|-- dir.1\n| `-- dir.1.2\n`-- dir.2\n\n5 directories, 0 files\n"
41
+ captured.out.should == expected
40
42
  captured.out.split("\n").length.should == 7
41
43
  end
42
44
 
@@ -47,6 +49,8 @@ describe CliTree do
47
49
  CliTree.new.parse_args(args)
48
50
  end
49
51
  # pp captured
52
+ expected ="test_dir_1\n|-- .dir_with_dot\n| `-- dummy.txt\n|-- dir.1\n| |-- file.1.1\n| `-- dir.1.2\n| `-- file.1.2.1\n`-- dir.2\n `-- file.2.1\n\n5 directories, 4 files\n"
53
+ captured.out.should == expected
50
54
  captured.out.split("\n").length.should == 11
51
55
  end
52
56
 
@@ -57,16 +61,34 @@ describe CliTree do
57
61
  CliTree.new.parse_args(args)
58
62
  end
59
63
  # puts captured
64
+ expected ="test_dir_1\n|-- dir.1\n| |-- file.1.1\n| `-- dir.1.2\n| `-- file.1.2.1\n`-- dir.2\n `-- file.2.1\n\n4 directories, 3 files\n"
65
+ captured.out.should == expected
60
66
  captured.out.split("\n").length.should == 9
61
67
  end
62
68
 
69
+ it "should accepts -A switch (ascii line graphics)" do
70
+ captured = capture_output do
71
+ args = %w{-A}
72
+ args << File.join(FIXTURES, "test_dir_1")
73
+ CliTree.new.parse_args(args)
74
+ end
75
+ # puts captured
76
+ expected ="test_dir_1\n├── dir.1\n│ ├── file.1.1\n│ └── dir.1.2\n│ └── file.1.2.1\n└── dir.2\n └── file.2.1\n\n4 directories, 3 files\n"
77
+ captured.out.should == expected
78
+ end
79
+
63
80
  it "should show tree with inaccessible directories" do
64
81
  captured = capture_output do
65
82
  args = []
66
83
  args << File.join(FIXTURES, "test_dir_3_with_error")
67
84
  CliTree.new.parse_args(args)
68
85
  end
69
- #puts captured
86
+ # puts captured
87
+
88
+ expected_out="test_dir_3_with_error\n`-- accessible_dir\n\n2 directories, 0 files\n"
89
+ expected_err="Permission denied - /home/gf/GioPrj.home/tree.rb/spec/fixtures/test_dir_3_with_error/no_accessible_dir\n"
90
+ captured.out.should == expected_out
91
+ captured.err.should == expected_err
70
92
  captured.err.should_not be_empty
71
93
  captured.out.split("\n").length.should == 4
72
94
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: tree.rb
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.7
4
+ version: 0.3.8
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-09-01 00:00:00.000000000 Z
12
+ date: 2012-09-15 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: json
@@ -144,6 +144,7 @@ files:
144
144
  - tree.rb.gemspec
145
145
  - .gemtest
146
146
  - ext/mkrf_conf.rb
147
+ - lib/colors.rb
147
148
  - lib/treevisitor_cli.rb
148
149
  - lib/tree_visitor.rb
149
150
  - lib/tree_rb/cli/cli_json.rb
@@ -186,6 +187,7 @@ files:
186
187
  - examples/d3_treemap/prova.html
187
188
  - examples/d3_treemap/d3_tree_rb_output.json
188
189
  - examples/d3_treemap/d3.layout.js
190
+ - examples/prova1/prova1.html
189
191
  - examples/protovis/treevisitor.png
190
192
  - examples/protovis/protovis-r3.2.js
191
193
  - examples/protovis/index.html
@@ -233,18 +235,12 @@ required_ruby_version: !ruby/object:Gem::Requirement
233
235
  - - ! '>='
234
236
  - !ruby/object:Gem::Version
235
237
  version: '0'
236
- segments:
237
- - 0
238
- hash: 3743714857926214739
239
238
  required_rubygems_version: !ruby/object:Gem::Requirement
240
239
  none: false
241
240
  requirements:
242
241
  - - ! '>='
243
242
  - !ruby/object:Gem::Version
244
243
  version: '0'
245
- segments:
246
- - 0
247
- hash: 3743714857926214739
248
244
  requirements: []
249
245
  rubyforge_project:
250
246
  rubygems_version: 1.8.24