# frozen_string_literal: truerequire_relative"../vendored_thor"moduleBundlermoduleUIclassShellLEVELS=%w[silent error warn confirm info debug].freezeOUTPUT_STREAMS=[:stdout,:stderr].freezeattr_writer:shellattr_reader:output_streamdefinitialize(options={})Thor::Base.shell=options["no-color"]?Thor::Shell::Basic:nil@shell=Thor::Base.shell.new@level=ENV["DEBUG"]?"debug":"info"@warning_history=[]@output_stream=:stdoutenddefadd_color(string,*color)@shell.set_color(string,*color)enddefinfo(msg=nil,newline=nil)returnunlessinfo?tell_me(msg||yield,nil,newline)enddefconfirm(msg=nil,newline=nil)returnunlessconfirm?tell_me(msg||yield,:green,newline)enddefwarn(msg=nil,newline=nil,color=:yellow)returnunlesswarn?returnif@warning_history.include?msg@warning_history<<msgtell_err(msg||yield,color,newline)enddeferror(msg=nil,newline=nil,color=:red)returnunlesserror?tell_err(msg||yield,color,newline)enddefdebug(msg=nil,newline=nil)returnunlessdebug?tell_me(msg||yield,nil,newline)enddefinfo?level("info")enddefconfirm?level("confirm")enddefwarn?level("warn")enddeferror?level("error")enddefdebug?level("debug")enddefquiet?level("quiet")enddefask(msg)@shell.ask(msg)enddefyes?(msg)@shell.yes?(msg)enddefno?(msg)@shell.no?(msg)enddeflevel=(level)raiseArgumentErrorunlessLEVELS.include?(level.to_s)@level=level.to_senddeflevel(name=nil)return@levelunlessnameunlessindex=LEVELS.index(name)raise"#{name.inspect} is not a valid level"endindex<=LEVELS.index(@level)enddefoutput_stream=(symbol)raiseArgumentErrorunlessOUTPUT_STREAMS.include?(symbol)@output_stream=symbolenddeftrace(e,newline=nil,force=false)returnunlessdebug?||forcemsg="#{e.class}: #{e.message}\n#{e.backtrace.join("\n ")}"tell_err(msg,nil,newline)enddefsilence(&blk)with_level("silent",&blk)enddefprogress(&blk)with_output_stream(:stderr,&blk)enddefunprinted_warnings[]endprivate# valimismdeftell_me(msg,color=nil,newline=nil)returntell_err(msg,color,newline)ifoutput_stream==:stderrmsg=word_wrap(msg)ifnewline.is_a?(Hash)&&newline[:wrap]ifnewline.nil?@shell.say(msg,color)else@shell.say(msg,color,newline)endenddeftell_err(message,color=nil,newline=nil)returnif@shell.send(:stderr).closed?newline=!message.to_s.match?(/( |\t)\Z/)ifnewline.nil?message=word_wrap(message)ifnewline.is_a?(Hash)&&newline[:wrap]color=nilifcolor&&!$stderr.tty?buffer=@shell.send(:prepare_message,message,*color)buffer<<"\n"ifnewline&&!message.to_s.end_with?("\n")@shell.send(:stderr).print(buffer)@shell.send(:stderr).flushenddefstrip_leading_spaces(text)spaces=text[/\A\s+/,0]spaces?text.gsub(/#{spaces}/,""):textenddefword_wrap(text,line_width=Thor::Terminal.terminal_width)strip_leading_spaces(text).split("\n").collectdo|line|line.length>line_width?line.gsub(/(.{1,#{line_width}})(\s+|$)/,"\\1\n").strip:lineend*"\n"enddefwith_level(level)original=@level@level=levelyieldensure@level=originalenddefwith_output_stream(symbol)original=output_streamself.output_stream=symbolyieldensure@output_stream=originalendendendend