capFileReadLine caps one rendered line at fileReadMaxLineBytes. The cut backs off to a UTF-8 rune boundary so a multibyte character is never split mid-sequence, and the marker reports the omitted byte count so the model knows the line was not shown in full.
(s string)
| 134 | // mid-sequence, and the marker reports the omitted byte count so the model |
| 135 | // knows the line was not shown in full. |
| 136 | func capFileReadLine(s string) (string, bool) { |
| 137 | if len(s) <= fileReadMaxLineBytes { |
| 138 | return s, false |
| 139 | } |
| 140 | cut := fileReadMaxLineBytes |
| 141 | for cut > 0 && !utf8.RuneStart(s[cut]) { |
| 142 | cut-- |
| 143 | } |
| 144 | return fmt.Sprintf("%s …[line truncated, %d more bytes omitted]", s[:cut], len(s)-cut), true |
| 145 | } |