summary refs log tree commit diff
path: root/bin/shotty.c
diff options
context:
space:
mode:
authorJune McEnroe <june@causal.agency>2019-07-12 21:14:43 -0400
committerJune McEnroe <june@causal.agency>2019-07-12 21:14:43 -0400
commitde9409e3888ba92b0dca38ac81fe3e4b17e7f466 (patch)
tree621f1f2981b0a8995ec7e89803a52fafd819cd34 /bin/shotty.c
parentAdd DCH to shotty (diff)
downloadsrc-de9409e3888ba92b0dca38ac81fe3e4b17e7f466.tar.gz
src-de9409e3888ba92b0dca38ac81fe3e4b17e7f466.zip
Use -s to infer terminal size
Diffstat (limited to 'bin/shotty.c')
-rw-r--r--bin/shotty.c12
1 files changed, 7 insertions, 5 deletions
diff --git a/bin/shotty.c b/bin/shotty.c
index a882e662..2d1e1f69 100644
--- a/bin/shotty.c
+++ b/bin/shotty.c
@@ -48,7 +48,7 @@ struct Cell {
 };
 
 static struct Style def = { .fg = 7 };
-static uint rows, cols;
+static uint rows = 24, cols = 80;
 
 static uint y, x;
 static bool insert;
@@ -294,15 +294,17 @@ int main(int argc, char *argv[]) {
 	setlocale(LC_CTYPE, "");
 
 	bool bright = false;
+	bool size = false;
 	FILE *file = stdin;
 
 	int opt;
-	while (0 < (opt = getopt(argc, argv, "Bb:f:h:w:"))) {
+	while (0 < (opt = getopt(argc, argv, "Bb:f:h:sw:"))) {
 		switch (opt) {
 			break; case 'B': bright = true;
 			break; case 'b': def.bg = strtoul(optarg, NULL, 0);
 			break; case 'f': def.fg = strtoul(optarg, NULL, 0);
 			break; case 'h': rows = strtoul(optarg, NULL, 0);
+			break; case 's': size = true;
 			break; case 'w': cols = strtoul(optarg, NULL, 0);
 			break; default:  return EX_USAGE;
 		}
@@ -313,12 +315,12 @@ int main(int argc, char *argv[]) {
 		if (!file) err(EX_NOINPUT, "%s", argv[optind]);
 	}
 
-	if (!rows || !cols) {
+	if (size) {
 		struct winsize window;
 		int error = ioctl(STDERR_FILENO, TIOCGWINSZ, &window);
 		if (error) err(EX_IOERR, "ioctl");
-		if (!rows) rows = window.ws_row;
-		if (!cols) cols = window.ws_col;
+		rows = window.ws_row;
+		cols = window.ws_col;
 	}
 
 	cells = calloc(rows * cols, sizeof(*cells));