Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Handle ANSI escape codes. #158

Open
junhaoliao opened this issue Dec 19, 2024 · 0 comments
Open

Handle ANSI escape codes. #158

junhaoliao opened this issue Dec 19, 2024 · 0 comments
Labels
enhancement New feature or request

Comments

@junhaoliao
Copy link
Member

junhaoliao commented Dec 19, 2024

Request

Currently, the log viewer does not support proper handling of ANSI escape codes, which are often used to add color, style, or special formatting to terminal output. When such codes are present in logs, they either appear as raw text or disrupt readability. This feature request is to enhance the log viewer by correctly interpreting and rendering ANSI escape codes.

For example, the Ray machine learning framework outputs logs with ANSI colour codes by default. These codes enhance log clarity during debugging but can clutter output when not handled properly. While this behaviour can be disabled by setting the environment variable RAY_COLOR_PREFIX=0, the default behaviour assumes support for ANSI codes and users wish not to turn it off. Proper handling in the log viewer would ensure seamless integration with Ray logs.

Possible implementation

  1. Detection of ANSI Codes: Add a parser to detect ANSI escape sequences in the log text (e.g., \033[31m for red text, \033[0m to reset formatting).
  2. Map ANSI Codes to Styles: Create a mapping of ANSI escape codes to styles supported by Monaco Editor. This might involve defining custom CSS classes or inline styles for text color, background colour, and formatting (bold, underline, etc.).
  3. (Alternative to 2.) Fallback for Unsupported Formats: If it's none-trivial to add ANSI mappings, strip ANSI codes and provide plain-text logs as a fallback.
@junhaoliao junhaoliao added the enhancement New feature or request label Dec 19, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

1 participant