about summary refs log tree commit diff homepage
diff options
context:
space:
mode:
authorJune McEnroe <june@causal.agency>2018-08-22 16:05:56 -0400
committerJune McEnroe <june@causal.agency>2018-08-22 16:05:56 -0400
commit3ff8639f865083abe28b9ef178101b42aef234a9 (patch)
treeb1f3c259b096d1a32ad97fa3b20d14b4fe0610b3
parentImplement r (diff)
downloadtorus-3ff8639f865083abe28b9ef178101b42aef234a9.tar.gz
torus-3ff8639f865083abe28b9ef178101b42aef234a9.zip
Implement R
Diffstat (limited to '')
-rw-r--r--client.c26
1 files changed, 23 insertions, 3 deletions
diff --git a/client.c b/client.c
index 9fd4cc7..dec86a9 100644
--- a/client.c
+++ b/client.c
@@ -197,9 +197,11 @@ static struct {
 		MODE_NORMAL,
 		MODE_INSERT,
 		MODE_REPLACE,
+		MODE_DRAW,
 	} mode;
 	uint8_t color;
 	uint8_t shift;
+	uint8_t draw;
 } input = {
 	.color = COLOR_WHITE,
 };
@@ -245,7 +247,7 @@ static void inputSwap(int8_t dx, int8_t dy) {
 }
 
 static uint8_t inputCell(wchar_t ch) {
-	if (ch < 0x7F) return (uint8_t)ch + input.shift;
+	if (ch < 0x80) return (uint8_t)ch + input.shift;
 	for (size_t i = 0; i < ARRAY_LEN(CP437); ++i) {
 		if (ch == CP437[i]) return i;
 	}
@@ -328,6 +330,7 @@ static void inputNormal(wchar_t ch) {
 		break; case 'i': insertMode(1, 0);
 		break; case 'a': clientMove(1, 0); insertMode(1, 0);
 		break; case 'r': input.mode = MODE_REPLACE;
+		break; case 'R': input.mode = MODE_DRAW; input.draw = 0;
 	}
 }
 
@@ -358,11 +361,27 @@ static void inputInsert(wchar_t ch) {
 }
 
 static void inputReplace(wchar_t ch) {
-	uint8_t cell = inputCell(ch);
-	if (ch != ESC && cell) clientPut(tile.colors[cellY][cellX], cell);
+	if (ch != ESC) {
+		uint8_t cell = inputCell(ch);
+		if (!cell) return;
+		clientPut(tile.colors[cellY][cellX], cell);
+	}
 	input.mode = MODE_NORMAL;
 }
 
+static void inputDraw(wchar_t ch) {
+	if (ch == ESC) {
+		input.mode = MODE_NORMAL;
+		return;
+	}
+	if (input.draw) {
+		inputNormal(ch);
+	} else {
+		input.draw = inputCell(ch);
+	}
+	clientPut(input.color, input.draw);
+}
+
 static void readInput(void) {
 	wint_t ch;
 	if (KEY_CODE_YES == get_wch(&ch)) {
@@ -373,6 +392,7 @@ static void readInput(void) {
 		break; case MODE_NORMAL:  inputNormal(ch);
 		break; case MODE_INSERT:  inputInsert(ch);
 		break; case MODE_REPLACE: inputReplace(ch);
+		break; case MODE_DRAW:    inputDraw(ch);
 	}
 }
 
/books.txt?id=a37fc29df3d52e5cabc693292840016171c92217&follow=1'>Add The Bone Shard EmperorJune McEnroe Suffers a little bit from middle book but I really enjoyed it. Read it faster than the first one too, despite its length. 2022-06-25Bump xterm font size to 12June McEnroe 2022-06-10Handle subshells (and functions) inside substitutionsJune McEnroe 2022-06-10Switch to jorts Install scriptJune McEnroe 2022-06-08Indicate if still reading or no resultsJune McEnroe 2022-06-08Add Maiden, Mother, CroneJune McEnroe Mixed bag like most collections of short stories. Some of them are pretty good. The author of the worst written story also has the worst written bio. 2022-06-05FIRST SHOW IN 2.5 YEARS BABEY!!!June McEnroe 2022-06-03Set line number on File linesJune McEnroe 2022-06-03Stop polling stdin after EOFJune McEnroe 2022-06-02Set TABSIZE=4June McEnroe Absolutely indiscriminately. 2022-06-02Do basic match highlightingJune McEnroe 2022-06-02Clean up parsing a littleJune McEnroe 2022-06-02Don't duplicate path stringJune McEnroe 2022-06-02Use stderr instead of /dev/tty, realloc buffer if lines too longJune McEnroe For some reason I haven't been able to figure out, trying to poll /dev/tty returns POLLNVAL (and this was using 100% CPU looping), but using stderr instead works fine. 2022-06-02Add initial working version of qfJune McEnroe 2022-05-29Set prompt for okshJune McEnroe