diff options
| author | user <user@clank> | 2026-08-26 16:11:42 +0200 |
|---|---|---|
| committer | user <user@clank> | 2026-08-26 16:11:42 +0200 |
| commit | 087b2bd1d31dac24f8b0ffe79c33f4ebf1f60bd3 (patch) | |
| tree | 282ce9a0e243333bb769bae231426cb4f9cf3a86 /src/app.c | |
| parent | compact: shared borders instead of gaps (D23) (diff) | |
| download | slosh-087b2bd1d31dac24f8b0ffe79c33f4ebf1f60bd3.tar.gz slosh-087b2bd1d31dac24f8b0ffe79c33f4ebf1f60bd3.tar.xz slosh-087b2bd1d31dac24f8b0ffe79c33f4ebf1f60bd3.zip | |
macos: the kernel still knows, it just spells /proc differently
Portability fixes contributed by our macOS developer, applied with one
hardening tweak (below).
Darwin has no /proc, so everything that read one gets the native answer:
live_cwd via proc_pidinfo(PROC_PIDVNODEPATHINFO), the foreground command
via sysctl(KERN_PROCARGS2) parsed back into the NUL-separated shape
/proc/<pid>/cmdline gives, and SLOSH_BIN via _NSGetExecutablePath plus
realpath. The pty gets its winsize set on the slave after opening it,
because Darwin attaches no line discipline to the master until then and
the earlier TIOCSWINSZ was silently dropped -- a pane born 0x0. The
shader repl binds tab in libedit's own words, since macOS ships Python's
readline as a libedit wrapper that accepts GNU syntax in silence.
Two finds are cross-platform bugs: a toast wider than the screen minus
the gap computed a negative x that uint16_t made ~65533, drawing the
longest messages -- the ones most worth reading -- off screen; now the
middle is elided (a path's tail is the half you needed) and x clamps.
And a pane label was 128 bytes, which a Homebrew interpreter's full path
exceeds before its arguments even start; dump-layout wrote the
truncation down and a restore ran it, so it is 1024 now.
Saving a layout learned cwd_as_named: the kernel answers with the
physical path, and on macOS /tmp is a symlink to /private/tmp, so a
layout that said cwd="/tmp" stopped round-tripping through a save.
If realpath(named) is where the pane still is, the named spelling wins.
Tests follow: realpath'd tmpdirs, the scroll test reads the shell's
first prompt instead of spelling out bash 5.3, and wrapped pane text is
joined before matching a long path.
One tweak on top of the contribution: the elision needs five columns
for a head, the dots and a tail -- below that `avail - 3` goes
negative, and negative as size_t is a pointer into the weeds; a
terminal that narrow gets a plain clip.
Diffstat (limited to 'src/app.c')
| -rw-r--r-- | src/app.c | 26 |
1 files changed, 24 insertions, 2 deletions
@@ -605,10 +605,32 @@ void draw_toasts(app_t *a, screen_t *s) { char line[160]; snprintf(line, sizeof line, " %s ", text); uint16_t w = (uint16_t)strlen(line); - if (w >= s->cols) w = (uint16_t)(s->cols - 1); + /* Too wide: elide the middle rather than the end. Almost every toast that + * overflows is about a path, and a path's last component is the part you + * needed -- clipping the tail told you "cannot open /var/folders/5q/g_q5" + * and made you go and look for the rest. */ + uint16_t avail = (uint16_t)(s->cols > 1 ? s->cols - 1 : 1); + if (w > avail && avail >= 5) { /* room for a head, the dots and a tail */ + size_t head = (size_t)(avail - 3) / 2, tail = (size_t)avail - 3 - head; + char elided[160]; + snprintf(elided, sizeof elided, "%.*s...%s", (int)head, line, + line + strlen(line) - tail); + memcpy(line, elided, sizeof line); + w = avail; + } else if (w > avail) { + /* A terminal too narrow for the dots gets a plain clip: `avail - 3` + * below five goes negative, and negative as size_t is a pointer into + * the weeds. */ + w = avail; + } uint16_t y = (uint16_t)(bottom - i); if (y >= s->rows) break; - uint16_t x = (uint16_t)(s->cols - w - CFG.gap * CFG.gap_aspect); + /* Clamped, not wrapped: a toast wider than the screen minus the gap used + * to compute a negative x, which as uint16_t became ~65533 and drew the + * whole message off-screen -- the long messages, which are the ones you + * most want to read, were the ones that vanished. */ + int xi = (int)s->cols - (int)w - (int)(CFG.gap * CFG.gap_aspect); + uint16_t x = xi > 0 ? (uint16_t)xi : 0; char clipped[160]; snprintf(clipped, sizeof clipped, "%.*s", (int)w, line); screen_text(s, x, y, clipped, TOAST_FG, TOAST_BG, ATTR_BOLD); |
