Remove ANSI escape codes from SSH output
Note that the ANSI escape code removal is not complete, but is fairly comprehensive in terms of the codes that really muck with the terminal layout.
This commit is contained in:
parent
d1e78f791d
commit
3a5f0cefb3
|
@ -4,6 +4,7 @@ require 'log4r'
|
||||||
require 'net/ssh'
|
require 'net/ssh'
|
||||||
require 'net/scp'
|
require 'net/scp'
|
||||||
|
|
||||||
|
require 'vagrant/util/ansi_escape_code_remover'
|
||||||
require 'vagrant/util/file_mode'
|
require 'vagrant/util/file_mode'
|
||||||
require 'vagrant/util/platform'
|
require 'vagrant/util/platform'
|
||||||
require 'vagrant/util/retryable'
|
require 'vagrant/util/retryable'
|
||||||
|
@ -12,6 +13,7 @@ module Vagrant
|
||||||
module Communication
|
module Communication
|
||||||
# Provides communication with the VM via SSH.
|
# Provides communication with the VM via SSH.
|
||||||
class SSH < Base
|
class SSH < Base
|
||||||
|
include Util::ANSIEscapeCodeRemover
|
||||||
include Util::Retryable
|
include Util::Retryable
|
||||||
|
|
||||||
def initialize(vm)
|
def initialize(vm)
|
||||||
|
@ -169,7 +171,7 @@ module Vagrant
|
||||||
ch2.on_data do |ch3, data|
|
ch2.on_data do |ch3, data|
|
||||||
if block_given?
|
if block_given?
|
||||||
# Filter out the clear screen command
|
# Filter out the clear screen command
|
||||||
data.gsub!("\e[H", "")
|
data = remove_ansi_escape_codes(data)
|
||||||
@logger.debug("stdout: #{data}")
|
@logger.debug("stdout: #{data}")
|
||||||
yield :stdout, data
|
yield :stdout, data
|
||||||
end
|
end
|
||||||
|
@ -178,7 +180,7 @@ module Vagrant
|
||||||
ch2.on_extended_data do |ch3, type, data|
|
ch2.on_extended_data do |ch3, type, data|
|
||||||
if block_given?
|
if block_given?
|
||||||
# Filter out the clear screen command
|
# Filter out the clear screen command
|
||||||
data.gsub!("\e[H", "")
|
data = remove_ansi_escape_codes(data)
|
||||||
@logger.debug("stderr: #{data}")
|
@logger.debug("stderr: #{data}")
|
||||||
yield :stderr, data
|
yield :stderr, data
|
||||||
end
|
end
|
||||||
|
|
|
@ -22,6 +22,7 @@ module Vagrant
|
||||||
/\e[DME78H]/, # Matches \eD, \eH, etc.
|
/\e[DME78H]/, # Matches \eD, \eH, etc.
|
||||||
/\e\[[0-2]?[JK]/, # Matches \e[0J, \e[K, etc.
|
/\e\[[0-2]?[JK]/, # Matches \e[0J, \e[K, etc.
|
||||||
]
|
]
|
||||||
|
|
||||||
# Take each matcher and replace it with emptiness.
|
# Take each matcher and replace it with emptiness.
|
||||||
matchers.each do |matcher|
|
matchers.each do |matcher|
|
||||||
text.gsub!(matcher, "")
|
text.gsub!(matcher, "")
|
||||||
|
|
Loading…
Reference in New Issue