-
Notifications
You must be signed in to change notification settings - Fork 10
/
autoresize.txt
26 lines (23 loc) · 1.63 KB
/
autoresize.txt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
The process of automatically resizing the window to match the shell-output is
surprisingly complex. Normally the way the shell and terminal orchestrate
themselves to do the output is the following:
The terminal gets resized and does a TIOCSWINSZ ioctl on the pty-fd over which
the two processes communicate, giving the new dimenions. This prompts the
terminal to send the shell a SIGWINCH. The shell handles this by doing a
TIOCGWINSZ ioctl on the pty which returns the data the terminal gave.
zsh now uses this to determine, wether or not e.g. a tabcompletion-suggestion
fits on the terminal and if not, handles it differently. This is a problem for
shellex, because when is starting it's output, there is not enough space, for
the tabcompletion, so even if we immediately resize the terminalwindow, it will
be too late and the shell-output is screwed up.
We rectify this, by injecting a custom ioctl-function into zsh via LD_PRELOAD,
which rewrites all TIOCGWINSZ-requests to have a constant size. This fakes to
the shell that there is more space available, then there actually is. The
actual number of rows is calculated on start of the urxvt and put into a
temporary file. The size is chosen a bit smaller than the screen, such that if
zsh needs even more space for the tabcompletion than fits on the screen, the
zsh handeling to deal with less space gets active. The filename is generated
with mktemp before either zsh or urxvt start. The file gets unlinked by
preload/main.c once a successful read happened.
Shrinking after tab completions mostly works fine: Depending on the
tabcompletion settings, shrinking breaks once one hit the maximum size limit.