# Copyright (c) 2013-2016 SUSE LLC # # This program is free software; you can redistribute it and/or # modify it under the terms of version 3 of the GNU General Public License as # published by the Free Software Foundation. # # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # # You should have received a copy of the GNU General Public License # along with this program; if not, contact SUSE LLC. # # To contact SUSE about this file by physical or electronic mail, # you may find current contact information at www.suse.com module Machinery class Ui class </dev/null", "w") { |f| f.close } if $?.success? write_output_to_pager(output) else raise(Machinery::Errors::InvalidPager.new("'#{ENV['PAGER']}' could not " \ "be executed. Use the --no-pager option or modify your $PAGER " \ "bash environment variable to display output.") ) end end end end def progress(output) return unless progress_enabled? reset_line if progress_visible? print output @progress_visible = true end def puts(output) print output + "\n" end def warn(s) STDERR.puts s end def error(s) STDERR.puts s end private def progress_enabled? $stdout.tty? || ENV["FORCE_MACHINERY_PROGRESS_OUTPUT"] end def progress_visible? @progress_visible end def reset_line STDOUT.print "\r" # Move cursor to beginning of line STDOUT.print "\033[K" # Clear line content @progress_visible = false end end end end