Merge pull request 'geadline2' (#5) from kdx/IronGOLEM:master into master

Reviewed-on: starnakin/IronGOLEM#5
This commit is contained in:
starnakin 2023-07-25 07:53:38 +00:00
commit a84415a953

View File

@ -1,18 +1,35 @@
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 {
red &c;
c = getchar();
if ((c == 0xffff) | (c == 0x04)) {
if ((size == 0) | (c == 0xffff)) {
free(buf);
@ -20,8 +37,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 {
@ -104,7 +121,13 @@ geadline(prompt) {
}
}
esccode(c) {
geadline(prompt)
{
geadline2(prompt, NULL);
}
esccode(c)
{
wrt 0x1b;
wrt '[';
wrt c;