From be5c51ab4250f4834bcde38ba48efe82dbf34e9e Mon Sep 17 00:00:00 2001 From: Curtis McEnroe Date: Wed, 22 Aug 2018 16:05:56 -0400 Subject: Implement R --- client.c | 26 +++++++++++++++++++++++--- 1 file 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); } } -- cgit 1.4.1 th: root/etc/Go-Mono.ttf (unfollow)
Commit message (Collapse)Author
2020-09-03Build fbclock with -lzJune McEnroe
I guess this got lost somewhere, long ago...
2020-08-29Add tweets from retweetsJune McEnroe