Skip to content

Conversation

@vincentullmann
Copy link
Contributor

Changelog Description

adds a syntax highlighting to the Console Widget

Additional info

as for the theme I went with "github-dark" as I figured this might be one of the most common ones used/seen,
but since its a mater of personal preference I added an option to customise it.

background color:

I'm not sure if setting the background color is a good idea.
technically we should as otherwise some styles dont work. for example a light style is very hard to read on the default dark background,
but it also breaks the overall look of the widget.

but then... who even uses light themes anyways? :D

Github Dark
image

Github Dark (without background)
image

Monokai:
image

Monokai (wihtout background)
image

staroffice (with and without)
image

@ynbot ynbot added the size/XS label Jan 15, 2026
@vincentullmann
Copy link
Contributor Author

note:

the github-dark" style in pygments doesn't seem to exactly match.
I found this one which is closer https://github.com/TDKorn/sphinx-github-style/blob/v1.2.2/sphinx_github_style/github_style.py but also not perfect

image

@BigRoy BigRoy self-assigned this Jan 15, 2026
@BigRoy BigRoy self-requested a review January 15, 2026 19:26
Copy link
Collaborator

@BigRoy BigRoy left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I quite like it!

image

But I do feel the darker background color feels off for AYON.

I actually think from your screenshots Github dark without background and Monokai without background are pretty good candidates for a default. @iLLiCiTiT @mkolar thoughts?
I personally like Monokai, but I can see reasons to go for the Github dark one since it may be more popular. Either is fine for me.

Especially nice to give this console some more polish since we're now looking to embed it with a few integrations (e.g. After Effects just got it - based on client request)

All we need next is some good autocomplete and tooltips over functions and it's pretty darn nice.


I wonder why imports don't look good though.
image

Comment on lines 54 to 57
if not self.style:
all_styles = ", ".join(pygments.styles.get_all_styles())
msg = f"'{style_name}' not found. Installed styles: {all_styles}"
raise ValueError(msg)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just for the edge cases - I wonder if this should just log a warning or error and continue without any styling?

@BigRoy BigRoy requested review from iLLiCiTiT and mkolar January 15, 2026 19:34
@vincentullmann
Copy link
Contributor Author

I wonder why imports don't look good though.

Not sure why, but the "github-dark" style shiped with pygments uses "Red" for the "Namespace" Tokens.
https://github.com/pygments/pygments/blob/master/pygments/styles/gh_dark.py#L77

ran a quick test to confirm: imports are tokenized as "Namespace"

from pygments.lexers import PythonLexer

lexer = PythonLexer()
for token, value in lexer.get_tokens("import os"):
    print(token, value)
Token.Keyword.Namespace import
Token.Text.Whitespace  
Token.Name.Namespace os
Token.Text.Whitespace 

I guess the best way to fix this would be to provide a custom "AYON" Theme based on this: #1651 (comment)

… apply no background color

Also remove walrus operator for backwards compatibility
@BigRoy
Copy link
Collaborator

BigRoy commented Jan 16, 2026

I've pushed a dedicated AYON style into the codebase - that matches the GH dark style somewhat but without background color.

image

@BigRoy
Copy link
Collaborator

BigRoy commented Jan 16, 2026

@iLLiCiTiT can you review?

@iLLiCiTiT
Copy link
Member

iLLiCiTiT commented Jan 16, 2026

Where is pygments comming from? I don't see it in AYON launcher nor in dependency packages.

It should be added to pyproject.toml in client directory. All code that is using pygments should be moved to one file and safe imported if it fails to import pygments then just don't use highlight.

@vincentullmann
Copy link
Contributor Author

vincentullmann commented Jan 16, 2026

Where is pygments comming from? I don't see it in AYON launcher nor in dependency packages.

It should be added to pyproject.toml in client directory. All code that is using pygments should be moved to one file and safe imported if it fails to import pygments then just don't use highlight.

I just saw its part of the dependency package, so I figured it would be safe to use it :D
Upon further inspection it seems its only there due to a single 2nd order dependency.

uv tree | grep -A5 -B20 pygments
Resolved 93 packages in 1ms
├── ftrack-python-api v3.0.5
│   ├── arrow v0.17.0
│   │   └── python-dateutil v2.9.0.post0
│   │       └── six v1.17.0
│   ├── clique v1.6.1
│   ├── platformdirs v4.5.1
│   ├── pyparsing v2.4.7
│   ├── requests v2.32.5 (*)
│   ├── sphinx-notfound-page v1.1.0
│   │   └── sphinx v9.0.4
│   │       ├── alabaster v1.0.0
│   │       ├── babel v2.17.0
│   │       ├── docutils v0.22.4
│   │       ├── imagesize v1.4.1
│   │       ├── jinja2 v3.1.6
│   │       │   └── markupsafe v3.0.3
│   │       ├── packaging v25.0
│   │       ├── pygments v2.19.2
│   │       ├── requests v2.32.5 (*)

I will add it to the pyproject.toml.

edit: and, but not sure how relevant this is for the client side: it is also part of the backend-dependency stack

Resolved 104 packages in 1ms
├── pyyaml v6.0.2
├── redis v5.2.1
├── rich v13.9.4
│   ├── markdown-it-py v3.0.0
│   │   └── mdurl v0.1.2
│   └── pygments v2.19.1

try:
highlighter = PythonSyntaxHighlighter(self.document())
except ValueError as e:
print(f"Error applying syntax highlighter: {e!s}")
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wasn't able to find an easy way to access a logger instance in this context,
so I went with a print for now.

is there any existing logger around we could use here?

Image

@iLLiCiTiT iLLiCiTiT changed the title add PythonSyntaxHighlighter to the PythonCodeEditor Widget Console Widget: Add PythonSyntaxHighlighter Jan 16, 2026
@iLLiCiTiT iLLiCiTiT added community Issues and PRs coming from the community members type: enhancement Improvement of existing functionality or minor addition labels Jan 16, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

community Issues and PRs coming from the community members size/XS type: enhancement Improvement of existing functionality or minor addition

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants