Repository navigation
Use a preview transformer's mode when no preview mode is requested - #1225
Merged
Merged
Conversation
The transformer's `mode` was only used to pick a transformer when a mode was explicitly requested. Otherwise the transformed file went through automatic detection, so a `tty` transformer's output was shown as text, escape sequences included. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
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.
The docs describe a transformer's
modeas how its output is displayed, includingtty"when the output contains ANSI color sequences". In 1.61 the mode is only consulted to choose which transformer applies when a mode has been requested (:preview_ttyand friends). When none has,PreviewStatebuilds the preview withpreferred_mode=None, so the transformer's output goes through automatic detection: image if it decodes as one, else text.So a transformer like this one, which renders code through bat:
previews as text, with bat's escape sequences shown literally (
[38;2;173;92;124mlocal[0m…).:preview_ttydisplays it correctly, but that mode then sticks for every file: images fail with "stream did not contain valid UTF-8" and untransformed text loses its highlighting.This change stores the transformer's mode on
PreviewTransformand uses it as the fallback in the three places a transformed preview is built (PreviewState::new,set_auto_mode, and the path used when the selection moves to another file): an explicitly requested mode still wins, and files without a transformer are unaffected.Tested with the transformer above on 1.61:
.luaand.tomlfiles preview with bat's colours, then moving to a.pngshows the image and to an extensionless file shows the syntect-highlighted text, without any mode being picked by hand.🤖 Generated with Claude Code