Browse Source

terminus

main
pvincent 6 months ago
parent
commit
ae10cdcd03
  1. 4
      lib/formatters/ansi_dimensions.rb
  2. 9
      lib/formatters/ansi_filter.rb
  3. 16
      lib/formatters/ansi_formatter.rb
  4. 0
      lib/old/basic_formatter.rb
  5. 0
      lib/old/symbols.txt
  6. 0
      lib/old/wrapper.rb

4
lib/formatters/ansi_dimensions.rb

@ -1,6 +1,6 @@
# extra dimensions to customize ansi_loggingg
module AnsiDimensions
def self.new(rails: '╣x╠', before: 0, after: 0)
OpenStruct.new(rails:, before:, after:)
def self.new(rails: '╣x╠', before: 0, after: 0, terminus: false)
OpenStruct.new(rails:, before:, after:, terminus:) # rubocop:disable Style/OpenStructUse
end
end

9
lib/formatters/ansi_filter.rb

@ -6,6 +6,7 @@ module AnsiFilter
$memory = nil
CHAR_FATAL = '⯶'.freeze
TERMINUS_STRING = '╙─╜'.freeze
def self.reject(log)
# log.name == 'ScoresController' || false
@ -22,7 +23,7 @@ module AnsiFilter
log.dimensions = AnsiDimensions.new(rails:)
$memory = nil
elsif log.message.starts_with?('Completed 2')
log.dimensions = AnsiDimensions.new(rails: '╙─╜', after: 2)
log.dimensions = AnsiDimensions.new(rails: TERMINUS_STRING, after: 2)
elsif log.message.starts_with?('Completed 3')
$memory = '║'
log.dimensions = AnsiDimensions.new(rails: "#{$memory}")
@ -32,7 +33,11 @@ module AnsiFilter
log.dimensions = AnsiDimensions.new(rails: "#{draw_fatal}")
end
elsif log.exception
log.dimensions = AnsiDimensions.new(rails: "#{draw_fatal(log.level.to_s.chr.upcase)}", after: 2)
log.dimensions = AnsiDimensions.new(
rails: "#{draw_fatal(log.level.to_s.chr.upcase)}",
after: 2,
terminus: true
)
end
end
log

16
lib/formatters/ansi_formatter.rb

@ -38,6 +38,7 @@ class AnsiFormatter < SemanticLogger::Formatters::Color
def origin = colorize(centerize(log.name), TEXT_CYAN)
def build_prefix(char) = "#{origin}#{colorize(char)}"
def build_terminus = "#{origin} #{AnsiFilter::TERMINUS_STRING} "
def centerize(text) = text.truncate(CENTER_SIZE).center(CENTER_SIZE)
def colorize(text, tint = color) = "#{tint}#{text}#{CLEAR}"
def stackisize(items) = items.length.positive? ? "\n#{items.join("\n")}" : ''
@ -84,10 +85,17 @@ class AnsiFormatter < SemanticLogger::Formatters::Color
prefix = log.dimensions ? build_dimensions(log.dimensions) : build_prefix(level_char)
continuation = build_prefix('┆')
log.dimensions&.before&.times { items.unshift('') }
log.dimensions&.after&.times { items << '' }
items.map do |item|
result = items.map do |item|
AnsiWrapper.wrap(item, length, prefix, continuation)
end.compact.join("\n")
end
if log.dimensions&.terminus
terminus = AnsiWrapper.wrap(' ', length, build_terminus)
result << terminus
end
log.dimensions&.before&.times { result.unshift('') }
log.dimensions&.after&.times { result << '' }
result.compact.join("\n")
end
end

0
lib/formatters/basic_formatter.rb → lib/old/basic_formatter.rb

0
lib/formatters/symbols.txt → lib/old/symbols.txt

0
lib/formatters/wrapper.rb → lib/old/wrapper.rb

Loading…
Cancel
Save