Repository navigation
Allow regex-based terminal text highlighting (#2788) - #4015
austinywang wants to merge 13 commits into
Conversation
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
📝 WalkthroughWalkthroughAdds regex-based automatic terminal text highlighting with user-configurable patterns and colors. Includes data models, settings persistence with notifications, pattern matching against visible terminal text, viewport-synchronized overlay rendering, and full settings UI integration. ChangesRegex-based Terminal Text Highlighting
Estimated code review effort🎯 4 (Complex) | ⏱️ ~60 minutes Possibly related PRs
Poem
Caution Pre-merge checks failedPlease resolve all errors before merging. Addressing warnings is optional.
❌ Failed checks (6 errors, 1 warning, 1 inconclusive)
✅ Passed checks (9 passed)
✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
Greptile SummaryAdds regex-based automatic text highlighting for visible terminal output. Users configure patterns (one per line, with an optional
Confidence Score: 5/5Presentation-only change with no auth, data, or persistence risk; the overlay is non-interactive and clears when the view is hidden or detached. All previous review concerns (regex recompilation per scroll, DispatchWorkItem debounce, Thread.isMainThread guard, wide-character column alignment) are addressed in this revision. The Task-based coalescing correctly handles cancellation before the task runs via the isCancelled guard. The NSLock-protected static cache for hasRuntimeRules() on the render thread is correctly scoped and non-reentrant. Localization covers all 20 supported locales. Schema, search index, settings file import, unit tests, and the end-to-end screenshot test are all wired. No files require special attention. Important Files Changed
Sequence DiagramsequenceDiagram
participant User as User / cmux.json
participant Settings as TerminalRegexHighlightSettings
participant ScrollView as GhosttySurfaceScrollView
participant Ghostty as Ghostty (render thread)
participant NSView as GhosttyNSView
participant Overlay as TerminalRegexHighlightOverlayView
User->>Settings: setRawHighlights() / notifyDidChange()
Settings-->>ScrollView: didChangeNotification (main queue)
ScrollView->>ScrollView: reloadRegexHighlightRules() compile NSRegularExpressions once
ScrollView->>ScrollView: "scheduleRegexHighlightRefresh() Task { @MainActor }"
Ghostty->>NSView: handleAction(GHOSTTY_ACTION_RENDER)
NSView->>Settings: hasRuntimeRules() [lock-guarded cache]
NSView->>NSView: flag + DispatchQueue.main.async
NSView-->>ScrollView: scheduleRegexHighlightRefreshAfterRender()
ScrollView->>ScrollView: scheduleRegexHighlightRefresh() coalesced: no-op if task pending
Note over ScrollView: Task runs on next MainActor turn
ScrollView->>Ghostty: ghostty_surface_read_text (viewport)
Ghostty-->>ScrollView: raw UTF-8 text
ScrollView->>ScrollView: TerminalRegexHighlightMatcher.runs() wide-char column math + 512-match cap
ScrollView->>Overlay: configure(runs:metrics:)
Overlay->>Overlay: "needsDisplay = true / draw() NSBezierPath rounded rects"
Reviews (8): Last reviewed commit: "Normalize Xcode project after merge" | Re-trigger Greptile |
There was a problem hiding this comment.
Cursor Bugbot has reviewed your changes and found 2 potential issues.
❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, enable autofix in the Cursor dashboard.
Reviewed by Cursor Bugbot for commit 1086baa. Configure here.
There was a problem hiding this comment.
Actionable comments posted: 4
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@Resources/Localizable.xcstrings`:
- Around line 105483-105516: The two new localization keys
settings.terminal.regexHighlights and settings.terminal.regexHighlights.subtitle
only include en and ja; add matching entries for every locale already present in
this Resources/*.xcstrings catalog (copy other keys’ locales as a template),
providing translated "stringUnit" values with "state":"translated" and the
appropriate localized strings for each locale; ensure the same structure
(extractionState, localizations → <locale> → stringUnit) is used so the catalog
contains a translation entry for every supported locale.
In `@Sources/App/WorkspaceRuntimeSettings.swift`:
- Around line 338-379: The current scalar-based width logic causes mismatches
for multi-scalar grapheme clusters; change terminalColumnWidth(_ text:
Substring) to iterate over grapheme clusters (for character in text) and compute
each cluster's cell width by inspecting that Character's Unicode scalars: if all
scalars are zero-width (use the existing terminalColumnWidth(for:) checks for 0,
ZWJ, variation selectors and generalCategory) treat the cluster as width 0;
otherwise treat the cluster as wide (2) if any scalar in the cluster matches
isWideTerminalScalar(_:) and not otherwise zero-width, else width 1; update any
matcher code in TerminalRegexHighlightOverlayView that relied on per-scalar
accumulation to call the revised terminalColumnWidth(_:) so
run.column/run.length reflect grapheme cell widths.
- Around line 304-330: The code in TerminalRegexHighlightMatcher.runs currently
calls compiledRule.expression.matches(in:range:), which materializes all matches
before you can enforce maxRuns; replace that call with
compiledRule.expression.enumerateMatches(in:options:range:using:) and in the
enumeration closure process each non-optional match (remove the unnecessary
optional binding), compute column/length/clippedLength as before, append
TerminalRegexHighlightRun items, and when runs.count >= maxRuns set the stop
pointer to true to terminate enumeration early; ensure you keep the existing
logic around maxColumnCount and terminalColumnWidth and preserve the
early-continue guards but remove any code that assumed match could be nil.
In `@Sources/GhosttyTerminalView.swift`:
- Around line 12668-12713: This deferred refresh must use
TerminalSurface.liveSurfaceForGhosttyAccess(reason:) instead of reading
surfaceView.terminalSurface?.surface directly because the native surface can be
torn down between scheduling and execution; update the code block that reads and
checks the surface (currently using surfaceView.terminalSurface?.surface,
cmuxSurfacePointerAppearsLive, ghostty_surface_size and readViewportText) to
call surfaceView.terminalSurface?.liveSurfaceForGhosttyAccess(reason: "<describe
purpose>"), guard the returned live surface/token is non-nil, use that live
surface for ghostty_surface_size and readViewportText (and any cmux checks),
then release/let the live access scope end per the liveSurfaceForGhosttyAccess
API before returning; keep the existing fallbacks that call
regexHighlightOverlayView.clear() on early failure and then pass the obtained
surface into TerminalRegexHighlightMatcher.runs and metrics as before.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Path: .coderabbit.yaml
Review profile: ASSERTIVE
Plan: Pro
Run ID: 92b0ba2c-f9ef-4352-b925-b2cb658e32fd
📒 Files selected for processing (14)
GhosttyTabs.xcodeproj/project.pbxprojResources/Localizable.xcstringsSources/App/WorkspaceRuntimeSettings.swiftSources/CmuxSettingsJSONPathSupport.swiftSources/GhosttyTerminalView.swiftSources/KeyboardShortcutSettingsFileStore+Template.swiftSources/KeyboardShortcutSettingsFileStore.swiftSources/SettingsNavigation.swiftSources/TerminalRegexHighlightOverlayView.swiftSources/cmuxApp.swiftcmuxTests/AgentSessionAutoResumeSettingsTests.swiftcmuxTests/KeyboardShortcutSettingsFileStoreStartupTests.swiftweb/app/[locale]/docs/configuration/page.tsxweb/data/cmux.schema.json
There was a problem hiding this comment.
3 issues found across 14 files
Reply with feedback, questions, or to request a fix.
Re-trigger cubic
All CodeRabbit inline comments from this older review were addressed in later commits, the related review threads are resolved, and the current CodeRabbit check is green on the latest branch head.
…light # Conflicts: # Sources/CmuxSettingsJSONPathSupport.swift # Sources/GhosttyTerminalView.swift # Sources/KeyboardShortcutSettingsFileStore+Template.swift # Sources/KeyboardShortcutSettingsFileStore.swift # Sources/TerminalController.swift # Sources/cmuxApp.swift # cmux.xcodeproj/project.pbxproj # web/app/[locale]/docs/configuration/page.tsx # web/data/cmux.schema.json

Closes #2788
Summary
Testing
Note
Medium Risk
New overlay path in GhosttyTerminalView runs user-supplied regex on viewport text each refresh; invalid patterns are skipped but complex rules could affect performance on busy terminals.
Overview
Adds regex-based automatic text highlights for visible terminal output: users define one pattern per line (optional
#RRGGBB/#RRGGBBAA+ tab for color) via Settings → Terminal,terminal.regexHighlightsin cmux.json, schema/docs, and settings search.Runtime:
TerminalRegexHighlightSettingsparses and caches compiled rules;TerminalRegexHighlightMatcherfinds matches with terminal column width (wide CJK/emoji), caps at 512 runs, and skips invalid regexes. A passthroughTerminalRegexHighlightOverlayViewdraws colored rounded rects over the Ghostty surface; refresh is coalesced after render, scroll, resize, visibility, and settings changes.Tests: Unit tests for parsing/matching; a Python regression uses full-window screenshot (not panel snapshot) so overlays are visible. Screenshot window selection is tightened so capturable windows are chosen reliably.
Reviewed by Cursor Bugbot for commit e500218. Bugbot is set up for automated code reviews on this repo. Configure here.
Summary by cubic
Adds regex-based automatic highlighting for visible terminal text with per‑rule colors. Highlights align to terminal columns and refresh after render and viewport changes. Closes #2788.
New Features
#RRGGBBor#RRGGBBAA+ tab; default#FFE06680.cmux.json(string or array). Docs, schema, localization, search, template examples, and tests added.Bug Fixes
Written for commit e500218. Summary will update on new commits.
Summary by CodeRabbit
Release Notes
New Features
Documentation
Tests