This commit is contained in:
邱博亞 2024-05-08 23:04:55 +08:00
parent 137b7781b6
commit 56a0797be3
1 changed files with 20 additions and 39 deletions

View File

@ -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