Commit 846de16
committed
Treat \r as logical-line boundary and swallow stray padding spaces
Follow-up to #32. While that fix preserved \r-based progress updates
end-to-end, two cosmetic glitches remained when running real apt /
pip installs through run_command:
1. apt's progress UI sometimes emits a stray padding space after a
\n, e.g. 'Fetched 52.4 MB in 30s (1,729 kB/s)\n Selecting...'.
The previous logic treated the trailing space as the start of a
fresh logical line, wrote the group prefix, then the space, then
the real content -- producing output like:
PITFT Fetched 52.4 MB in 30s (1,729 kB/s)
PITFT Selecting previously unselected package ...
^ stray space, prefix pushed one column right
2. A bare \r-only line (e.g. apt's 'erase-progress-line' sequence)
was being treated as 'still on the same logical line', so the
next chunk's content would not get a prefix at all -- producing:
PITFT 52.4 MB ...
Selecting previously unselected package ...
^ no PITFT prefix; line just looks orphaned
Reproduced both with a deterministic harness. Same root cause: the
splitter only recognized \n as a logical-line boundary, and the
emitter treated any non-empty body at line-start as 'real content'
(so apt's padding-space pushed the prefix right).
This change:
* Splits chunks on either \n or runs of \r (\r+), so cursor-at-col-0
is the actual boundary, not just newline.
* Strips leading horizontal whitespace (spaces and tabs) immediately
after a boundary, so padding from the source process doesn't push
the prefix right.
* Suppresses the prefix entirely when a logical line is pure padding,
but keeps the terminator (the \r or \n) so the terminal still sees
cursor motion.
* Stays in line-start state when an unterminated tail was pure
padding, so the next chunk's real content still gets a prefix.
Pip-style \r-only progress bars now correctly keep the prefix on
every redraw ('PITFT 10%\rPITFT 25%\rPITFT 50%\r...') rather than
having the prefix appear only on the very first frame.
Verified end-to-end via a deterministic harness that simulates
terminal CR/LF cursor semantics against captured output. Six
scenarios pass: plain multi-line, \r progress, line-split-across-
reads, apt stray-space, apt \r-pad-\r, pip \r-only progress, and
the no-group raw passthrough.
ruff check + ruff format clean.1 parent 02d9c27 commit 846de16
1 file changed
Lines changed: 82 additions & 14 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
190 | 190 | | |
191 | 191 | | |
192 | 192 | | |
| 193 | + | |
| 194 | + | |
| 195 | + | |
| 196 | + | |
| 197 | + | |
| 198 | + | |
| 199 | + | |
193 | 200 | | |
194 | 201 | | |
195 | 202 | | |
196 | 203 | | |
197 | 204 | | |
198 | 205 | | |
199 | 206 | | |
| 207 | + | |
| 208 | + | |
| 209 | + | |
| 210 | + | |
| 211 | + | |
| 212 | + | |
| 213 | + | |
| 214 | + | |
| 215 | + | |
| 216 | + | |
| 217 | + | |
| 218 | + | |
| 219 | + | |
| 220 | + | |
| 221 | + | |
200 | 222 | | |
201 | 223 | | |
202 | 224 | | |
| |||
220 | 242 | | |
221 | 243 | | |
222 | 244 | | |
223 | | - | |
224 | | - | |
225 | | - | |
226 | | - | |
227 | | - | |
228 | | - | |
229 | | - | |
230 | | - | |
231 | | - | |
232 | | - | |
233 | | - | |
234 | | - | |
235 | | - | |
236 | | - | |
| 245 | + | |
| 246 | + | |
| 247 | + | |
| 248 | + | |
| 249 | + | |
| 250 | + | |
| 251 | + | |
| 252 | + | |
| 253 | + | |
| 254 | + | |
| 255 | + | |
| 256 | + | |
| 257 | + | |
| 258 | + | |
| 259 | + | |
| 260 | + | |
| 261 | + | |
| 262 | + | |
| 263 | + | |
| 264 | + | |
| 265 | + | |
| 266 | + | |
| 267 | + | |
237 | 268 | | |
238 | 269 | | |
239 | 270 | | |
| 271 | + | |
| 272 | + | |
| 273 | + | |
| 274 | + | |
| 275 | + | |
| 276 | + | |
| 277 | + | |
| 278 | + | |
| 279 | + | |
| 280 | + | |
| 281 | + | |
| 282 | + | |
| 283 | + | |
| 284 | + | |
| 285 | + | |
| 286 | + | |
| 287 | + | |
| 288 | + | |
| 289 | + | |
| 290 | + | |
| 291 | + | |
| 292 | + | |
| 293 | + | |
| 294 | + | |
| 295 | + | |
| 296 | + | |
| 297 | + | |
| 298 | + | |
| 299 | + | |
| 300 | + | |
| 301 | + | |
| 302 | + | |
| 303 | + | |
| 304 | + | |
| 305 | + | |
| 306 | + | |
| 307 | + | |
240 | 308 | | |
241 | 309 | | |
242 | 310 | | |
| |||
0 commit comments