Sha256: 82547e95f0f21871f2cf554c168ec32d9faf24c91b2d5d842b09b7c4ae1bdc22

Contents?: true

Size: 1.27 KB

Versions: 100

Compression:

Stored size: 1.27 KB

Contents

module Vagrant
  module Util
    module ANSIEscapeCodeRemover
      # Removes ANSI escape code sequences from the text and returns
      # it.
      #
      # This removes all the ANSI escape codes listed here along with
      # the escape codes for VT100 terminals:
      #
      # http://ascii-table.com/ansi-escape-sequences.php
      def remove_ansi_escape_codes(text)
        # An array of regular expressions which match various kinds
        # of escape sequences. I can't think of a better single regular
        # expression or any faster way to do this.
        matchers = [/\e\[\d*[ABCD]/,       # Matches things like \e[4D
                    /\e\[(\d*;)?\d*[HF]/,  # Matches \e[1;2H or \e[H
                    /\e\[(s|u|2J|K)/,      # Matches \e[s, \e[2J, etc.
                    /\e\[=\d*[hl]/,        # Matches \e[=24h
                    /\e\[\?[1-9][hl]/,     # Matches \e[?2h
                    /\e\[20[hl]/,          # Matches \e[20l]
                    /\e[DME78H]/,          # Matches \eD, \eH, etc.
                    /\e\[[0-2]?[JK]/,      # Matches \e[0J, \e[K, etc.
                    ]

        # Take each matcher and replace it with emptiness.
        matchers.each do |matcher|
          text.gsub!(matcher, "")
        end

        text
      end
    end
  end
end

Version data entries

100 entries across 93 versions & 18 rubygems

Version Path
vagrant-unbundled-2.2.9.0 lib/vagrant/util/ansi_escape_code_remover.rb
vagrant-unbundled-2.2.8.0 lib/vagrant/util/ansi_escape_code_remover.rb
vagrant-unbundled-2.2.7.0 lib/vagrant/util/ansi_escape_code_remover.rb
vagrant-unbundled-2.2.6.2 lib/vagrant/util/ansi_escape_code_remover.rb
vagrant-unbundled-2.2.6.1 lib/vagrant/util/ansi_escape_code_remover.rb
vagrant-unbundled-2.2.6.0 lib/vagrant/util/ansi_escape_code_remover.rb
vagrant-unbundled-2.2.5.0 lib/vagrant/util/ansi_escape_code_remover.rb
tamtam-vagrant-reload-1.1.3 vendor/cache/vagrant-0ac2a8738841/lib/vagrant/util/ansi_escape_code_remover.rb
vagrant-unbundled-2.2.4.0 lib/vagrant/util/ansi_escape_code_remover.rb
vagrant-unbundled-2.2.3.0 lib/vagrant/util/ansi_escape_code_remover.rb
vagrant-unbundled-2.2.2.0 lib/vagrant/util/ansi_escape_code_remover.rb
vagrant-unbundled-2.2.0.0 lib/vagrant/util/ansi_escape_code_remover.rb
vagrant-unbundled-2.1.4.0 lib/vagrant/util/ansi_escape_code_remover.rb
vagrant-unbundled-2.1.2.0 lib/vagrant/util/ansi_escape_code_remover.rb
vagrant-packet-0.1.2 vendor/bundle/ruby/2.5.0/bundler/gems/vagrant-04f7215b5e3f/lib/vagrant/util/ansi_escape_code_remover.rb
vagrant-packet-0.1.2 vendor/bundle/ruby/2.3.0/bundler/gems/vagrant-04f7215b5e3f/lib/vagrant/util/ansi_escape_code_remover.rb
vagrant-packet-0.1.2 vendor/bundle/ruby/2.4.0/bundler/gems/vagrant-04f7215b5e3f/lib/vagrant/util/ansi_escape_code_remover.rb
vagrant-packet-0.1.1 vendor/bundle/ruby/2.4.0/bundler/gems/vagrant-04f7215b5e3f/lib/vagrant/util/ansi_escape_code_remover.rb
vagrant-packet-0.1.1 vendor/bundle/ruby/2.3.0/bundler/gems/vagrant-04f7215b5e3f/lib/vagrant/util/ansi_escape_code_remover.rb
vagrant-packet-0.1.1 vendor/bundle/ruby/2.5.0/bundler/gems/vagrant-04f7215b5e3f/lib/vagrant/util/ansi_escape_code_remover.rb