Skip to content

This issue was moved to a discussion.

You can continue the conversation there. Go to discussion →

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

Applying a RegexHighlighter with a dfeined Theme to a Log #4477

Closed
b0bh00d opened this issue May 5, 2024 · 1 comment
Closed

Applying a RegexHighlighter with a dfeined Theme to a Log #4477

b0bh00d opened this issue May 5, 2024 · 1 comment

Comments

@b0bh00d
Copy link

b0bh00d commented May 5, 2024

Perhaps I'm not seeing all the pieces for this, but I'm not seeing how I can apply a RegexHighlighter:

class LogHighlighter(RegexHighlighter):
    """Apply style to anything that looks like an loguru message."""

    base_style = "snlog."
    highlights = [r"(?P<date>\d+-\d+-\d+)",
                  r"(?P<time>\d+:\d+:\d+\.\d+)",
                  r"(?P<warning>WARN)",
                  r"(?P<error>ERROR)",
                  r"(?P<fatal>FATAL)",
                  r"(?P<critical>CRITICAL)",
                  r"(?P<source>\w+:[\w_]+:\d+)",
                  r"(?P<path>^/[\w/]+)",
                  ]

with a theme:

        rich.theme.Theme({
                "snlog.date": "green",
                "snlog.time": "green",
                "snlog.warning": "yellow",
                "snlog.error": "red",
                "snlog.fatal": "bold red",
                "snlog.critical": "bold magenta",
                "snlog.source": "cyan",
                "snlog.path": "bold red",
              })

To a Textual Log widget. The widget has a highlight parameter to enable highlighting, but there are no further arguments provided to apply a different highlighter w/ a theme. The reference page for the Log widget shows a highlighter instance value, but I'm not sure if I am supposed to simply replace it. I've tried doing that, but without defining the theme, the text in the Log widget is just plain white.

I humbly request instruction to wash away my ignorance, or a means added to Log to defined this more formally.

@willmcgugan
Copy link
Collaborator

Textual doesn't expose the rich.theme, so there is no straightforward way of doing that.

You can, hover, disable automatic highlighting, and log Text instances. Rich's Text objects have a number of ways of applying styles, so you can highlight however you like.

@Textualize Textualize deleted a comment from github-actions bot May 7, 2024
@Textualize Textualize locked and limited conversation to collaborators May 7, 2024
@willmcgugan willmcgugan converted this issue into discussion #4490 May 7, 2024

This issue was moved to a discussion.

You can continue the conversation there. Go to discussion →

Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants