Merge pull request 'geadline first version' (#2) from kdx/IronGOLEM:master into master
Reviewed-on: #2
This commit is contained in:
commit
3443ed76e8
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