1
0
Fork 0
mirror of git://git.code.sf.net/p/cdesktopenv/code synced 2025-03-09 15:50:02 +00:00

Add support for 'stty size' to the libcmd 'stty' builtin (#342)

This commit adds support for 'stty size' to the stty builtin, as
defined in <https://austingroupbugs.net/view.php?id=1053>. The size
mode is used to display the terminal's number of rows and columns.
Note that stty isn't included in the default list of builtin
commands; testing this addition requires adding CMDLIST(stty) to
the table of builtins in src/cmd/ksh93/data/builtins.c.

src/lib/libcmd/stty.c:
- Add support for the size mode to the stty builtin. This mode is
  only used to display the terminal's number of rows and columns,
  so error out if any arguments are given that attempt to set the
  terminal size.
This commit is contained in:
Johnothan King 2021-11-22 16:15:24 -08:00 committed by Martijn Dekker
parent 10ef74e1a2
commit e26937b36a
2 changed files with 29 additions and 3 deletions

5
NEWS
View file

@ -9,6 +9,11 @@ Any uppercase BUG_* names are modernish shell bug IDs.
script is entirely parsed before (or without) being executed, such as
dotted/sourced scripts and scripts compiled by shcomp.
- Added support for the size mode to the stty(1) built-in. This mode is used
to display the terminal's number of rows and columns. Note that the stty
built-in is not compiled in by default. This can be changed by adding
stty to the table of built-ins in src/cmd/ksh93/data/builtins.c.
2021-11-20:
- Listing types with 'typeset -T' no longer displays incomplete versions of

View file

@ -27,7 +27,7 @@
*/
static const char usage[] =
"[-?@(#)$Id: stty (AT&T Research) 2010-04-01 $\n]"
"[-?@(#)$Id: stty (ksh 93u+m) 2021-11-23 $\n]"
"[--catalog?" ERROR_CATALOG "]"
"[+NAME?stty - set or get terminal modes]"
"[+DESCRIPTION?\bstty\b sets certain terminal I/O modes for the device "
@ -110,6 +110,7 @@ static const char usage[] =
#define CASE 10
#define TABS 11
#define WIND 12
#define WINDSZ 13
#undef SS /* who co-opted this namespace? */
@ -157,6 +158,7 @@ static const Tty_t Ttable[] =
{ "rows", WIND, W_SIZE, IG, 0, 24, C("\an\a is the number of lines for display") },
{ "cols", WIND, W_SIZE, IG, 1, 80, C("\an\a is the number of columns for display") },
{ "columns", WIND, W_SIZE, IG, 1, 80, C("Same as \bcols\b") },
{ "size", WINDSZ, W_SIZE, IG, 2, 0, C("Current terminal window size") },
#endif
{ "intr", CHAR, T_CHAR, SS, VINTR, 'C', C("Send an interrupt signal") },
{ "quit", CHAR, T_CHAR, SS, VQUIT, '|', C("Send a quit signal") },
@ -703,6 +705,7 @@ static void set(char *argv[], struct termios *sp)
break;
#ifdef TIOCSWINSZ
case WIND:
case WINDSZ:
{
struct winsize win;
int n;
@ -711,11 +714,28 @@ static void set(char *argv[], struct termios *sp)
error(ERROR_system(1),"cannot set %s",tp->name);
UNREACHABLE();
}
if(!(cp= *argv))
if(!(cp = *argv))
{
sfprintf(sfstdout,"%d\n",tp->mask?win.ws_col:win.ws_row);
switch(tp->mask)
{
case 0: /* stty rows */
sfprintf(sfstdout,"%d\n",win.ws_row);
break;
case 1: /* stty cols/stty columns */
sfprintf(sfstdout,"%d\n",win.ws_col);
break;
case 2: /* stty size */
sfprintf(sfstdout,"%d %d\n",win.ws_row,win.ws_col);
break;
}
break;
}
if(tp->mask==2)
{
/* 'stty size' doesn't set the terminal window size */
error(ERROR_system(1),"%s: invalid argument",argv[0]);
UNREACHABLE();
}
argv++;
n=strtol(cp,&cp,10);
if(*cp)
@ -898,6 +918,7 @@ static int infof(Opt_t* op, Sfio_t* sp, const char* s, Optdisc_t* dp)
sfprintf(sp,"}[+Control Assignments.?If \ac\a is \bundef\b or an empty "
"string then the control assignment is disabled.]{");
listchars(sp,WIND);
listmode(sp,"size");
listchars(sp,CHAR);
sfprintf(sp,"}[+Combination Modes.]{");
listmode(sp,"ek");