Module: OllamaChat::Utils::StripANSI
- Defined in:
- lib/ollama_chat/utils/strip_ansi.rb
Overview
Strips ANSI escape sequences from a string.
Handles both SGR (Select Graphic Rendition) sequences like
\e[38;2;255;128;0m and OSC (Operating System Command) sequences
like \e]0;title\a or \e]8;;url\e\\.
Constant Summary collapse
- ANSI_RE =
/\e\[[0-9;?]*[A-Za-z]|\e\].*?(\e\\|\a)/m
Class Method Summary collapse
-
.strip_ansi(line) ⇒ String
Removes all ANSI escape sequences from the given string.
Instance Method Summary collapse
-
#strip_ansi(line) ⇒ String
private
Removes all ANSI escape sequences from the given string.
Class Method Details
.strip_ansi(line) ⇒ String
Removes all ANSI escape sequences from the given string.
19 20 21 |
# File 'lib/ollama_chat/utils/strip_ansi.rb', line 19 def strip_ansi(line) line.to_s.gsub(ANSI_RE, '') end |
Instance Method Details
#strip_ansi(line) ⇒ String (private)
Removes all ANSI escape sequences from the given string.
19 20 21 |
# File 'lib/ollama_chat/utils/strip_ansi.rb', line 19 def strip_ansi(line) line.to_s.gsub(ANSI_RE, '') end |