summary refs log tree commit diff
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--term.c18
-rw-r--r--term.h2
2 files changed, 10 insertions, 10 deletions
diff --git a/term.c b/term.c
index 5814f33..0554ec2 100644
--- a/term.c
+++ b/term.c
@@ -26,6 +26,10 @@
 
 #include "term.h"
 
+#define MIN(a, b) ((a) < (b) ? (a) : (b))
+#define MAX(a, b) ((a) > (b) ? (a) : (b))
+#define BOX(l, x, u) MIN(MAX((x), (l)), (u))
+
 static void unhandled(const char *format, ...) {
 	if (isatty(STDERR_FILENO)) return;
 	va_list ap;
@@ -54,7 +58,6 @@ static void move(struct Cell *dst, struct Cell *src, uint len) {
 }
 
 static void scrollUp(struct Term *term, uint top, uint n) {
-	if (!n) return;
 	move(
 		cell(term, top, 0),
 		cell(term, top + n, 0),
@@ -68,7 +71,6 @@ static void scrollUp(struct Term *term, uint top, uint n) {
 }
 
 static void scrollDown(struct Term *term, uint top, uint n) {
-	if (!n) return;
 	move(
 		cell(term, top + n, 0),
 		cell(term, top, 0),
@@ -179,18 +181,18 @@ ACTION(ech) {
 }
 
 ACTION(dch) {
-	uint n = MIN(P(0, 1), t->cols - X); if (!n) return;
+	uint n = BOX(1, P(0, 1), t->cols - X);
 	move(C(Y, X), C(Y, X + n), t->cols - X - n);
 	erase(t->style, C(Y, t->cols - n), C(Y, R));
 }
 ACTION(ich) {
-	uint n = MIN(P(0, 1), t->cols - X); if (!n) return;
+	uint n = BOX(1, P(0, 1), t->cols - X);
 	move(C(Y, X + n), C(Y, X), t->cols - X - n);
 	erase(t->style, C(Y, X), C(Y, X + n - 1));
 }
 
-ACTION(dl) { scrollUp(t, Y, MIN(P(0, 1), t->scroll.bot - Y)); }
-ACTION(il) { scrollDown(t, Y, MIN(P(0, 1), t->scroll.bot - Y)); }
+ACTION(dl) { scrollUp(t, Y, BOX(1, P(0, 1), t->scroll.bot - Y)); }
+ACTION(il) { scrollDown(t, Y, BOX(1, P(0, 1), t->scroll.bot - Y)); }
 
 ACTION(nl) {
 	if (Y == t->scroll.bot) {
@@ -207,10 +209,10 @@ ACTION(ri) {
 	}
 }
 ACTION(su) {
-	scrollUp(t, t->scroll.top, MIN(P(0, 1), t->scroll.bot - t->scroll.top));
+	scrollUp(t, t->scroll.top, BOX(1, P(0, 1), t->scroll.bot - t->scroll.top));
 }
 ACTION(sd) {
-	scrollDown(t, t->scroll.top, MIN(P(0, 1), t->scroll.bot - t->scroll.top));
+	scrollDown(t, t->scroll.top, BOX(1, P(0, 1), t->scroll.bot - t->scroll.top));
 }
 ACTION(decstbm) {
 	t->scroll.bot = MIN(P(1, t->rows) - 1, B);
diff --git a/term.h b/term.h
index 2bc4dcb..b4a96af 100644
--- a/term.h
+++ b/term.h
@@ -17,8 +17,6 @@
 #include <stdbool.h>
 #include <wchar.h>
 
-#define MIN(a, b) ((a) < (b) ? (a) : (b))
-
 typedef unsigned uint;
 
 enum {