Repository navigation
Conversation
[Medium impact] The PR appears safe to merge; all three previous findings are fixed. SummaryAdds theme-colored source previews through optional
Review used source inspection; tests were not run.
|
A source file was previewed as plain text. Its lines now come in the theme's colors, as bat reads them: the first 400 with the text, a longer file's others once bat is through it. Without bat the text is shown as it was.
The details showed a source file's first lines as plain text. They now come in the theme's colors, read with the text and laid out as the plain lines are. Without bat nothing changes.
thisisgm
force-pushed
the
code-colours
branch
from
November 12, 2026 23:24
d2128d1 to
e2606a7
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
A source file is previewed as one block of plain text: Space shows it in a single ink, and so do its opening lines in the details pane. With these two commits both draw it in color, in the colors of the theme in use. The colors are read by
bat, which Omarchy already installs (omarchy-base.packages), run with itsansitheme so that it names six terminal colors and nothing else, and Folio draws those six in the current theme's red, green, yellow, blue, magenta and cyan. The suite goes from 196 to 202 tests. No library is linked and nothing is added to the build; wherebatisn't installed a source file is shown as it is today.What you'd notice
batgives them, for every languagebatknows.colors.toml. Picking another theme recolors an open preview and the details at once.batis sent); the lines after it get their colors whenbathas read the whole text, and nothing but the ink changes when they do.batisn't run for them, in the preview or in the details.Pictures
A mini PC, the same folder,
mainon the left and this branch on the right.The same file on three stock themes, one of them light,
mainabove and this branch below.What it costs
batis run once for a source file that is previewed, a second time for one that goes on past its opening, and once for the 41 lines the details pane shows, always off the UI thread. A plain text and a Markdown file wait for nothing. On a mini PC that was otherwise idle (load 0.7), 25 runs ofbateach, as Folio runs it:So a source file's text appears 13 to 27 ms later than on
main, already in color, and the lines of a 4,000 line file past the first 400 get theirs about 170 ms after that. Long lines are why the opening is also held to 16 KiB: one line of minified JavaScript takesbat23 ms at 4 KiB, 33 ms at 8 KiB and 50 ms at 16 KiB (the same mini PC, load 0.01, three runs each). A text whose first line is longer than that is shown at once and colored by the one run over the whole text. A run is given up on after half a second for the opening and five seconds for a whole text, and one for a whole text is stopped as soon as another file is shown or the preview is closed.On the UI thread, measured on a Linux server with a 128 KiB text of 2,721 lines, six runs: showing the text with its first 400 lines colored takes 16.9 to 19.0 ms, against 14.4 to 16.6 ms for the plain text; the colors of the remaining lines are then applied in one step of 27.9 to 31.0 ms. (Applying them line by line with
QSyntaxHighlighter::rehighlight()took 537 to 552 ms, which is why they aren't.)What stays the same
bat, with one that fails, or with one that hasn't answered in half a second, the text is shown plain, as onmain. One that prints far more than colors could take is stopped, or left unread when it has already ended, and what it prints on its standard error is never kept.batis run with--no-config: a pager, line numbers or a theme in the user's ownbatsettings can't change what is shown. It reads the text Folio has already read, on its standard input, so no file is opened a second time and the preview's 128 KiB limit holds.batread. If the two ever differ, that line stays plain.green, read fromcolors.tomllike the other colors with a fallback beside theirs, andcodeInks, the six as code is drawn in them. No other color of the theme changes.Tests
Six new cases, all of which fail on the sources of
main:codeColorsReadWhatBatPrints: the escape sequencesbatprints become runs of the six inks, an ink carries across a line end, bright codes count as their plain ones, black, white and a reset end an ink, and colors by number and sequences that aren't colors are passed over.codeColorsPaintTheLinesTheyWereReadFrom: a realTextEditis colored in the given inks, takes another theme's inks at once, leaves a line plain when the text has moved on, handles Windows line ends, and tells the text's layout of new colors once, not line by line.previewerColorsCode: with a stand-inbat, the text and its colors arrive in one change; a plain text and a Markdown file never run it; a long file shows its opening colored and gets the rest with no change to the text; 400 lines are run once and a 401st makes it two; long lines cut the opening at 16 KiB, counted in bytes, so sooner for letters of three bytes, and a first line longer than that isn't waited for; a file stepped past before it was read isn't given tobat; a run on a whole text is stopped when another file is shown, even when the first is shown again right after, or when the preview is closed, and colors that arrive for a file no longer shown are dropped; a missing, failing, stuck or endlessly printingbat, or one that prints too much and ends at once, leaves plain text, a stuck one long before the five seconds a whole text is given.previewWindowDrawsCodeInTheThemesInks: the realPreviewWindow.qmldraws a C file's words in the theme's magenta and green, and in another theme's as soon as it is picked.detailsColorTheOpeningLinesOfCode: the details carry the colors with the text in one change and lose them when the same file is read again withoutbat; a plain text and a Markdown file never run it; abatthat never answers holds the lines back half a second at most; a realPreviewPanedraws them with the same line count, width and height as the plain text, tabs and Windows line ends included, and in another theme's colors as soon as it is picked.themeDrawsCodeInInksThatReadOnItsBackgrounds: a theme whose six colors read is drawn in exactly those; a yellow too faint for a light theme is darkened and a red too deep for a dark one lightened, each to 4.5:1 against the nearer background and no further, with its hue kept.91 single changes to the sources (a limit, a bound, a missing check, a swapped ink) were each tried alone, and each made one of these six cases fail: 89 by a failed check, one by a run that never ended and one by a crash. Each commit builds without warnings and passes the suite on its own, also with
TMPDIRset to a folder whose name has a space, where onlyextractRefusesWhatWouldLandOutsidefails, as it does onmain.