I have this YAML data:
data.yml
game:
welcome: Welcome to \e[34myour\e[0m new chess game players.\n\n
which I am successfully accessing with:
puts data['game']['welcome']
however when output to terminal neither the ansi escape character formatting nor the newline formatting is working. It just prints out all of the characters literally. I have tried/checked:
- terminal is using UTF-8 encoding and does print ansi escape formatting when directly used on string characters on a ruby programme.
- tried escaping the escape characters with another
\character, e.g. \e[34myour\e[0m. This doesn’t work.
Any ideas how I might be able to get this working? Thanks
>Solution :
YAML only allows escape character sequences in double-quoted scalars. See section 5.7 Escaped Characters of the YAML specification [bold italic emphasis mine]:
5.7. Escaped Characters
All non-printable characters must be escaped. YAML escape sequences use the “
\” notation common to most modern computer languages. Each escape sequence must be parsed into the appropriate Unicode character. The original escape sequence is a presentation detail and must not be used to convey content information.Note that escape sequences are only interpreted in double-quoted scalars. In all other scalar styles, the “
\” character has no special meaning and non-printable characters are not available.