julia
bcbea400 - WIP: Read the terminal colour scheme on REPL startup (#59958)

Commit
116 days ago
WIP: Read the terminal colour scheme on REPL startup (#59958) Wouldn't it be nice if Julia/the REPL knew what your terminal colours were, and displayed content appropriately? This introduces light/dark theme detection, as well as your ANSI 8-colour theme. With this capability, we can avoid accidental low-contrast highlights and related issues that will only become worse as we try to extend the graphical capabilities of the REPL. Sneak peek: <img width="450" height="auto" alt="image" src="https://github.com/user-attachments/assets/b084961e-6602-4dd2-b8bf-af319376910c" /> ### Query durations - initial query on a local machine: ~0.1s (which I suspect is due to other work that gets scheduled before the response is read) - subsequent queries on a local machine: <0.01s - initial query over SSH (100ms latency): ~0.3s > [!IMPORTANT] > This is asynchronous, and does not impact startup latency ## Tested terminals <details> <summary> Test script </summary> ```julia using StyledStrings let (; FACES, SimpleColor, rgbcolor) = StyledStrings # Grab some private API colors = Iterators.flatten((c, Symbol("bright_" * String(c))) for c in [:black, :green, :cyan, :blue, :magenta, :red, :yellow, :white]) println(styled"{bold: Swatch test Read Actual}\n ", '━'^30) termfg, termbg = @. SimpleColor(rgbcolor((:foreground, :background))) println(styled" foreground {(bg=$termfg): } {inverse: }") println(styled" background {light,grey:▕{(bg=$termbg): }▏ ▕{: }▏}") for color in colors termc = SimpleColor(FACES.basecolors[color]) println(styled" $(lpad(color, 14)) {(bg=$termc): } {(bg=$color): }") end print(styled"\n {bold:Platform:} {emphasis:$(Sys.KERNEL){grey:/}$(ENV[\"TERM\"])} {grey:(truecolor }") println(if Base.ttyhastruecolor() styled"{green,bold:✓}" else styled"{red,bold:✕}" end, styled"{grey:)}") println(styled" Do the swatches match?") end ``` </details> ### Everything works * Linux * Kitty * Wezterm * Foot * Ghostty * Xterm * Alacritty * St (Suckless) * Ubuntu terminal (Gnome terminal?) * Tilix * Mac * Terminal.app * iTerm2 * WezTerm * Alacritty * Ghostty * Kitty * Windows * Windows terminal (it messes up inverse video though) * Windows terminal: WSL ### Misbehaving (terminal's fault) * Linux * Konsole (lies about values) * Emacs * Eat (doesn't supply colours) * Vterm (doesn't report anything) * Mac * iTerm2 + Tmux (doesn't report anything) * Windows * Wezterm via Ubuntu WSL (doesn't report anything) ### Misbehaving (our fault) * Nothing yet :slightly_smiling_face:
Author
Parents
Loading