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; + } + } +}