Implement hint mode: configurable patterns, multi-pattern select, Select action#1917
Conversation
…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>
Signed-off-by: Christian Parpart <christian@parpart.family>
There was a problem hiding this comment.
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::onHintSelectedto include match coordinates (start/end). - Merge profile
hint_patternswith built-ins and support multi-pattern selection inTerminalSession. - Implement
HintAction::Selectto 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>
- 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>
cb3ff69 to
cf128b3
Compare
|
I'd suggest using SRELL instead of |
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. :) |
hint_patternsin profile YAML config (withHintPatternConfigstruct, YAML parsing, documentation, and serialization). User patterns with the same name as a builtin override it; new names are appended.HintModeaction (e.g.patterns: 'filepath|git_hash'), usingcrispy::splitandstd::erase_iffor idiomatic filtering.HintAction::Selectto enter vi visual mode with the matched range pre-selected, replacing the previous TODO/clipboard-copy fallback. ExtendedonHintSelectedinterface to pass match coordinates.std::moveoptimization forHintMatch.Partial fix for #1864 (remaining: wrapped/logical line handling,
scopeparameter).