From 23d68474116e14757db50f17d040cab5ab0027f6 Mon Sep 17 00:00:00 2001 From: Steffen Nurpmeso Date: Wed, 24 Oct 2018 18:20:33 +0200 Subject: [PATCH] =?utf8?q?Tweak=20[34b66785]=20+=20document=20$COLUMNS=20a?= =?utf8?q?nd=20$LINES=20in=20batch=20mode=20(J=C3=B6rg=20Schilling)?= MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit --- main.c | 12 ++++++++---- nail.1 | 38 ++++++++++++++++++++++++-------------- 2 files changed, 32 insertions(+), 18 deletions(-) diff --git a/main.c b/main.c index a069fb08..f00ade53 100644 --- a/main.c +++ b/main.c @@ -477,6 +477,7 @@ a_main_setup_vars(void){ #endif } }else + /* $COLUMNS and $LINES defaults as documented in the manual */ n_scrnheight = n_realscreenheight = 24, n_scrnwidth = 80; NYD2_LEAVE; } @@ -490,6 +491,7 @@ a_main_setscreensize(int is_sighdl){/* TODO globl policy; int wraps; minvals! */ struct ttysize ts; #endif NYD2_ENTER; + assert((n_psonce & n_PSO_INTERACTIVE) || (n_poption & n_PO_BATCH_FLAG)); n_scrnheight = n_realscreenheight = n_scrnwidth = 0; @@ -498,19 +500,21 @@ a_main_setscreensize(int is_sighdl){/* TODO globl policy; int wraps; minvals! */ * only honour it upon first run; abuse *is_sighdl* as an indicator */ if(!is_sighdl){ char const *cp; + bool_t hadl, hadc; - if((cp = ok_vlook(LINES)) != NULL){ + if((hadl = ((cp = ok_vlook(LINES)) != NULL))){ n_idec_ui32_cp(&n_scrnheight, cp, 0, NULL); n_realscreenheight = n_scrnheight; } - if((cp = ok_vlook(COLUMNS)) != NULL) + if((hadc = ((cp = ok_vlook(COLUMNS)) != NULL))) n_idec_ui32_cp(&n_scrnwidth, cp, 0, NULL); if(n_scrnwidth != 0 && n_scrnheight != 0) goto jleave; - /* For batch mode without explicit request, stop now */ - if(!(n_psonce & n_PSO_INTERACTIVE)){ + /* In non-interactive mode, stop now, except for the documented case that + * both are set but not both have been usable */ + if(!(n_psonce & n_PSO_INTERACTIVE) && (!hadl || !hadc)){ n_scrnheight = n_realscreenheight = 24; n_scrnwidth = 80; goto jleave; diff --git a/nail.1 b/nail.1 index c63dfc37..a43e589a 100644 --- a/nail.1 +++ b/nail.1 @@ -770,6 +770,11 @@ and .Va inbox (the latter three to .Pa /dev/null ) . +Also, the values of +.Ev COLUMNS +and +.Ev LINES +are looked up, and acted upon. The following prepares an email message in a batched dry run: .Bd -literal -offset indent $ LC_ALL=C printf 'm bob\en~s ubject\enText\en~.\enx\en' |\e @@ -12691,15 +12696,23 @@ $ COLUMNS=80 \*(uA -R .Bl -tag -width ".It Ev BaNg" .Mx .It Ev COLUMNS -The user's preferred width in column positions for the terminal screen -or window. -Queried and used once on program startup, actively managed for child -processes and the MLE (see +The user's preferred width in column positions for the terminal screen. +Queried and used once on program startup in interactive or batch +.Pf ( Fl \&# ) +mode, actively managed for child processes and the MLE (see .Sx "On terminal control and line editor" ) in interactive mode thereafter. -Ignored in non-interactive mode, which always uses 80 columns, unless in -.Fl \&# -batch mode. +Non-interactive mode always uses, and the fallback default is 80 columns. +If in batch mode +.Ev \&\&COLUMNS +and +.Ev LINES +are both set but not both are usable (empty, not a number, or 0) at +program startup, then the real terminal screen size will be (tried to +be) determined once. +(Normally the +.Xr sh 1 +manages these variables, and unsets them for pipe specifications etc.) . .Mx .It Ev DEAD @@ -12756,13 +12769,10 @@ which includes updating . .Mx .It Ev LINES -The user's preferred number of lines on a page or the vertical screen -or window size in lines. -Queried and used once on program startup, actively managed for child -processes in interactive mode thereafter. -Ignored in non-interactive mode, which always uses 24 lines, unless in -.fl # -batch mode. +The user's preferred number of lines for the terminal screen. +The behaviour is as described for +.Ev COLUMNS , +yet the non-interactive and fallback default is 24 (lines). . .Mx .It Ev LISTER -- 2.11.4.GIT