1 /* vi: set sw=4 ts=4: */
3 * Replacement for "stty size", which is awkward for shell script use.
4 * - Allows to request width, height, or both, in any order.
5 * - Does not complain on error, but returns width 80, height 24.
6 * - Size: less than 200 bytes
8 * Copyright (C) 2007 by Denys Vlasenko <vda.linux@googlemail.com>
10 * Licensed under GPLv2, see file LICENSE in this source tree.
12 //config:config TTYSIZE
13 //config: bool "ttysize"
16 //config: A replacement for "stty size". Unlike stty, can report only width,
17 //config: only height, or both, in any order. It also does not complain on
18 //config: error, but returns default 80x24.
19 //config: Usage in shell scripts: width=`ttysize w`.
21 //usage:#define ttysize_trivial_usage
23 //usage:#define ttysize_full_usage "\n\n"
24 //usage: "Print dimension(s) of stdin's terminal, on error return 80x25"
28 int ttysize_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
29 int ttysize_main(int argc UNUSED_PARAM, char **argv)
36 if (!ioctl(0, TIOCGWINSZ, &wsz)) {
42 printf("%u %u", w, h);
44 const char *fmt, *arg;
46 fmt = "%u %u" + 3; /* "%u" */
47 while ((arg = *++argv) != NULL) {
53 fmt = "%u %u" + 2; /* " %u" */