geadline2 #5

Merged
starnakin merged 3 commits from kdx/IronGOLEM:master into master 2023-07-25 03:53:39 -04:00
Showing only changes of commit cc53b0cda5 - Show all commits

View File

@ -1,15 +1,32 @@
geadline(prompt) { geadline2(prompt, text)
{
local capacity = 64, local capacity = 64,
size = 0, size = 0,
i = 0, i = 0,
c, c,
a, a,
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); buf = galloc(capacity);
if (prompt)
putstr(prompt);
if (buf == NULL) if (buf == NULL)
return NULL; return NULL;
[buf] = 0; [buf] = 0;
}
if (prompt)
putstr(prompt);
putstr(buf);
loop { loop {
c = getchar(); c = getchar();
@ -104,7 +121,13 @@ geadline(prompt) {
} }
} }
esccode(c) { geadline(prompt)
{
geadline2(prompt, NULL);
}
esccode(c)
{
wrt 0x1b; wrt 0x1b;
wrt '['; wrt '[';
wrt c; wrt c;