lib/rgversion/terminal.rb in rgversion-1.1.6 vs lib/rgversion/terminal.rb in rgversion-1.1.7.beta1

- old
+ new

@@ -10,16 +10,12 @@ render_output end def copy_to_clipboard return if @output.blank? - if command_exists? - system("echo \"#{@output}\" | #{clarified_command}") - puts "\nCopied to your clipboard!".green - else - render_instructions - end + clipboard = Clipboard.new(@command) + clipboard.copy end private def render_errors @@ -30,40 +26,8 @@ def render_output return if @results[:gems].blank? @output = @results[:gems].join("\n") puts @output - end - - def clarified_command - return "#{@command} -selection clipboard" if OS.linux? - @command - end - - def command_exists? - return false if which(@command.to_s).nil? - true - end - - # based on https://stackoverflow.com/a/5471032 - # let's avoid find_executable from mkmf because in this case we need to supress logs - def which(cmd) - exts = ENV['PATHEXT'] ? ENV['PATHEXT'].split(';') : [''] - ENV['PATH'].split(File::PATH_SEPARATOR).each do |path| - exts.each do |ext| - exe = File.join(path, "#{cmd}#{ext}") - return exe if File.executable?(exe) && !File.directory?(exe) - end - end - nil - end - - def render_instructions - if @command.nil? - puts "\nRgversion doesn't support copy to clipboard feature if your OS isn't macOS or Linux. You can manually copy output above." - else - puts "\nUnable to copy to clipboard because #{@command} is missed.\nTry the command below if you are on Ubuntu/Debian:" - puts "sudo apt-get install #{@command}" - end end end end