Sha256: 3a58dc37e483bad1231040febeb34ebebde373e3bf688d03e53e000bf6f0c37e

Contents?: true

Size: 1.43 KB

Versions: 26

Compression:

Stored size: 1.43 KB

Contents

# Aruba
module Aruba
  # Api
  module Api
    # Text manipulation
    module Text
      # Unescape text
      #
      # '\n' => "\n"
      # '\e' => "\e"
      # '\033' => "\e"
      # '\"' => '"'
      #
      # @param [#to_s] text
      #   Input
      def unescape_text(text)
        text.gsub('\n', "\n").gsub('\"', '"').gsub('\e', "\e").gsub('\033', "\e").gsub('\016', "\016").gsub('\017', "\017").gsub('\t', "\t")
      end

      # Remove ansi characters from text
      #
      # @param [#to_s] text
      #   Input
      def extract_text(text)
        if Aruba::VERSION < '1'
          text.gsub(/(?:\e|\033)\[\d+(?>(;\d+)*)m/, '')
        else
          text.gsub(/(?:\e|\033)\[\d+(?>(;\d+)*)m/, '').gsub(/\\\[|\\\]/, '').gsub(/\007|\016|\017/, '')
        end
      end

      # Unescape special characters and remove ANSI characters
      #
      # @param [#to_s] text
      #   The text to sanitize
      def sanitize_text(text)
        text = unescape_text(text)
        text = extract_text(text) if !aruba.config.keep_ansi || aruba.config.remove_ansi_escape_sequences

        text.chomp
      end

      # @experimental
      #
      # Replace variables in command string
      #
      # @param [#to_s] text
      #   The text to parse
      def replace_variables(text)
        text = text.gsub(/<pid-last-command-started>/, last_command_started.pid.to_s) if text.include? '<pid-last-command-started>'

        text
      end
    end
  end
end

Version data entries

26 entries across 26 versions & 3 rubygems

Version Path
aruba-0.14.14 lib/aruba/api/text.rb
aruba-0.14.13 lib/aruba/api/text.rb
honeybadger-4.5.3 vendor/bundle/ruby/2.6.0/gems/aruba-0.14.12/lib/aruba/api/text.rb
aruba-0.14.12 lib/aruba/api/text.rb
aruba-0.14.11 lib/aruba/api/text.rb
aruba-0.14.10 lib/aruba/api/text.rb
aruba-0.14.9 lib/aruba/api/text.rb
aruba-0.14.8 lib/aruba/api/text.rb
aruba-0.14.7 lib/aruba/api/text.rb
aruba-0.14.6 lib/aruba/api/text.rb
aruba-0.14.5 lib/aruba/api/text.rb
aruba-0.14.4 lib/aruba/api/text.rb
aruba-0.14.3 lib/aruba/api/text.rb
aruba-1.0.0.pre.alpha.2 lib/aruba/api/text.rb
aruba-1.0.0.pre.alpha.1 lib/aruba/api/text.rb
aruba-win-fix-0.14.2 lib/aruba/api/text.rb
aruba-0.14.2 lib/aruba/api/text.rb
aruba-0.14.1 lib/aruba/api/text.rb
aruba-0.14.0 lib/aruba/api/text.rb
aruba-0.13.0 lib/aruba/api/text.rb