class Status
Represents a status indicator for test execution.
Definitions
def self.register(output)
Register status styling with an output handler.
Signature
-
parameter
outputOutput The output handler to register with.
Implementation
def self.register(output)
output[:free] ||= output.style(:green)
output[:busy] ||= output.style(:blue)
end
def initialize(state = :free, context = nil)
Initialize a new Status indicator.
Signature
-
parameter
stateSymbol The state (:free or :busy).
-
parameter
contextObject, nil Optional context to display.
Implementation
def initialize(state = :free, context = nil)
@state = state
@context = context
end
INDICATORS = {...}
Status indicators for different states.
Implementation
INDICATORS = {
busy: ["◑", "◒", "◐", "◓"],
free: ["◌"]
}
def update(state, context = nil)
Update the status.
Signature
-
parameter
stateSymbol The new state.
-
parameter
contextObject, nil Optional new context.
Implementation
def update(state, context = nil)
@state = state
@context = context
end
def indicator
Signature
-
returns
String The current indicator character (animated for busy state).
Implementation
def indicator
if indicators = INDICATORS[@state]
return indicators[(Time.now.to_f * 10) % indicators.size]
end
return " "
end
def print(output)
Print the status to the output.
Signature
-
parameter
outputOutput The output handler.
Implementation
def print(output)
output.write(
@state, self.indicator, " "
)
output.write(@context)
output.puts
end