about summary refs log tree commit diff homepage
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--client.c119
1 files changed, 63 insertions, 56 deletions
diff --git a/client.c b/client.c
index ea2eba7..99a4829 100644
--- a/client.c
+++ b/client.c
@@ -137,61 +137,7 @@ static void swapCell(int8_t dx, int8_t dy) {
 	clientPut(aColor, aCell);
 }
 
-static void readInput(void) {
-	int c = getch();
-
-	if (input.mode == MODE_INSERT) {
-		if (c == ESC) {
-			input.mode = MODE_NORMAL;
-			clientMove(-input.dx, -input.dy);
-		} else if (!input.dx && !input.dy) {
-			switch (c) {
-				break; case 'h': insertMode(-1,  0);
-				break; case 'j': insertMode( 0,  1);
-				break; case 'k': insertMode( 0, -1);
-				break; case 'l': insertMode( 1,  0);
-				break; case 'y': insertMode(-1, -1);
-				break; case 'u': insertMode( 1, -1);
-				break; case 'b': insertMode(-1,  1);
-				break; case 'n': insertMode( 1,  1);
-			}
-		} else if (c == '\b' || c == DEL) {
-			clientMove(-input.dx, -input.dy);
-			clientPut(input.color, ' ');
-			input.len--;
-		} else if (c == '\n') {
-			clientMove(input.dy, input.dx);
-			clientMove(-input.dx * input.len, -input.dy * input.len);
-			input.len = 0;
-		} else if (isprint(c)) {
-			clientPut(input.color, c);
-			clientMove(input.dx, input.dy);
-			input.len++;
-		}
-		return;
-	}
-
-	if (input.mode == MODE_REPLACE) {
-		if (isprint(c)) clientPut(attrsColor(inch()), c);
-		input.mode = MODE_NORMAL;
-		return;
-	}
-
-	if (input.mode == MODE_PUT) {
-		if (isprint(c)) clientPut(input.color, c);
-		input.mode = MODE_NORMAL;
-		return;
-	}
-
-	if (input.mode == MODE_DRAW && !input.draw) {
-		if (c == ESC) input.mode = MODE_NORMAL;
-		if (isprint(c)) {
-			input.draw = c;
-			clientPut(input.color, c);
-		}
-		return;
-	}
-
+static void inputNormal(int c) {
 	switch (c) {
 		break; case ESC: input.mode = MODE_NORMAL;
 
@@ -267,8 +213,69 @@ static void readInput(void) {
 		break; case KEY_UP:    clientMove( 0, -1);
 		break; case KEY_RIGHT: clientMove( 1,  0);
 	}
+}
 
-	if (input.mode == MODE_DRAW && input.draw) clientPut(input.color, input.draw);
+static void inputInsert(int c) {
+	if (c == ESC) {
+		input.mode = MODE_NORMAL;
+		clientMove(-input.dx, -input.dy);
+	} else if (!input.dx && !input.dy) {
+		switch (c) {
+			break; case 'h': insertMode(-1,  0);
+			break; case 'j': insertMode( 0,  1);
+			break; case 'k': insertMode( 0, -1);
+			break; case 'l': insertMode( 1,  0);
+			break; case 'y': insertMode(-1, -1);
+			break; case 'u': insertMode( 1, -1);
+			break; case 'b': insertMode(-1,  1);
+			break; case 'n': insertMode( 1,  1);
+		}
+	} else if (c == '\b' || c == DEL) {
+		clientMove(-input.dx, -input.dy);
+		clientPut(input.color, ' ');
+		input.len--;
+	} else if (c == '\n') {
+		clientMove(input.dy, input.dx);
+		clientMove(-input.dx * input.len, -input.dy * input.len);
+		input.len = 0;
+	} else if (isprint(c)) {
+		clientPut(input.color, c);
+		clientMove(input.dx, input.dy);
+		input.len++;
+	}
+}
+
+static void inputReplace(int c) {
+	if (isprint(c)) clientPut(attrsColor(inch()), c);
+	input.mode = MODE_NORMAL;
+}
+
+static void inputPut(int c) {
+	if (isprint(c)) clientPut(input.color, c);
+	input.mode = MODE_NORMAL;
+}
+
+static void inputDraw(int c) {
+	if (input.draw) {
+		inputNormal(c);
+		clientPut(input.color, input.draw);
+	} else if (isprint(c)) {
+		input.draw = c;
+		clientPut(input.color, c);
+	} else if (c == ESC) {
+		input.mode = MODE_NORMAL;
+	}
+}
+
+static void readInput(void) {
+	int c = getch();
+	switch (input.mode) {
+		break; case MODE_NORMAL:  inputNormal(c);
+		break; case MODE_INSERT:  inputInsert(c);
+		break; case MODE_REPLACE: inputReplace(c);
+		break; case MODE_PUT:     inputPut(c);
+		break; case MODE_DRAW:    inputDraw(c);
+	}
 }
 
 static void serverPut(uint8_t x, uint8_t y, uint8_t color, char cell) {
76b42cb326da25a3e2904fe4&follow=1'>Update catgirl to 1.5 (BONUS WEBISODE)June McEnroe 2021-01-15Update litterbox to 1.7June McEnroe 2021-01-15Update pounce to 2.2June McEnroe 2021-01-15Update catgirl to 1.4June McEnroe 2020-12-28Replace cgit-patched with cgit-causal-agencyJune McEnroe 2020-12-18Add notemap portJune McEnroe 2020-12-15Update libretls to 3.3.1June McEnroe 2020-12-15Update catsit to 1.1June McEnroe 2020-12-15Update pounce to 2.1p1June McEnroe 2020-12-15Add imbox portJune McEnroe 2020-11-24Update pounce to 2.1June McEnroe 2020-11-24Update libretls to 3.3.0June McEnroe 2020-11-17Update catgirl to 1.3June McEnroe 2020-11-17Update libretls to 3.2.2June McEnroe 2020-09-29Update libretls to 3.2.1June McEnroe 2020-09-10Update catgirl to 1.2June McEnroe 2020-09-09Add pounce-palaver portJune McEnroe 2020-09-09Update pounce to 2.0June McEnroe 2020-09-09Update litterbox to 1.6June McEnroe 2020-08-23Add scooper portJune McEnroe 2020-08-23Add catsit portJune McEnroe 2020-08-13Update pounce to 1.4p2June McEnroe 2020-08-11Update pounce to 1.4p1June McEnroe 2020-08-10Add litterbox portJune McEnroe 2020-08-10Add missing USES=pkgconfig to pounceJune McEnroe