module Console::Output::Default
Default
output format selection.
Public Class Methods
Source
# File vendor/bundle/ruby/3.4.0/gems/console-1.31.0/lib/console/output/default.rb, line 36 def self.mail?(env = ENV) # Check for common cron environment indicators return true if env.key?("MAILTO") && !env["MAILTO"].empty? false end
Detect if we’re running in a cron job or mail context where human-readable output is preferred. Cron jobs often have MAILTO set and lack TERM, or have minimal TERM values.
Source
# File vendor/bundle/ruby/3.4.0/gems/console-1.31.0/lib/console/output/default.rb, line 20 def self.new(stream, env: ENV, **options) stream ||= $stderr if stream.tty? || mail?(env) output = Terminal.new(stream, **options) else output = Serialized.new(stream, **options) end return output end
Create a new output format based on the given stream.
@parameter io [IO] The output stream. @parameter env [Hash] Environment variables (defaults to ENV for testing). @parameter options [Hash] Additional options to customize the output. @returns [Console::Output::Terminal | Console::Output::Serialized
] The output instance, depending on whether the ‘io` is a terminal or not.