geadline2

This commit is contained in:
kdx 2023-07-25 09:21:05 +02:00
parent a432fd32c5
commit 62f368e007

View File

@ -1,14 +1,25 @@
geadline(prompt) { geadline2(prompt, text)
{
local capacity = 64, local capacity = 64,
size = 0, size = 0,
i = 0, i = 0,
c, c,
a, a,
buf = galloc(capacity); buf;
if (prompt) if (text) {
putstr(prompt); loop {
if (capacity > strlen(text))
break;
capacity = capacity * 2;
}
buf = galloc(capacity);
strcpy(buf, text);
} else
buf = galloc(capacity);
if (buf == NULL) if (buf == NULL)
return NULL; return NULL;
if (prompt)
putstr(prompt);
[buf] = 0; [buf] = 0;
loop { loop {
@ -104,7 +115,13 @@ geadline(prompt) {
} }
} }
esccode(c) { geadline(prompt)
{
geadline2(prompt, NULL);
}
esccode(c)
{
wrt 0x1b; wrt 0x1b;
wrt '['; wrt '[';
wrt c; wrt c;