From a432fd32c51d87af53e7f5017bc501e6eb0994af Mon Sep 17 00:00:00 2001 From: kdx Date: Tue, 25 Jul 2023 07:56:22 +0200 Subject: [PATCH 1/2] geadline: use getchar --- src/geadline.🗿 | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/geadline.🗿 b/src/geadline.🗿 index 974650a..9aaa69e 100644 --- a/src/geadline.🗿 +++ b/src/geadline.🗿 @@ -12,7 +12,7 @@ geadline(prompt) { [buf] = 0; loop { - red &c; + c = getchar(); if ((c == 0xffff) | (c == 0x04)) { if ((size == 0) | (c == 0xffff)) { free(buf); @@ -20,8 +20,8 @@ geadline(prompt) { } } else if (c == 0x1b) { // ESC code - red &c; // skip [ - red &c; // value + getchar(); // skip [ + c = getchar(); // value if ((c == 'A') & (size > 0)) { loop { From cc53b0cda5ea064f5a9197265fac9e49aac98e57 Mon Sep 17 00:00:00 2001 From: kdx Date: Tue, 25 Jul 2023 09:21:05 +0200 Subject: [PATCH 2/2] geadline2 --- src/geadline.🗿 | 35 +++++++++++++++++++++++++++++------ 1 file changed, 29 insertions(+), 6 deletions(-) diff --git a/src/geadline.🗿 b/src/geadline.🗿 index 9aaa69e..c691337 100644 --- a/src/geadline.🗿 +++ b/src/geadline.🗿 @@ -1,15 +1,32 @@ -geadline(prompt) { +geadline2(prompt, text) +{ local capacity = 64, size = 0, i = 0, c, a, - buf = galloc(capacity); + buf; + if (text) { + size = strlen(text); + i = size; + loop { + if (capacity > size) + break; + capacity = capacity * 2; + } + buf = galloc(capacity); + if (buf == NULL) + return NULL; + strcpy(buf, text); + } else { + buf = galloc(capacity); + if (buf == NULL) + return NULL; + [buf] = 0; + } if (prompt) putstr(prompt); - if (buf == NULL) - return NULL; - [buf] = 0; + putstr(buf); loop { c = getchar(); @@ -104,7 +121,13 @@ geadline(prompt) { } } -esccode(c) { +geadline(prompt) +{ + geadline2(prompt, NULL); +} + +esccode(c) +{ wrt 0x1b; wrt '['; wrt c;