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
commitbe5c51ab4250f4834bcde38ba48efe82dbf34e9e (patch)
tree054f548c9203895e177458ef85581b8c061a75ec
parentImplement r (diff)
downloadtorus-be5c51ab4250f4834bcde38ba48efe82dbf34e9e.tar.gz
torus-be5c51ab4250f4834bcde38ba48efe82dbf34e9e.zip
Implement R
-rw-r--r--client.c26
1 files changed, 23 insertions, 3 deletions
diff --git a/client.c b/client.c
index c52d3bf..dbe49d6 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);
 	}
 }
 
>2018-09-28Disable visual bell in light terminal profileJune McEnroe 2018-09-28Add psf2pngJune McEnroe 2018-09-27Add HJKL for moving glyphs to psfedJune McEnroe 2018-09-27Move psfed paste to edit modeJune McEnroe 2018-09-27Export PWDJune McEnroe Without it, $(PWD) is unset in GNU make. 2018-09-27Add sans6x8 PSF2 fontJune McEnroe 2018-09-26Add copy paste to psfedJune McEnroe 2018-09-25Add r to psfed for invertJune McEnroe 2018-09-24Add psfed, a PSF2 font editorJune McEnroe 2018-09-21Add scheme -i to swap white and blackJune McEnroe 2018-09-21Map caps lock to escape on Linux consoleJune McEnroe 2018-09-19Fix README mandoc lintsJune McEnroe 2018-09-19Un-NOT trans.alpha values in pngoJune McEnroe 2018-09-18Refactor reads in pngo and clear palette between filesJune McEnroe 2018-09-17Add tRNS support to pngoJune McEnroe 2018-09-11Move gfx man pages to gfx/manJune McEnroe 2018-09-11Move bin man pages to bin/manJune McEnroe 2018-09-11Rewrite gfx.7 and render plaintext READMEJune McEnroe 2018-09-11Remove GAMES from BINSJune McEnroe 2018-09-11Rewrite bin.7 and render to plaintext READMEJune McEnroe 2018-09-11Add "blank" lines to man pagesJune McEnroe 2018-09-10Add mdoc syntax fileJune McEnroe 2018-09-08Fix Nm usage in multi-name man pagesJune McEnroe 2018-09-08Put real dates on man pagesJune McEnroe 2018-09-08Replace gfx README with REAMDE.7June McEnroe 2018-09-08Link gfx man pages in ~/.localJune McEnroe