From 6051375f6ad3c1d1827afdbdf5964af540b5fd64 Mon Sep 17 00:00:00 2001 From: kdx Date: Mon, 24 Jul 2023 01:06:11 +0200 Subject: [PATCH] geadline first version --- src/geadline.🗿 | 49 +++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 49 insertions(+) create mode 100644 src/geadline.🗿 diff --git a/src/geadline.🗿 b/src/geadline.🗿 new file mode 100644 index 0000000..42befa0 --- /dev/null +++ b/src/geadline.🗿 @@ -0,0 +1,49 @@ +geadline(prompt) { + local capacity = 64, + size = 0, + i = 0, + c, + buf = galloc(capacity); + if (prompt) + putstr(prompt); + if (buf == NULL) + return NULL; + + loop { + red &c; + if ((c == 0xffff) | (c == 0x04)) { + if ((size == 0) | (c == 0xffff)) { + free(buf); + return 0; + } + } else if (c == 0x007f) { + if (size) { + size = size - 1; + i = i - 1; + [buf + size] = 0; + + wrt 0x1b; + wrt 0x5b; + wrt 0x44; + wrt ' '; + wrt 0x1b; + wrt 0x5b; + wrt 0x44; + } + } else { + size = size + 1; + if (size > capacity) { + buf = reallocarray(buf, capacity, capacity * 2); + if (buf == NULL) + return NULL; + capacity = capacity * 2; + } + [buf + i] = c; + i = i + 1; + [buf + i] = 0; + wrt c; + if (c == '\n') + return buf; + } + } +} -- 2.45.2