module Aruba::Api::Text

Text manipulation

Public Instance Methods

extract_text(text) click to toggle source

Remove ansi characters from text

@param [#to_s] text

Input
# File lib/aruba/api/text.rb, line 31
def extract_text(text)
  text
    .gsub(/(?:\e|\033)\[\d+(?>(;\d+)*)m/, "")
    .gsub(/\\\[|\\\]/, "")
    .gsub(/\007|\016|\017/, "")
end
replace_variables(text) click to toggle source

Replace variables in command string (experimental)

@param [#to_s] text

The text to parse
# File lib/aruba/api/text.rb, line 53
def replace_variables(text)
  if text.include? "<pid-last-command-started>"
    text = text.gsub(/<pid-last-command-started>/, last_command_started.pid.to_s)
  end

  text
end
sanitize_text(text) click to toggle source

Unescape special characters and remove ANSI characters

@param [#to_s] text

The text to sanitize
# File lib/aruba/api/text.rb, line 42
def sanitize_text(text)
  text = unescape_text(text)
  text = extract_text(text) if aruba.config.remove_ansi_escape_sequences

  text.chomp
end
unescape_text(text) click to toggle source

Unescape text

'n' => “n” 'e' => “e” '033' => “e” '"' => '“'

@param [#to_s] text

Input
# File lib/aruba/api/text.rb, line 16
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