Module: Strings::ANSI
- Defined in:
- lib/strings/ansi.rb,
lib/strings/ansi/version.rb,
lib/strings/ansi/extensions.rb
Overview
Helper functions for handling ANSI escape sequences
Defined Under Namespace
Modules: Extensions
Constant Summary collapse
- CSI =
The control sequence indicator
"\033"
- RESET =
The code for reseting styling
"\e[0m"
- ANSI_MATCHER =
The regex to match ANSI codes
'(\[)?\033(\[)?[;?\d]*[\dA-Za-z]([\];])?'
- VERSION =
"0.2.0"
Class Method Summary collapse
-
.ansi?(string) ⇒ Boolean
Check if string contains ANSI codes.
-
.only_ansi?(string) ⇒ Boolean
Check if string contains only ANSI codes.
-
.sanitize(string) ⇒ String
Return a copy of string with ANSI characters removed.
Class Method Details
.ansi?(string) ⇒ Boolean
Check if string contains ANSI codes
45 46 47 |
# File 'lib/strings/ansi.rb', line 45 def ansi?(string) !!(string =~ /#{ANSI_MATCHER}/) end |
.only_ansi?(string) ⇒ Boolean
Check if string contains only ANSI codes
65 66 67 |
# File 'lib/strings/ansi.rb', line 65 def only_ansi?(string) !!(string =~ /^(#{ANSI_MATCHER})+$/) end |
.sanitize(string) ⇒ String
Return a copy of string with ANSI characters removed
28 29 30 |
# File 'lib/strings/ansi.rb', line 28 def sanitize(string) string.gsub(/#{ANSI_MATCHER}/, '') end |