[erlang-patches] Patch for erl shell (unix/ttsl_drv.c) SIGWINCH handling (R12B-1 31-Dec-2007)
Mon Dec 31 20:27:39 CET 2007
This is an attempt to fix the problem described by Matthew
The erl shell in Unix does not properly handle terminal
resize events which can result in a misplaced cursor and
This patch adds two functions to the file
winch() is registered as the handler for SIGWINCH which is
received on terminal resize events. winch() sets a global
flag "cols_needs_update = TRUE".
update_cols() is run at the start of each function that uses
the COL() or LINE() macros for calculating cursor positions,
namely the del_chars(), write_buf(), and move_cursor()
functions. It checks the "cols_needs_update" flag, and sets
the "cols" global var to the number returned by
If the terminal is resized after update_cols() but before
use of the COL() macro, then we'll have the same incorrect
cursor problems during that function.
We don't run ttysl_get_window_size() from the SIGWINCH
handler because it uses ioctl() which is not listed as a
"safe" function for use in signal handlers in the signal(7)
That said, the solution would be more elegant if we did call
ttysl_get_window_size() from the signal handler, avoiding
the polling done by update_cols(). The ncurses source
includes a simple test/view.c program that does use ioctl()
in its SIGWINCH handler. It states "This uses functions
that are 'unsafe', but it seems to work on SunOS and Linux."
Doing this in erl works for me on Linux, but I have no idea
on which platforms if may fail.
I've only tested this with R12B-1 on Linux 2.6.22.
Patrick Mahoney <>
-------------- next part --------------
A non-text attachment was scrubbed...
Size: 2628 bytes
More information about the erlang-patches