Changeset View
Changeset View
Standalone View
Standalone View
head/usr.bin/resizewin/resizewin.c
Show First 20 Lines • Show All 41 Lines • ▼ Show 20 Lines | |||||
/* screen doesn't support ESC[18t (return terminal size) so do it the hard way */ | /* screen doesn't support ESC[18t (return terminal size) so do it the hard way */ | ||||
static const char query[] = | static const char query[] = | ||||
"\0337" /* Save cursor position */ | "\0337" /* Save cursor position */ | ||||
"\033[r" /* Scroll whole screen */ | "\033[r" /* Scroll whole screen */ | ||||
"\033[999;999H" /* Move cursor */ | "\033[999;999H" /* Move cursor */ | ||||
"\033[6n" /* Get cursor position */ | "\033[6n" /* Get cursor position */ | ||||
"\0338"; /* Restore cursor position */ | "\0338"; /* Restore cursor position */ | ||||
static void | |||||
usage(void) | |||||
{ | |||||
fprintf(stderr, "usage: resizewin [-z]\n"); | |||||
exit(1); | |||||
} | |||||
int | int | ||||
main(__unused int argc, __unused char **argv) | main(int argc, char **argv) | ||||
{ | { | ||||
struct termios old, new; | struct termios old, new; | ||||
struct winsize w; | struct winsize w; | ||||
int ret, fd, cnt, error; | int ret, fd, ch, cnt, error, zflag; | ||||
char data[20]; | char data[20]; | ||||
struct timeval then, now; | struct timeval then, now; | ||||
error = 0; | 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) | if ((fd = open("/dev/tty", O_RDWR | O_NONBLOCK)) == -1) | ||||
exit(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 */ | /* Disable echo */ | ||||
if (tcgetattr(fd, &old) == -1) | if (tcgetattr(fd, &old) == -1) | ||||
exit(1); | exit(1); | ||||
new = old; | new = old; | ||||
new.c_cflag |= (CLOCAL | CREAD); | new.c_cflag |= (CLOCAL | CREAD); | ||||
new.c_lflag &= ~(ICANON | ECHO | ECHOE | ISIG); | new.c_lflag &= ~(ICANON | ECHO | ECHOE | ISIG); | ||||
▲ Show 20 Lines • Show All 64 Lines • Show Last 20 Lines |