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.



222
223
224
225
226
227
# File 'lib/spoom/file_tree.rb', line 222

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



230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
# File 'lib/spoom/file_tree.rb', line 230

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