Skip to content

Commit a8bf9ae

Browse files
committed
Use 80x24 default size when ghostel-exec target buffer is undisplayed
When BUFFER is not displayed in any window, ghostel-exec previously sized the PTY from (selected-window). That window has nothing to do with where the agent buffer will eventually be shown — programs ending up in a different window had to rely on SIGWINCH to recover, and TUIs that latch initial dimensions at startup rendered against the wrong size. Match eat's behavior: if no window is displaying BUFFER, start at the universal 80x24 default and let SIGWINCH resize on first display. The displayed-buffer path is unchanged.
1 parent abae518 commit a8bf9ae

2 files changed

Lines changed: 38 additions & 10 deletions

File tree

lisp/ghostel.el

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -3687,28 +3687,32 @@ Returns the buffer."
36873687
"Run PROGRAM with ARGS as a ghostel terminal in BUFFER.
36883688
36893689
BUFFER is switched into `ghostel-mode' (if not already) and a new
3690-
terminal is created sized to the window displaying BUFFER, falling
3691-
back to the selected window if BUFFER is not displayed. No shell
3692-
integration is applied — PROGRAM is exec'd directly via
3693-
`ghostel--spawn-pty'. PROGRAM is shell-quoted before it is passed
3694-
to `/bin/sh -c', so shell metacharacters are not interpreted; pass
3695-
extra tokens via ARGS, a list of strings. Returns the process.
3690+
terminal is created sized to the window displaying BUFFER, or
3691+
80x24 if BUFFER is not currently displayed. No shell integration
3692+
is applied — PROGRAM is exec'd directly via `ghostel--spawn-pty'.
3693+
PROGRAM is shell-quoted before it is passed to `/bin/sh -c', so
3694+
shell metacharacters are not interpreted; pass extra tokens via
3695+
ARGS, a list of strings. Returns the process.
36963696
36973697
Signals `user-error' if BUFFER already has a live ghostel process."
36983698
(ghostel--load-module t)
36993699
(when (and (buffer-local-value 'ghostel--process buffer)
37003700
(process-live-p (buffer-local-value 'ghostel--process buffer)))
37013701
(user-error "Buffer %s already has a running ghostel process"
37023702
(buffer-name buffer)))
3703-
(let ((window (or (get-buffer-window buffer t) (selected-window))))
3703+
(let ((window (get-buffer-window buffer t)))
37043704
(with-current-buffer buffer
37053705
(ghostel--prepare-buffer buffer nil)
37063706
;; Use `window-screen-lines' (not `window-body-height') so the
37073707
;; height matches the unit `window-adjust-process-window-size-smallest'
37083708
;; uses — see `ghostel--init-buffer' for why.
3709-
(let* ((height (max 1 (with-selected-window window
3710-
(floor (window-screen-lines)))))
3711-
(width (max 1 (window-max-chars-per-line window)))
3709+
(let* ((height (if window
3710+
(max 1 (with-selected-window window
3711+
(floor (window-screen-lines))))
3712+
24))
3713+
(width (if window
3714+
(max 1 (window-max-chars-per-line window))
3715+
80))
37123716
(remote-p (file-remote-p default-directory)))
37133717
(setq ghostel--term
37143718
(ghostel--new height width ghostel-max-scrollback))

test/ghostel-test.el

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7831,6 +7831,29 @@ while :; do sleep 0.1; done'\n")
78317831
(should (nth 6 captured))))
78327832
(kill-buffer buf))))
78337833

7834+
(ert-deftest ghostel-test-exec-uses-default-size-when-buffer-not-displayed ()
7835+
"`ghostel-exec' on an undisplayed buffer uses the 80x24 default.
7836+
Falling back to (selected-window) sized the PTY from whatever window
7837+
happened to be focused at call time, which rarely matches where the
7838+
buffer eventually shows up."
7839+
(let ((buf (generate-new-buffer "ghostel-exec-test"))
7840+
captured)
7841+
(unwind-protect
7842+
(progn
7843+
;; Sanity: the buffer is not displayed in any window.
7844+
(should-not (get-buffer-window buf t))
7845+
(cl-letf (((symbol-function 'ghostel--load-module) #'ignore)
7846+
((symbol-function 'ghostel--new)
7847+
(lambda (&rest args) (setq captured args) 'fake-term))
7848+
((symbol-function 'ghostel--apply-palette) #'ignore)
7849+
((symbol-function 'ghostel--spawn-pty)
7850+
(lambda (&rest _) 'fake-proc)))
7851+
(ghostel-exec buf "ls" nil)
7852+
;; ghostel--new is called as (height width max-scrollback).
7853+
(should (equal (nth 0 captured) 24))
7854+
(should (equal (nth 1 captured) 80))))
7855+
(kill-buffer buf))))
7856+
78347857
;; -----------------------------------------------------------------------
78357858
;; Test: ghostel-eshell integration
78367859
;; -----------------------------------------------------------------------
@@ -8092,6 +8115,7 @@ COLORTERM, INSIDE_EMACS, …) plus pass-through LANG/LC_*."
80928115
ghostel-test-exec-errors-on-live-process
80938116
ghostel-test-exec-calls-spawn-pty-with-expected-args
80948117
ghostel-test-exec-threads-remote-p-from-tramp-dir
8118+
ghostel-test-exec-uses-default-size-when-buffer-not-displayed
80958119
ghostel-test-environment-precedes-internal-env
80968120
ghostel-test-environment-applies-to-compile
80978121
ghostel-test-environment-honors-dir-locals

0 commit comments

Comments
 (0)