aboutsummaryrefslogtreecommitdiffstats
path: root/src/pane.c
diff options
context:
space:
mode:
authorsl0p <sl0p@sl0p.foo>2026-08-13 23:50:24 +0200
committersl0p <sl0p@sl0p.foo>2026-08-13 23:50:24 +0200
commitb514f68d9535e0ee882eecbbac217486f999f538 (patch)
tree1175f74690a61080a8b2d9339335f8b42ef52f05 /src/pane.c
parentsl0ptty: focus follows the mouse, with the guards that make it liveable (diff)
downloadslosh-b514f68d9535e0ee882eecbbac217486f999f538.tar.gz
slosh-b514f68d9535e0ee882eecbbac217486f999f538.tar.xz
slosh-b514f68d9535e0ee882eecbbac217486f999f538.zip
sl0ptty: scrollback — wheel, keyboard, and a clickable indicator
libghostty-vt already keeps the scrollback, so the work was deciding whose wheel it is: - a program tracking the mouse gets the wheel events themselves; - a full-screen program without mouse tracking (vim, less) has no scrollback of ours to show, so the wheel becomes arrow keys, which is what it means to that program; - anything else scrolls our viewport. All three are tested against real programs rather than asserted in principle. C-a PageUp/PageDown/Home/End, and scroll_lines in the config for the wheel. Typing snaps back to the live view, because reading scrollback and then typing into a screen you are not looking at is a trap. New output does not yank the viewport back — it just grows the gap, which the indicator shows. The indicator is compact, right-aligned, budgeted after the split button and before the title (a title is the thing you can most afford to lose), and clicking it returns to the bottom. Three test failures on the way, all mine and all instructive: the top of the scrollback is the shell's first prompt rather than the first line of output; typing without a newline types rather than runs; and two side-by-side panes share a screen row, so asserting on line(y) reads both frames at once. 341 checks green.
Diffstat (limited to 'src/pane.c')
-rw-r--r--src/pane.c48
1 files changed, 48 insertions, 0 deletions
diff --git a/src/pane.c b/src/pane.c
index 38b8f41..6d3bc4b 100644
--- a/src/pane.c
+++ b/src/pane.c
@@ -308,6 +308,9 @@ void pane_write(pane_t *p, const void *buf, size_t len) {
* actually negotiated (kitty flags, cursor-key application mode, alt-esc
* prefix, modifyOtherKeys). This is the reason we decode at all. */
void pane_send_key(pane_t *p, const input_event_t *ev) {
+ /* Typing snaps back to the live view: reading scrollback and then typing
+ * into a screen that is not the one you are looking at is a trap. */
+ if (pane_scrolled(p)) pane_scroll_edge(p, false);
ghostty_key_encoder_setopt_from_terminal(p->kenc, p->term);
ghostty_key_event_set_key(p->kev, (GhosttyKey)ev->key);
ghostty_key_event_set_mods(p->kev, (GhosttyMods)ev->mods);
@@ -370,6 +373,51 @@ void pane_send_paste(pane_t *p, const char *text, size_t len) {
free(buf);
}
+/* ---- scrollback --------------------------------------------------------- */
+
+void pane_scroll(pane_t *p, int delta) {
+ GhosttyTerminalScrollViewport b = {.tag = GHOSTTY_SCROLL_VIEWPORT_DELTA};
+ b.value.delta = delta;
+ ghostty_terminal_scroll_viewport(p->term, b);
+ p->dirty = true;
+}
+
+void pane_scroll_edge(pane_t *p, bool top) {
+ GhosttyTerminalScrollViewport b = {
+ .tag = top ? GHOSTTY_SCROLL_VIEWPORT_TOP : GHOSTTY_SCROLL_VIEWPORT_BOTTOM};
+ ghostty_terminal_scroll_viewport(p->term, b);
+ p->dirty = true;
+}
+
+bool pane_scrolled(const pane_t *p) {
+ bool active = true; /* "the viewport is on the active area", i.e. the bottom */
+ ghostty_terminal_get(p->term, GHOSTTY_TERMINAL_DATA_VIEWPORT_ACTIVE, &active);
+ return !active;
+}
+
+/* Rows hidden above the viewport, and how many exist in total. */
+void pane_scroll_pos(const pane_t *p, uint32_t *above, uint32_t *total) {
+ GhosttyTerminalScrollbar sb = {0};
+ *above = *total = 0;
+ if (ghostty_terminal_get(p->term, GHOSTTY_TERMINAL_DATA_SCROLLBAR, &sb) !=
+ GHOSTTY_SUCCESS)
+ return;
+ *above = (uint32_t)sb.offset;
+ *total = (uint32_t)(sb.total > sb.len ? sb.total - sb.len : 0);
+}
+
+bool pane_alt_screen(const pane_t *p) {
+ GhosttyTerminalScreen screen = GHOSTTY_TERMINAL_SCREEN_PRIMARY;
+ ghostty_terminal_get(p->term, GHOSTTY_TERMINAL_DATA_ACTIVE_SCREEN, &screen);
+ return screen == GHOSTTY_TERMINAL_SCREEN_ALTERNATE;
+}
+
+bool pane_wants_mouse(const pane_t *p) {
+ GhosttyMouseTrackingMode mode = GHOSTTY_MOUSE_TRACKING_NONE;
+ ghostty_terminal_get(p->term, GHOSTTY_TERMINAL_DATA_MOUSE_TRACKING, &mode);
+ return mode != GHOSTTY_MOUSE_TRACKING_NONE;
+}
+
void pane_resize(pane_t *p, uint16_t cols, uint16_t rows) {
if (cols == p->cols && rows == p->rows_n) return;
p->cols = cols;