about summary refs log tree commit diff homepage
diff options
context:
space:
mode:
-rw-r--r--client.c59
1 files changed, 30 insertions, 29 deletions
diff --git a/client.c b/client.c
index ff1a12c..9fd4cc7 100644
--- a/client.c
+++ b/client.c
@@ -30,7 +30,6 @@
 #include <sysexits.h>
 #include <unistd.h>
 #include <wchar.h>
-#include <wctype.h>
 
 #include "torus.h"
 
@@ -197,6 +196,7 @@ static struct {
 	enum {
 		MODE_NORMAL,
 		MODE_INSERT,
+		MODE_REPLACE,
 	} mode;
 	uint8_t color;
 	uint8_t shift;
@@ -252,23 +252,22 @@ static uint8_t inputCell(wchar_t ch) {
 	return 0;
 }
 
-static void inputNormal(bool keyCode, wchar_t ch) {
-	if (keyCode) {
-		switch (ch) {
-			break; case KEY_LEFT:  clientMove(-1,  0);
-			break; case KEY_RIGHT: clientMove( 1,  0);
-			break; case KEY_UP:    clientMove( 0, -1);
-			break; case KEY_DOWN:  clientMove( 0,  1);
-
-			break; case KEY_F(1): input.shift = 0x00;
-			break; case KEY_F(2): input.shift = 0xC0;
-			break; case KEY_F(3): input.shift = 0xA0;
-			break; case KEY_F(4): input.shift = 0x70;
-			break; case KEY_F(5): input.shift = 0x40;
-		}
-		return;
+static void inputKeyCode(wchar_t ch) {
+	switch (ch) {
+		break; case KEY_LEFT:  clientMove(-1,  0);
+		break; case KEY_RIGHT: clientMove( 1,  0);
+		break; case KEY_UP:    clientMove( 0, -1);
+		break; case KEY_DOWN:  clientMove( 0,  1);
+
+		break; case KEY_F(1): input.shift = 0x00;
+		break; case KEY_F(2): input.shift = 0xC0;
+		break; case KEY_F(3): input.shift = 0xA0;
+		break; case KEY_F(4): input.shift = 0x70;
+		break; case KEY_F(5): input.shift = 0x40;
 	}
+}
 
+static void inputNormal(wchar_t ch) {
 	switch (ch) {
 		break; case ESC: input.mode = MODE_NORMAL; input.shift = 0;
 		break; case 'q': endwin(); exit(EX_OK);
@@ -328,14 +327,11 @@ static void inputNormal(bool keyCode, 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;
 	}
 }
 
-static void inputInsert(bool keyCode, wchar_t ch) {
-	if (keyCode) {
-		inputNormal(keyCode, ch);
-		return;
-	}
+static void inputInsert(wchar_t ch) {
 	switch (ch) {
 		break; case ESC: {
 			input.mode = MODE_NORMAL;
@@ -352,11 +348,6 @@ static void inputInsert(bool keyCode, wchar_t ch) {
 			insert.len = 0;
 		}
 		break; default: {
-			if (iswcntrl(ch)) {
-				inputNormal(false, ch);
-				break;
-			}
-
 			uint8_t cell = inputCell(ch);
 			if (!cell) break;
 			clientPut(input.color, cell);
@@ -366,12 +357,22 @@ static void inputInsert(bool keyCode, wchar_t ch) {
 	}
 }
 
+static void inputReplace(wchar_t ch) {
+	uint8_t cell = inputCell(ch);
+	if (ch != ESC && cell) clientPut(tile.colors[cellY][cellX], cell);
+	input.mode = MODE_NORMAL;
+}
+
 static void readInput(void) {
 	wint_t ch;
-	bool keyCode = (KEY_CODE_YES == get_wch(&ch));
+	if (KEY_CODE_YES == get_wch(&ch)) {
+		inputKeyCode(ch);
+		return;
+	}
 	switch (input.mode) {
-		break; case MODE_NORMAL: inputNormal(keyCode, ch);
-		break; case MODE_INSERT: inputInsert(keyCode, ch);
+		break; case MODE_NORMAL:  inputNormal(ch);
+		break; case MODE_INSERT:  inputInsert(ch);
+		break; case MODE_REPLACE: inputReplace(ch);
 	}
 }
 
ill update the status line while the edit buffer still has input "pending", showing an indicator. 2022-02-20Show indicator in status when window has pending inputJune McEnroe 2022-02-20Use separate edit buffers for each IDJune McEnroe 2022-02-20Make sure new cap is actually larger than new lengthJune McEnroe 2022-02-20Remove unused mbs.len field from struct EditJune McEnroe 2022-02-19Remove unneeded includes in ui.cJune McEnroe 2022-02-19Reimplement tab completeJune McEnroe 2022-02-19Handle errors from editFn, etc.June McEnroe 2022-02-19Reimplement text macrosJune McEnroe 2022-02-19Factor out input handling to input.cJune McEnroe 2022-02-19Factor out window management to window.cJune McEnroe 2022-02-19Enable -Wmissing-prototypesJune McEnroe In other words, warn when a function is missing static. I don't see why this isn't in -Wextra. 2022-02-19Fix edit.[ch] license notice additional permissionsJune McEnroe 2022-02-19Run line editing testsJune McEnroe I know, it feels wrong. 2022-02-18Implement new line editing "library"June McEnroe Losing tab complete and text macros, for now. This new implementation works on an instance of a struct and does not interact with the rest of catgirl, making it possible to copy into another project. Unlike existing line editing libraries, this one is entirely abstract and can be rendered externally. My goal with this library is to be able to implement vi mode. Since it operates on struct instances rather than globals, it might also be possible to give catgirl separate line editing buffers for each window, which would be a nice UX improvement. 2022-02-18Simplify cursor positioning in inputJune McEnroe Do some extra work by adding the portion before the cursor to the input window twice, but simplify the interaction with the split point. This fixes the awkward behaviour when moving the cursor across colour codes where the code would be partially interpreted up to the cursor. 2022-02-18Fix M-f orderingJune McEnroe 2022-02-12Move sandman build to scripts/MakefileJune McEnroe 2022-02-12Use compat_readpassphrase.c on LinuxJune McEnroe 2022-02-12Copy RPP defines from oconfigureJune McEnroe