Browse Source

rescue IO.console in case of debug

pagy
pvincent 11 months ago
parent
commit
334e12bf0e
  1. 2
      Procfile.dev
  2. 9
      lib/formatters/basic_formatter.rb

2
Procfile.dev

@ -1,3 +1,3 @@
# web: env RUBY_DEBUG_OPEN=true bin/rails server --port 3000 # web: env RUBY_DEBUG_OPEN=true bin/rails server --port 3000
web: bin/rails server --port 3000
web: env TERMINAL_PREFIX=15 bin/rails server --port 3000
css: bin/rails tailwindcss:watch css: bin/rails tailwindcss:watch

9
lib/formatters/basic_formatter.rb

@ -4,7 +4,7 @@ require 'io/console'
# Opinioned Rails custom formatter # Opinioned Rails custom formatter
class BasicFormatter < SemanticLogger::Formatters::Color class BasicFormatter < SemanticLogger::Formatters::Color
NAME_MAX_SIZE = 25 NAME_MAX_SIZE = 25
FOREMAN_PREFIX = 15
TERMINAL_PREFIX = ENV['TERMINAL_PREFIX'].to_i || 0
CONTENT_PREFIX = ' '.freeze CONTENT_PREFIX = ' '.freeze
WRAP_PREFIX = ' > '.freeze WRAP_PREFIX = ' > '.freeze
@ -54,7 +54,12 @@ class BasicFormatter < SemanticLogger::Formatters::Color
message += "\n" unless message.starts_with?('Completed 5') message += "\n" unless message.starts_with?('Completed 5')
end end
wrap_length = IO.console.winsize[1] - FOREMAN_PREFIX - before_message.length + CONTENT_PREFIX.length + 12
begin
wrap_length = IO.console.winsize[1] - TERMINAL_PREFIX - before_message.length + CONTENT_PREFIX.length + 12
rescue StandardError
wrap_length = 100
end
space_prefix = message.match(/^\s*/) space_prefix = message.match(/^\s*/)
message = Wrapper.wrap("#{CONTENT_COLOR_MAP[log.level]}#{message}", before_message(true, space_prefix), message = Wrapper.wrap("#{CONTENT_COLOR_MAP[log.level]}#{message}", before_message(true, space_prefix),
wrap_length - space_prefix.length) wrap_length - space_prefix.length)

Loading…
Cancel
Save