Module: Parlour::Debugging::Tree

Extended by:
T::Sig
Defined in:
lib/parlour/debugging.rb

Overview

A module for generating a globally-consistent, nicely-formatted tree of output using Unicode block characters.

Constant Summary collapse

INDENT_SPACES =

The number of spaces to indent each layer of the tree by. Should be at least 1.

2

Class Method Summary collapse

Class Method Details

.begin(message) ⇒ Object



81
82
83
84
85
# File 'lib/parlour/debugging.rb', line 81

def self.begin(message)
  result = line_prefix + '├' + text_prefix + Rainbow(message).green.bright.bold
  @indent_level += 1
  result
end

.end(message) ⇒ Object



100
101
102
103
104
# File 'lib/parlour/debugging.rb', line 100

def self.end(message)
  result = line_prefix + '└' + text_prefix + message
  @indent_level = [0, @indent_level - 1].max
  result
end

.here(message) ⇒ Object



91
92
93
# File 'lib/parlour/debugging.rb', line 91

def self.here(message)
  line_prefix + '├' + text_prefix + message
end

.line_prefixString

The prefix which should be printed before anything else on this line of the tree, based on the current indent level.

Returns:

  • (String)


109
110
111
# File 'lib/parlour/debugging.rb', line 109

def self.line_prefix
  @indent_level.times.map { '│' + ' ' * INDENT_SPACES }.join
end

.text_prefixString

The horizontal lines which should be printed between the beginning of the current element and its text, based on the specified number of spaces to use for indents.

Returns:

  • (String)


117
118
119
# File 'lib/parlour/debugging.rb', line 117

def self.text_prefix
  '─' * (INDENT_SPACES - 1) + " "
end