diff options
| author | dana <dana@dana.is> | 2026-06-05 04:23:29 +0000 |
|---|---|---|
| committer | dana <dana@dana.is> | 2026-06-08 21:11:58 -0500 |
| commit | d7da0f59fc86f1e5d6465ea0b0ca4b93d6a31d54 (patch) | |
| tree | 0bcecbba5e44e1ae524a74302c1abac40b6dc8ec /Src | |
| parent | unposted: NEWS: fix 5.9 changes header (diff) | |
| download | zsh-d7da0f59fc86f1e5d6465ea0b0ca4b93d6a31d54.tar zsh-d7da0f59fc86f1e5d6465ea0b0ca4b93d6a31d54.tar.gz zsh-d7da0f59fc86f1e5d6465ea0b0ca4b93d6a31d54.tar.bz2 zsh-d7da0f59fc86f1e5d6465ea0b0ca4b93d6a31d54.tar.lz zsh-d7da0f59fc86f1e5d6465ea0b0ca4b93d6a31d54.tar.xz zsh-d7da0f59fc86f1e5d6465ea0b0ca4b93d6a31d54.tar.zst zsh-d7da0f59fc86f1e5d6465ea0b0ca4b93d6a31d54.zip | |
54676: preserve COLUMNS + LINES from the environment
Diffstat (limited to 'Src')
| -rw-r--r-- | Src/init.c | 17 | ||||
| -rw-r--r-- | Src/params.c | 5 | ||||
| -rw-r--r-- | Src/utils.c | 4 |
3 files changed, 24 insertions, 2 deletions
diff --git a/Src/init.c b/Src/init.c index eb34b4cab..f36bc332b 100644 --- a/Src/init.c +++ b/Src/init.c @@ -1288,6 +1288,23 @@ setupvals(char *cmd, char *runscript, char *zsh_name) condtab = NULL; wrappers = NULL; + zterm_columns_preserve = zterm_lines_preserve = 0; + + // preserve COLUMNS and LINES from environment when non-interactive + if (!isset(INTERACTIVE)) { + char *e, *p; + zlong v; + + if ((e = zgetenv("COLUMNS")) && (v = zstrtol(e, &p, 10)) > 0 && !*p) { + zterm_columns = v; + zterm_columns_preserve = 1; + } + if ((e = zgetenv("LINES")) && (v = zstrtol(e, &p, 10)) > 0 && !*p) { + zterm_lines = v; + zterm_lines_preserve = 1; + } + } + #ifdef TIOCGWINSZ adjustwinsize(0); #else diff --git a/Src/params.c b/Src/params.c index 7b55d38f2..05efd19c0 100644 --- a/Src/params.c +++ b/Src/params.c @@ -107,6 +107,11 @@ mod_export zlong ppid, /* $PPID */ zsh_subshell; /* $ZSH_SUBSHELL */ +// whether COLUMNS and LINES should be preserved because they were imported from +// the environment into a non-interactive shell +/**/ +mod_export int zterm_columns_preserve, zterm_lines_preserve; + /* $FUNCNEST */ /**/ mod_export diff --git a/Src/utils.c b/Src/utils.c index 801dabd9b..0b4bb9a82 100644 --- a/Src/utils.c +++ b/Src/utils.c @@ -1837,7 +1837,7 @@ adjustlines(int signalled) int oldlines = zterm_lines; #ifdef TIOCGWINSZ - if (signalled || zterm_lines <= 0) + if ((signalled && !zterm_lines_preserve) || zterm_lines <= 0) zterm_lines = shttyinfo.winsize.ws_row; else shttyinfo.winsize.ws_row = zterm_lines; @@ -1862,7 +1862,7 @@ adjustcolumns(int signalled) int oldcolumns = zterm_columns; #ifdef TIOCGWINSZ - if (signalled || zterm_columns <= 0) + if ((signalled && !zterm_columns_preserve) || zterm_columns <= 0) zterm_columns = shttyinfo.winsize.ws_col; else shttyinfo.winsize.ws_col = zterm_columns; |
