Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 14 additions & 5 deletions lib/sus/output.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,19 @@
module Sus
# Represents output handlers for test results and messages.
module Output
# Detect if we're running in GitHub Actions, where human-readable output is preferred.
# GitHub Actions sets the GITHUB_ACTIONS environment variable to "true".
# @parameter env [Hash] The environment variables to check.
def self.github_actions?(env)
env["GITHUB_ACTIONS"] == "true"
end

# Create an appropriate output handler for the given IO.
# @parameter io [IO] The IO object to write to.
# @returns [XTerm, Text] An XTerm handler if the IO is a TTY, otherwise a Text handler.
def self.for(io)
if io.isatty
# @parameter env [Hash] The environment variables to consider (defaults to ENV).
# @returns [XTerm, Text] An XTerm handler if the IO is a TTY or running in GitHub Actions, otherwise a Text handler.
def self.for(io, env = ENV)
if io.isatty or self.github_actions?(env)
XTerm.new(io)
else
Text.new(io)
Expand All @@ -26,9 +34,10 @@ def self.for(io)

# Create a default output handler with styling configured.
# @parameter io [IO] The IO object to write to (defaults to $stderr).
# @parameter env [Hash] The environment variables to consider (defaults to ENV).
# @returns [XTerm, Text] A configured output handler.
def self.default(io = $stderr)
output = self.for(io)
def self.default(io = $stderr, env = ENV)
output = self.for(io, env)

Output::Bar.register(output)

Expand Down
2 changes: 1 addition & 1 deletion lib/sus/output/status.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ class Status
# @parameter output [Output] The output handler to register with.
def self.register(output)
output[:free] ||= output.style(:blue)
output[:busy] ||= output.style(:orange)
output[:busy] ||= output.style(:red)
end

# Initialize a new Status indicator.
Expand Down
2 changes: 1 addition & 1 deletion test/sus/output/status.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

describe Sus::Output::Status do
let(:buffer) {StringIO.new}
let(:output) {Sus::Output.for(buffer)}
let(:output) {Sus::Output.for(buffer, {})}

def before
Sus::Output::Status.register(output)
Expand Down
Loading