Skip to content

feat: file preview with syntax highlighting#57

Merged
nrjdalal merged 3 commits into
mainfrom
feat/syntax-highlight
Mar 22, 2026
Merged

feat: file preview with syntax highlighting#57
nrjdalal merged 3 commits into
mainfrom
feat/syntax-highlight

Conversation

@nrjdalal
Copy link
Copy Markdown
Owner

Summary

  • Vendor @speed-highlight/core for terminal ANSI syntax highlighting (zero runtime deps)
  • 38 languages supported with auto-detection by file extension
  • Highlights code in the file preview when pressing enter on a file

Size impact

  • Packed: 14kb -> 24kb (+10kb for syntax highlighting engine)
  • Unpacked: 38kb -> 63kb

Full Changelog: stacked on #feat/file-preview

🤖 Generated with Claude Code

nrjdalal and others added 3 commits March 22, 2026 06:31
Vendor @speed-highlight/core for terminal ANSI syntax highlighting.
Supports 38 languages with auto-detection by file extension.
Zero runtime dependencies - library is vendored.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
const lang = detectLang(node.name)
if (lang !== "plain") {
try {
content = await highlightText(text, lang)
Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

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

Because highlightText() is async, preview mode is no longer entered atomically. onKey() fires showPreview() and returns immediately, but the stdin listener is only swapped after the await resolves. On larger files, any keys pressed during highlighting are still handled by the main picker, so users can move the cursor, toggle selections, or even quit before the preview opens. It would be safer to either await showPreview() from an async key handler or detach onKey before starting the highlight work.

@nrjdalal
Copy link
Copy Markdown
Owner Author

Review score: 6.5/10\n\nThe feature direction is strong and the repo still builds and passes the full test suite (132 passing), but I found two interactive preview issues worth fixing before merge:\n\n1. Preview entry is now asynchronous, so keystrokes can still mutate the picker state while highlighting is in flight.\n2. Highlighted output is rendered with ANSI escapes, but the preview truncation logic is not ANSI-aware, so long colored lines can display incorrectly.\n\nInline comments are on the relevant lines.

} else {
content = raw.toString("utf-8")
const text = raw.toString("utf-8")
const lang = detectLang(node.name)
Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

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

Highlighting changes content from plain text to ANSI-colored text, but the preview code below still calculates width and truncates with plain string slicing. For long lines that means escape sequences can be cut in half or counted as visible columns, which corrupts the preview and can leak colors into following rows. This path probably needs ANSI-aware width/slice handling before we ship colored previews.

@nrjdalal nrjdalal changed the base branch from feat/file-preview to main March 22, 2026 01:13
@nrjdalal nrjdalal merged commit aa3d497 into main Mar 22, 2026
9 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant