Update termsize before a sigwinch handler

This could have been one iteration off, e.g.

```fish
function on-winch --on-signal winch
    echo $LINES
end
```

Resize the terminal, it'll print e.g.

24

then run `echo $LINES` interactively, it might have a different answer.

This isn't beautiful, but it works. A better solution might be to make
the termsize vars electric and just always update them on read?
This commit is contained in:
Fabian Homborg 2021-04-14 17:17:22 +02:00
parent 9db846a5a7
commit ef96a6614b
2 changed files with 21 additions and 0 deletions

View file

@ -21,6 +21,7 @@
#include "parser.h"
#include "proc.h"
#include "signal.h"
#include "termsize.h"
#include "wutil.h" // IWYU pragma: keep
class pending_signals_t {
@ -327,6 +328,12 @@ void event_fire_delayed(parser_t &parser) {
if (signals.any()) {
for (uint32_t sig = 0; sig < signals.size(); sig++) {
if (signals.test(sig)) {
// HACK: The only variables we change in response to a *signal*
// are $COLUMNS and $LINES.
// Do that now.
if (sig == SIGWINCH) {
(void)termsize_container_t::shared().updating(parser);
}
auto e = std::make_shared<event_t>(event_type_t::signal);
e->desc.param1.signal = sig;
e->arguments.push_back(sig2wcs(sig));

View file

@ -21,6 +21,19 @@ expect_str("term-support: Terminal has 0 columns, falling back to default width"
expect_str("term-support: Terminal has 0 rows, falling back to default height")
expect_prompt()
# See if $LINES/$COLUMNS change in response to sigwinch, also in a --on-signal function
sendline("function on-winch --on-signal winch; echo $LINES $COLUMNS; end")
expect_prompt()
sp.spawn.setwinsize(40, 50)
expect_str("40 50")
sendline("echo $LINES $COLUMNS")
expect_prompt("40 50")
sp.spawn.setwinsize(20, 70)
expect_str("20 70")
sendline("echo $LINES $COLUMNS")
expect_prompt("20 70")
sendline("stty -a")
expect_prompt()
# Confirm flow control in the shell is disabled - we should ignore the ctrl-s in there.
@ -48,3 +61,4 @@ if platform.system() in ["Linux"]:
expect_str("hellohello", timeout=1, shouldfail=True)
send("\x11") # ctrl-q to resume flow
expect_prompt("hellohello")