Skip to content

Use a preview transformer's mode when no preview mode is requested - #1225

Merged
Canop merged 1 commit into
Canop:mainfrom
matthewhadley:transformer-mode
Oct 10, 2026
Merged

Canop merged 1 commit into
Canop:mainfrom
matthewhadley:transformer-mode

Conversation

@matthewhadley

Copy link
Copy Markdown
Contributor

The docs describe a transformer's mode as how its output is displayed, including tty "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_tty and friends). When none has, PreviewState builds the preview with preferred_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:

{
    input_extensions: [ "lua", "toml" ]
    output_extension: txt
    mode: tty
    command: [ "sh", "-c", "bat --color=always \"$1\" > \"$2\"", "_", "{input-path}", "{output-path}" ]
}

previews as text, with bat's escape sequences shown literally ([38;2;173;92;124mlocal[0m…). :preview_tty displays 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 PreviewTransform and 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: .lua and .toml files preview with bat's colours, then moving to a .png shows the image and to an extensionless file shows the syntect-highlighted text, without any mode being picked by hand.

🤖 Generated with Claude Code

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>
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.

3 participants