summaryrefslogtreecommitdiffstats
path: root/usr.bin
diff options
context:
space:
mode:
authortrasz <trasz@FreeBSD.org>2017-05-23 08:07:39 +0000
committertrasz <trasz@FreeBSD.org>2017-05-23 08:07:39 +0000
commit3d8e1008e01b488282cf1c4699654b5b74d84f52 (patch)
tree8cbbf6a0eafa3fd83aed8b806539ddd777a324f9 /usr.bin
parent8df1ab3df949635e62128a83d7991f17902b8b87 (diff)
downloadFreeBSD-src-3d8e1008e01b488282cf1c4699654b5b74d84f52.zip
FreeBSD-src-3d8e1008e01b488282cf1c4699654b5b74d84f52.tar.gz
MFC rr317934:
Add resizewin -z. It makes resizewin not do anything if the terminal size is already set to something other than zero. It's supposed to be called from eg /etc/profile - it's not neccessary to query terminal size when logging in over the network, because the protocol used already takes care of this, but it's neccessary when logging over a serial line.
Diffstat (limited to 'usr.bin')
-rw-r--r--usr.bin/resizewin/resizewin.112
-rw-r--r--usr.bin/resizewin/resizewin.c34
2 files changed, 43 insertions, 3 deletions
diff --git a/usr.bin/resizewin/resizewin.1 b/usr.bin/resizewin/resizewin.1
index b7376c7..ce15ce7 100644
--- a/usr.bin/resizewin/resizewin.1
+++ b/usr.bin/resizewin/resizewin.1
@@ -27,17 +27,27 @@
.\"
.\" $FreeBSD$
.\"
-.Dd July 9, 2016
+.Dd May 8, 2017
.Dt RESIZEWIN 1
.Os
.Sh NAME
.Nm resizewin
.Nd update the kernel window size for the current TTY
+.Sh SYNOPSIS
+.Nm
+.Op Fl z
.Sh DESCRIPTION
Query the terminal emulator window size with the
.Dv TIOCSWINSZ
ioctl and set the window size known by the kernel to the new values.
The terminal is assumed to be VT100/ANSI compatible.
+.Pp
+The following options are available:
+.Bl -tag -width ".Fl z"
+.It Fl z
+Do nothing unless the current kernel terminal size is zero.
+.El
+.Pp
.Nm
is functionally similar to
.Xr resize 1 ,
diff --git a/usr.bin/resizewin/resizewin.c b/usr.bin/resizewin/resizewin.c
index 566577b..20116b6 100644
--- a/usr.bin/resizewin/resizewin.c
+++ b/usr.bin/resizewin/resizewin.c
@@ -47,20 +47,50 @@ static const char query[] =
"\033[999;999H" /* Move cursor */
"\033[6n" /* Get cursor position */
"\0338"; /* Restore cursor position */
+
+static void
+usage(void)
+{
+
+ fprintf(stderr, "usage: resizewin [-z]\n");
+ exit(1);
+}
+
int
-main(__unused int argc, __unused char **argv)
+main(int argc, char **argv)
{
struct termios old, new;
struct winsize w;
- int ret, fd, cnt, error;
+ int ret, fd, ch, cnt, error, zflag;
char data[20];
struct timeval then, now;
error = 0;
+ zflag = 0;
+ while ((ch = getopt(argc, argv, "z")) != -1) {
+ switch (ch) {
+ case 'z':
+ zflag = 1;
+ break;
+ case '?':
+ default:
+ usage();
+ }
+ }
+ argc -= optind;
+ if (argc != 0)
+ usage();
if ((fd = open("/dev/tty", O_RDWR | O_NONBLOCK)) == -1)
exit(1);
+ if (zflag) {
+ if (ioctl(fd, TIOCGWINSZ, &w) == -1)
+ exit(1);
+ if (w.ws_row != 0 && w.ws_col != 0)
+ exit(0);
+ }
+
/* Disable echo */
if (tcgetattr(fd, &old) == -1)
exit(1);
OpenPOWER on IntegriCloud