free_mutant/lib/mutant/reporter/cli/tput.rb
Markus Schirp ac8fe85810 Add output format representation
Upcoming commits will add a progressive reporter that does NOT require a
rewindable output. Usefull for imperfect terminal emulations as on CI
etc.
2014-08-10 22:09:31 +00:00

32 lines
842 B
Ruby

module Mutant
class Reporter
class CLI
# Interface to the optionally present tput binary
class Tput
include Adamantium, Concord::Public.new(:available, :prepare, :restore)
private_class_method :new
capture = lambda do |command|
stdout, _stderr, exitstatus = Open3.capture3(command)
stdout if exitstatus.success?
end
reset = capture.('tput reset')
save = capture.('tput sc') if reset
restore = capture.('tput rc') if save
clean = capture.('tput ed') if restore
UNAVAILABLE = new(false, nil, nil)
INSTANCE =
if save && restore && clean
new(true, reset + save, restore + clean)
else
UNAVAILABLE
end
end # TPUT
end # CLI
end # Reporter
end # Mutant