diff options
| author | Lukasz Kasprzak <lukas@labunix.xyz> | 2026-09-14 22:31:12 +0200 |
|---|---|---|
| committer | Lukasz Kasprzak <lukas@labunix.xyz> | 2026-09-14 22:31:12 +0200 |
| commit | a91b713dcec4d17f76155f0cd6b26903c59b9c19 (patch) | |
| tree | 44b1354e152c71a978738ee6ec47164ccef10b81 /cmd/krino/display.go | |
| parent | c03a72f1d7b598c1fe8fd01bb1f5bbfbd0256313 (diff) | |
| download | krino-a91b713dcec4d17f76155f0cd6b26903c59b9c19.tar.gz krino-a91b713dcec4d17f76155f0cd6b26903c59b9c19.zip | |
plan 10: stderr messages cannot be split by quoted newlines; config paths escaped; krino new refuses control characters; independent terminal oracle
Diffstat (limited to 'cmd/krino/display.go')
| -rw-r--r-- | cmd/krino/display.go | 20 |
1 files changed, 12 insertions, 8 deletions
diff --git a/cmd/krino/display.go b/cmd/krino/display.go index 193d8b8..d468c6b 100644 --- a/cmd/krino/display.go +++ b/cmd/krino/display.go @@ -58,18 +58,22 @@ func controlRune(r rune) bool { return (r >= 0x80 && r <= 0x9f) || unicode.Is(unicode.Bidi_Control, r) || unicode.In(r, unicode.Zl, unicode.Zp) } -// safeWriter writes through display line by line, keeping the newlines: -// every error and warning krino writes to stderr may quote a file name or a -// tool's message, and nothing krino itself writes there is styled (review -// M5). +// safeWriter writes through display: every error and warning krino writes +// to stderr may quote a file name or a tool's message, and nothing krino +// itself writes there is styled (review M5). Each Write is one message line: +// only its final newline is kept, and a newline inside it - from quoted text +// - is escaped, so it cannot start a line that reads as krino's own +// (re-review term F1). A message of several lines is written with one Write +// per line. type safeWriter struct{ w io.Writer } func (s safeWriter) Write(p []byte) (int, error) { - lines := strings.Split(string(p), "\n") - for i, l := range lines { - lines[i] = display(l) + text := string(p) + end := "" + if strings.HasSuffix(text, "\n") { + text, end = text[:len(text)-1], "\n" } - if _, err := io.WriteString(s.w, strings.Join(lines, "\n")); err != nil { + if _, err := io.WriteString(s.w, display(text)+end); err != nil { return 0, err } return len(p), nil |
