From ef96a6614bb816e8dd1f1bf594b019c73384dda3 Mon Sep 17 00:00:00 2001 From: Fabian Homborg Date: Wed, 14 Apr 2021 17:17:22 +0200 Subject: [PATCH] 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? --- src/event.cpp | 7 +++++++ tests/pexpects/terminal.py | 14 ++++++++++++++ 2 files changed, 21 insertions(+) diff --git a/src/event.cpp b/src/event.cpp index bb96898f6..040a5c3b2 100644 --- a/src/event.cpp +++ b/src/event.cpp @@ -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_type_t::signal); e->desc.param1.signal = sig; e->arguments.push_back(sig2wcs(sig)); diff --git a/tests/pexpects/terminal.py b/tests/pexpects/terminal.py index 37a3592e8..3ffa10f20 100644 --- a/tests/pexpects/terminal.py +++ b/tests/pexpects/terminal.py @@ -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") +