Skip to content

Implement hint mode: configurable patterns, multi-pattern select, Select action#1917

Merged
christianparpart merged 6 commits intomasterfrom
feature/hint-mode-gaps-1-2-3
Mar 21, 2026
Merged

Implement hint mode: configurable patterns, multi-pattern select, Select action#1917
christianparpart merged 6 commits intomasterfrom
feature/hint-mode-gaps-1-2-3

Conversation

@christianparpart
Copy link
Copy Markdown
Member

  • Add user-configurable hint_patterns in profile YAML config (with HintPatternConfig struct, YAML parsing, documentation, and serialization). User patterns with the same name as a builtin override it; new names are appended.
  • Support pipe-separated multi-pattern selection in HintMode action (e.g. patterns: 'filepath|git_hash'), using crispy::split and std::erase_if for idiomatic filtering.
  • Implement HintAction::Select to enter vi visual mode with the matched range pre-selected, replacing the previous TODO/clipboard-copy fallback. Extended onHintSelected interface to pass match coordinates.
  • Added error handling for invalid user regex (try/catch with log warning), warning on unrecognized pattern names, and std::move optimization for HintMatch.

Partial fix for #1864 (remaining: wrapped/logical line handling, scope parameter).

…ion, Select action

Address three remaining acceptance criteria from issue #1864:

1. User-configurable hint patterns via `hint_patterns` in profile YAML config.
   Users can define custom regex patterns or override builtins by name.

2. Pipe-separated multi-pattern selection (e.g. `patterns: 'filepath|git_hash'`)
   using crispy::split and std::erase_if for idiomatic filtering.

3. HintAction::Select now enters vi visual mode with the match range
   pre-selected, replacing the previous TODO/clipboard-copy fallback.

Also includes: try/catch for invalid user regex in config, warning log
on unrecognized pattern names, and std::move optimization for HintMatch.

Signed-off-by: Christian Parpart <christian@parpart.family>
@christianparpart christianparpart added the no changelog Tells the CI to not require a changelog entry label Mar 21, 2026
@github-actions github-actions bot added VT: Backend Virtual Terminal Backend (libterminal API) frontend Contour Terminal Emulator (GUI frontend) test Unit tests labels Mar 21, 2026
Signed-off-by: Christian Parpart <christian@parpart.family>
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Adds a more capable “hint mode” by allowing user-configurable regex patterns, multi-pattern selection via patterns (pipe-separated), and a new HintAction::Select that transitions into vi visual mode with the match pre-selected.

Changes:

  • Extend HintModeHandler::Executor::onHintSelected to include match coordinates (start/end).
  • Merge profile hint_patterns with built-ins and support multi-pattern selection in TerminalSession.
  • Implement HintAction::Select to enter vi visual mode and select the matched range.

Reviewed changes

Copilot reviewed 9 out of 9 changed files in this pull request and generated 6 comments.

Show a summary per file
File Description
src/vtbackend/Terminal.h Updates HintModeExecutor::onHintSelected signature to include match coordinates.
src/vtbackend/Terminal.cpp Implements HintAction::Select behavior using vi visual mode and cursor movement.
src/vtbackend/HintModeHandler_test.cpp Updates mock executor to capture start/end coordinates.
src/vtbackend/HintModeHandler.h Documents the extended onHintSelected contract (text + coordinates).
src/vtbackend/HintModeHandler.cpp Passes moved HintMatch (including coordinates) into onHintSelected.
src/contour/TerminalSession.cpp Merges user patterns with built-ins and filters patterns by pipe-separated names.
src/contour/ConfigDocumentation.h Adds documentation block for hint_patterns.
src/contour/Config.h Introduces HintPatternConfig, wires it into TerminalProfile, and adds serialization.
src/contour/Config.cpp Loads hint_patterns from YAML into profile configuration.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

- TerminalSession.cpp: Preserve merged user+builtin patterns as fallback
  when no requested names match, instead of dropping user patterns
