commit 54a8723197d4b841c1b3e50a56aa0610f45caec3
parent 1e5d7837b49f7d665b25614ef262b7a963107771
Author: Anton Konyahin <me@konyahin.xyz>
Date: Mon, 11 Mar 2024 20:07:22 +0300
improved error's handling
Diffstat:
2 files changed, 6 insertions(+), 3 deletions(-)
diff --git a/main.c b/main.c
@@ -28,8 +28,6 @@ restoreTerminal() {
puts("\e[?25h");
if (tcsetattr(STDOUT_FILENO, TCSAFLUSH, &orig_term) < 0)
err(1, "can't restore terminal state");
- // clear screen
- puts("\x1b[2J");
}
void
@@ -122,7 +120,7 @@ getInput(struct screen_size s) {
err(1, "can't read line from stdin");
if (text.lines == 0)
- err(1, "empty input");
+ errx(1, "empty input");
return text;
}
@@ -161,5 +159,8 @@ main(void) {
free(text.data[i]);
free(text.data);
+ // clear screen
+ puts("\x1b[2J");
+
return 0;
}
diff --git a/test.sh b/test.sh
@@ -29,7 +29,9 @@ chars | ./flbng
Some errors check. Should be:
flbng: too much lines for this terminal, should be less than X
flbng: too long line for this terminal, should be shorter than X
+ flbng: empty input
EOF
echo "0\n$(lines)" | ./flbng
echo "*$(chars)" | ./flbng
+printf "" | ./flbng