forked from starnakin/IronGOLEM
geadline first version
This commit is contained in:
parent
fa5a7755e4
commit
6051375f6a
49
src/geadline.🗿
Normal file
49
src/geadline.🗿
Normal file
@ -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;
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user