- Config.h: Fix YAML serialization to use writer indentation and escape
  single quotes in regex strings
- Config.cpp: Improve log message for skipped hint patterns to include
  name and regex for easier debugging, remove trailing newline
- HintModeHandler.h: Clarify docstring that coordinates are viewport-relative
  (line 0 = first visible line), not absolute grid coordinates
- HintModeHandler_test.cpp: Add coordinate assertions to ProgressiveFiltering
  test to verify start/end are forwarded correctly
- Terminal.cpp: Fix HintAction::Select to convert viewport-relative coordinates
  to grid-relative using scroll offset, and clear existing selection before
  entering visual mode to prevent stale anchor reuse

Signed-off-by: Christian Parpart <christian@parpart.family>
Add an optional transformer function to HintPattern that rewrites matched
text before storing in HintMatch. The overlay still shows the original
terminal text, but Copy/Open/Paste actions use the transformed (absolute)
path.

In Terminal::activateHintMode, extract the path resolution logic into a
shared lambda used by both the validator (filesystem existence check) and
the new transformer (relative-to-absolute conversion). This ensures that
copying a filepath hint like "src/foo.cpp" yields the full path
"/home/user/project/src/foo.cpp", and opening it passes a resolvable
absolute path to the system's URL handler.

Signed-off-by: Christian Parpart <christian@parpart.family>
- Terminal.cpp: Restore old behavior for ~/ paths when HOME is unset:
  the validator lets them through unvalidated, and the transformer
  returns the match unchanged. Fixes regression where ~/ hints were
  silently suppressed in environments without HOME.
- Terminal.cpp: Use std::error_code overload of std::filesystem::exists
  to prevent exceptions on permission errors during hint scanning.
- TerminalSession.cpp: Avoid unconditional deep-copy of all patterns
  (including compiled regex objects) for the rare fallback case. Check
  whether any name matches before erasing, skip mutation if none match.

Signed-off-by: Christian Parpart <christian@parpart.family>
@github-actions github-actions bot added the documentation Improvements or additions to documentation label Mar 21, 2026
- docs/demo/hint-mode.md: Add "Custom Patterns" section explaining
  hint_patterns profile config with YAML examples. Add "Path Resolution"
  section explaining that relative paths are resolved to absolute for
  Copy/Open actions. Document pipe-separated multi-pattern syntax
  (e.g. 'filepath|githash'). Update Select action description to
  reflect the now-implemented vi visual mode pre-selection.
- ConfigDocumentation.h: Add HintMode to the InputMappingsConfig action
  list with parameters documentation. It was the only action missing
  from the generated config comments.

Signed-off-by: Christian Parpart <christian@parpart.family>
@christianparpart christianparpart force-pushed the feature/hint-mode-gaps-1-2-3 branch from cb3ff69 to cf128b3 Compare March 21, 2026 09:56
@github-actions github-actions bot added the CI GitHub Actions & CI label Mar 21, 2026
@data-man
Copy link
Copy Markdown
Contributor

I'd suggest using SRELL instead of std::regex.
I maintain the mirror at https://github.com/ZimProjects/SRELL.

@christianparpart
Copy link
Copy Markdown
Member Author

I'd suggest using SRELL instead of std::regex. I maintain the mirror at https://github.com/ZimProjects/SRELL.

this sounds like an amazing regex implementation. I definitely prefer stdlib over custom 3rdparties, however, they actually have a value (Unicode) over stdlib. Maybe we do that at a later stage. :)

@christianparpart christianparpart merged commit f3806b2 into master Mar 21, 2026
32 checks passed
@christianparpart christianparpart deleted the feature/hint-mode-gaps-1-2-3 branch March 21, 2026 15:43
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

CI GitHub Actions & CI documentation Improvements or additions to documentation frontend Contour Terminal Emulator (GUI frontend) no changelog Tells the CI to not require a changelog entry test Unit tests VT: Backend Virtual Terminal Backend (libterminal API)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants