From 56a0797be31c419579bc4c140f860c805a1029b7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=82=B1=E5=8D=9A=E4=BA=9E?= Date: Wed, 8 May 2024 23:04:55 +0800 Subject: [PATCH] test --- lib/tasks/exec_command.rake | 59 +++++++++++++------------------------ 1 file changed, 20 insertions(+), 39 deletions(-) diff --git a/lib/tasks/exec_command.rake b/lib/tasks/exec_command.rake index b537cb3..24e0f79 100644 --- a/lib/tasks/exec_command.rake +++ b/lib/tasks/exec_command.rake @@ -262,57 +262,38 @@ namespace :exec_commands do channel.send_data "#{@password}\n" else print data_str unless @no_stdout - data_str.gsub!("\r\n", "\n") - rm_idx = data_str.index("\r") - if rm_idx.nil? - @remove_last_line = false - else - @remove_last_line = (outputs.count > 0 && data_str[0...rm_idx].exclude?("\n")) - end - data_str.gsub!(/.*\r(?!\n)/, '') + data_str.gsub!(/\r\n/, "\n") next if data_str.length == 0 - if data_str.include?("\n") || outputs.empty? - output_lines = data_str.split("\n") - first_output = output_lines[0] - if first_output - if @remove_last_line - outputs = outputs[1..-1] - outputs = [] if outputs.nil? - end - if outputs.count != 0 - outputs[-1] += first_output - else - outputs << first_output + output_lines = data_str.split("\n") + first_output = output_lines[0] + if first_output + if outputs.count != 0 + outputs[-1] += first_output + @remove_last_line = false + outputs[-1] = outputs[-1].sub(/(.+)\r(.+)/) do |s| + @remove_last_line = true + first_output = $2 end + else + outputs << first_output end + if update_outputs + update_thread_infos_for_exec(first_output,true) if @flag + update_infos_for_exec(first_output,true) + end + @remove_last_line = false new_arr = output_lines[1..-1] - new_arr = [] if new_arr.nil? + new_arr = new_arr.map do |output_line| + output_line = output_line.sub(/(.+)\r(.+)/, '\2') + end.select{|s| s.present?} if data_str[-1] == "\n" new_arr << "" end outputs += new_arr if update_outputs - if first_output - update_thread_infos_for_exec(first_output,true) if @flag - update_infos_for_exec(first_output,true) - end update_thread_infos_for_exec(new_arr,false,true) if @flag update_infos_for_exec(new_arr,false,true) end - else - if @remove_last_line - outputs = outputs[1..-1] - outputs = [] if outputs.nil? - end - if outputs.count == 0 - outputs.push(data_str) - else - outputs[-1] += (data_str rescue "") - end - if update_outputs - update_thread_infos_for_exec(data_str,true) if @flag - update_infos_for_exec(data_str,true) - end end end end