Repository navigation
Fix(tui): control sequences in a note are not sent to the terminal - #44
Merged
Merged
Conversation
Bytes in a note reached the terminal as they were, so an escape sequence in a note acted on the terminal instead of showing as text. Every frame now passes through one filter at the end of `App.View`, which keeps text, newlines, tabs and colours and drops everything else. zn's own cursor and picture sequences are written apart from the frame and are not affected.
…e keeps its bytes The filter moves to internal/termsafe and now also covers the plain CLI: when stdout or stderr is a terminal, control sequences in what zn prints are dropped. Pipes and files keep every byte. In the TUI, control runes are now handled where note text enters a frame. The editor and both reading views draw each as a one-cell picture such as ␛, so the insert cursor stays on its rune, a note's own colours do not reach the terminal, and a note cannot place a picture's placeholder rune. File names in the sidebar and tabs stay on one row, and bidirectional overrides are dropped from what is written. Very long words are broken before Glamour, whose word wrap is quadratic in a word's length, so a long run in a note no longer stalls the reading view. Opening a note holding bytes that are not valid UTF-8, or CRLF line ends, no longer marks it changed, so quitting no longer rewrites the file. The file stays as it is until a real edit.
A note's own colour still reached the terminal in the Tasks list, the board, the comments panel and thread, the outline panel and Home, since those views take note text without going through the editor or the reading view. Truncating a row's text is where these views take it in, so truncateCells now makes it safe, and that covers every other view using it. Comment threads and the text reader are covered where they wrap, and a task's note name directly. Messages that name a note, in the status line and toasts, and an error on a terminal's stderr, show the name the same way.
Windows refuses an escape in a file name, so the test could not create its file there; the escaped title is now set in the index. The comments and outline checks were also passing on rows from another view, so each view now names the text it must show.
1 task
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.
Note text is data, so it should show as text and never act on the terminal. This covers the TUI and the plain CLI, and fixes two older bugs in the same area.
What changes
A shared filter.
internal/termsafeholds it.Cleankeeps text, newlines, tabs and SGR colours, and drops other CSI sequences, OSC, DCS, APC, PM and SOS strings, single-character escapes, C0 and C1 controls, and bidirectional overrides. An unterminated string stops at the end of its row, so later rows stay.The CLI. When stdout or stderr is a terminal, both go through the filter. That covers every command that prints through them,
zn task watchincluded. Pipes and files keep every byte.The TUI.
App.ViewrunsCleanon every frame, and note text is also handled where it enters a frame.Visibledraws each control rune as a one-cell picture such as␛, in the editor and both reading views. So:truncateCells, and so does every other view that uses it. Messages in the status line and toasts do too, and so do errors on a terminal's stderr.Older bugs.
:qano longer rewrites the file. The bytes stay until a real edit.Cost
About 47 microseconds to clean a 60-row frame, measured once on the first commit.
Visiblereturns early when a note has nothing to change.Testing
go test ./...andgo vet ./...pass.:qaon a note with an invalid byte leaves the file's hash unchanged; a pipe still carries the original bytes.Known limits
emitLine,zn reador--prettykeep a note's own SGR colours on a terminal, because the filter keeps colours for zn's help and pretty output. Other control sequences are still dropped.truncateCells,wrapCommentTextor the editor and reading views, such as a menu's title, only gets the frame filter. It cannot send other control sequences, but it can keep a note's SGR colours.