Class: Spoom::FileTree::Printer

Inherits:
Visitor
  • Object
show all
Extended by:
T::Sig
Defined in:
lib/spoom/file_tree.rb

Overview

An internal class used to print a FileTree

See ‘FileTree#print`

Instance Method Summary collapse

Methods inherited from Visitor

#visit_nodes, #visit_tree

Constructor Details

#initialize(strictnesses, out: $stdout, colors: true) ⇒ Printer

Returns a new instance of Printer.



238
239
240
241
242
243
# File 'lib/spoom/file_tree.rb', line 238

def initialize(strictnesses, out: $stdout, colors: true)
  super()
  @strictnesses = strictnesses
  @colors = colors
  @printer = T.let(Spoom::Printer.new(out: out, colors: colors), Spoom::Printer)
end

Instance Method Details

#visit_node(node) ⇒ Object



246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
# File 'lib/spoom/file_tree.rb', line 246

def visit_node(node)
  @printer.printt
  if node.children.empty?
    strictness = @strictnesses[node]
    if @colors
      @printer.print_colored(node.name, strictness_color(strictness))
    elsif strictness
      @printer.print("#{node.name} (#{strictness})")
    else
      @printer.print(node.name.to_s)
    end
    @printer.print("\n")
  else
    @printer.print_colored(node.name, Color::BLUE)
    @printer.print("/")
    @printer.printn
    @printer.indent
    super
    @printer.dedent
  end
end