SusSourceSusOutputStatus

class Status

Represents a status indicator for test execution.

Definitions

def self.register(output)

Register status styling with an output handler.

Signature

parameter output Output

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 state Symbol

The state (:free or :busy).

parameter context Object, 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 state Symbol

The new state.

parameter context Object, 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 output Output

The output handler.

Implementation

def print(output)
	output.write(
		@state, self.indicator, " "
	)
	
	output.write(@context)
	
	output.puts
end