2020-10-27 10:09:27 +03:00
|
|
|
#include <stdint.h>
|
|
|
|
#include <stddef.h>
|
|
|
|
#include <lib/readline.h>
|
|
|
|
#include <lib/libc.h>
|
2022-08-27 00:44:47 +03:00
|
|
|
#include <lib/misc.h>
|
2020-10-27 10:09:27 +03:00
|
|
|
#include <lib/term.h>
|
2021-08-25 23:28:32 +03:00
|
|
|
#include <lib/print.h>
|
2022-09-02 03:29:12 +03:00
|
|
|
#if defined (BIOS)
|
2021-03-02 12:23:43 +03:00
|
|
|
# include <lib/real.h>
|
2022-09-02 03:29:12 +03:00
|
|
|
#elif defined (UEFI)
|
2021-03-02 12:23:43 +03:00
|
|
|
# include <efi.h>
|
|
|
|
#endif
|
2022-03-01 19:53:46 +03:00
|
|
|
#include <drivers/serial.h>
|
|
|
|
#include <sys/cpu.h>
|
2020-11-02 11:20:34 +03:00
|
|
|
|
2022-03-02 17:15:22 +03:00
|
|
|
int getchar(void) {
|
|
|
|
for (;;) {
|
|
|
|
int ret = pit_sleep_and_quit_on_keypress(65535);
|
|
|
|
if (ret != 0) {
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-08-25 23:28:32 +03:00
|
|
|
int getchar_internal(uint8_t scancode, uint8_t ascii, uint32_t shift_state) {
|
2021-03-02 12:23:43 +03:00
|
|
|
switch (scancode) {
|
2022-09-02 03:29:12 +03:00
|
|
|
#if defined (BIOS)
|
2020-11-18 02:13:54 +03:00
|
|
|
case 0x44:
|
|
|
|
return GETCHAR_F10;
|
2020-11-02 11:20:34 +03:00
|
|
|
case 0x4b:
|
|
|
|
return GETCHAR_CURSOR_LEFT;
|
|
|
|
case 0x4d:
|
|
|
|
return GETCHAR_CURSOR_RIGHT;
|
|
|
|
case 0x48:
|
|
|
|
return GETCHAR_CURSOR_UP;
|
|
|
|
case 0x50:
|
|
|
|
return GETCHAR_CURSOR_DOWN;
|
|
|
|
case 0x53:
|
|
|
|
return GETCHAR_DELETE;
|
2020-12-19 21:27:10 +03:00
|
|
|
case 0x4f:
|
|
|
|
return GETCHAR_END;
|
|
|
|
case 0x47:
|
|
|
|
return GETCHAR_HOME;
|
|
|
|
case 0x49:
|
|
|
|
return GETCHAR_PGUP;
|
|
|
|
case 0x51:
|
|
|
|
return GETCHAR_PGDOWN;
|
2021-05-19 09:13:15 +03:00
|
|
|
case 0x01:
|
|
|
|
return GETCHAR_ESCAPE;
|
2022-09-02 03:29:12 +03:00
|
|
|
#elif defined (UEFI)
|
2021-03-04 15:48:31 +03:00
|
|
|
case SCAN_F10:
|
|
|
|
return GETCHAR_F10;
|
|
|
|
case SCAN_LEFT:
|
|
|
|
return GETCHAR_CURSOR_LEFT;
|
|
|
|
case SCAN_RIGHT:
|
|
|
|
return GETCHAR_CURSOR_RIGHT;
|
|
|
|
case SCAN_UP:
|
|
|
|
return GETCHAR_CURSOR_UP;
|
|
|
|
case SCAN_DOWN:
|
|
|
|
return GETCHAR_CURSOR_DOWN;
|
|
|
|
case SCAN_DELETE:
|
|
|
|
return GETCHAR_DELETE;
|
|
|
|
case SCAN_END:
|
|
|
|
return GETCHAR_END;
|
|
|
|
case SCAN_HOME:
|
|
|
|
return GETCHAR_HOME;
|
|
|
|
case SCAN_PAGE_UP:
|
|
|
|
return GETCHAR_PGUP;
|
|
|
|
case SCAN_PAGE_DOWN:
|
|
|
|
return GETCHAR_PGDOWN;
|
|
|
|
case SCAN_ESC:
|
2021-05-19 09:13:15 +03:00
|
|
|
return GETCHAR_ESCAPE;
|
2021-03-04 15:48:31 +03:00
|
|
|
#endif
|
2020-11-02 11:20:34 +03:00
|
|
|
}
|
2021-03-02 12:23:43 +03:00
|
|
|
switch (ascii) {
|
2020-12-15 09:40:19 +03:00
|
|
|
case '\r':
|
|
|
|
return '\n';
|
2021-05-12 14:10:39 +03:00
|
|
|
case '\b':
|
|
|
|
return '\b';
|
2020-12-15 09:40:19 +03:00
|
|
|
}
|
2021-08-25 23:28:32 +03:00
|
|
|
|
|
|
|
if (shift_state & (GETCHAR_LCTRL | GETCHAR_RCTRL)) {
|
|
|
|
switch (ascii) {
|
2022-02-05 00:54:11 +03:00
|
|
|
case 'a': return GETCHAR_HOME;
|
|
|
|
case 'e': return GETCHAR_END;
|
2021-08-25 23:28:32 +03:00
|
|
|
case 'p': return GETCHAR_CURSOR_UP;
|
|
|
|
case 'n': return GETCHAR_CURSOR_DOWN;
|
|
|
|
case 'b': return GETCHAR_CURSOR_LEFT;
|
|
|
|
case 'f': return GETCHAR_CURSOR_RIGHT;
|
|
|
|
default: break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-05-12 14:10:39 +03:00
|
|
|
// Guard against non-printable values
|
2021-05-19 09:13:15 +03:00
|
|
|
if (ascii < 0x20 || ascii > 0x7e) {
|
2021-05-12 14:10:39 +03:00
|
|
|
return -1;
|
2021-05-19 09:13:15 +03:00
|
|
|
}
|
2021-03-02 12:23:43 +03:00
|
|
|
return ascii;
|
2020-11-02 11:20:34 +03:00
|
|
|
}
|
|
|
|
|
2022-09-02 03:29:12 +03:00
|
|
|
#if defined (BIOS)
|
2021-03-04 15:48:31 +03:00
|
|
|
int _pit_sleep_and_quit_on_keypress(uint32_t ticks);
|
|
|
|
|
2022-03-01 19:53:46 +03:00
|
|
|
static int input_sequence(void) {
|
|
|
|
int val = 0;
|
2021-08-26 19:22:09 +03:00
|
|
|
|
2022-03-01 19:53:46 +03:00
|
|
|
for (;;) {
|
|
|
|
int ret = -1;
|
|
|
|
size_t retries = 0;
|
2021-08-26 19:22:09 +03:00
|
|
|
|
2022-03-01 19:53:46 +03:00
|
|
|
while (ret == -1 && retries < 1000000) {
|
|
|
|
ret = serial_in();
|
|
|
|
retries++;
|
|
|
|
}
|
|
|
|
if (ret == -1) {
|
|
|
|
return 0;
|
|
|
|
}
|
2021-08-25 23:28:32 +03:00
|
|
|
|
2022-03-01 19:53:46 +03:00
|
|
|
switch (ret) {
|
|
|
|
case 'A':
|
|
|
|
return GETCHAR_CURSOR_UP;
|
|
|
|
case 'B':
|
|
|
|
return GETCHAR_CURSOR_DOWN;
|
|
|
|
case 'C':
|
|
|
|
return GETCHAR_CURSOR_RIGHT;
|
|
|
|
case 'D':
|
|
|
|
return GETCHAR_CURSOR_LEFT;
|
|
|
|
case 'F':
|
|
|
|
return GETCHAR_END;
|
|
|
|
case 'H':
|
|
|
|
return GETCHAR_HOME;
|
|
|
|
}
|
2021-08-25 23:28:32 +03:00
|
|
|
|
2022-03-01 19:53:46 +03:00
|
|
|
if (ret > '9' || ret < '0') {
|
|
|
|
break;
|
2021-08-25 23:28:32 +03:00
|
|
|
}
|
2021-08-26 19:22:09 +03:00
|
|
|
|
2022-03-01 19:53:46 +03:00
|
|
|
val *= 10;
|
|
|
|
val += ret - '0';
|
|
|
|
}
|
|
|
|
|
|
|
|
switch (val) {
|
|
|
|
case 3:
|
|
|
|
return GETCHAR_DELETE;
|
|
|
|
case 5:
|
|
|
|
return GETCHAR_PGUP;
|
|
|
|
case 6:
|
|
|
|
return GETCHAR_PGDOWN;
|
|
|
|
case 21:
|
|
|
|
return GETCHAR_F10;
|
2021-08-25 23:28:32 +03:00
|
|
|
}
|
|
|
|
|
2022-03-01 19:53:46 +03:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
int pit_sleep_and_quit_on_keypress(int seconds) {
|
2022-03-02 17:15:22 +03:00
|
|
|
if (!serial) {
|
|
|
|
return _pit_sleep_and_quit_on_keypress(seconds * 18);
|
|
|
|
}
|
|
|
|
|
2022-03-01 19:53:46 +03:00
|
|
|
for (int i = 0; i < seconds * 18; i++) {
|
|
|
|
int ret = _pit_sleep_and_quit_on_keypress(1);
|
|
|
|
|
|
|
|
if (ret != 0) {
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
ret = serial_in();
|
|
|
|
|
|
|
|
if (ret != -1) {
|
2021-08-26 19:22:09 +03:00
|
|
|
again:
|
2022-03-01 19:53:46 +03:00
|
|
|
switch (ret) {
|
|
|
|
case '\r':
|
|
|
|
return '\n';
|
|
|
|
case 0x1b:
|
|
|
|
delay(10000);
|
|
|
|
ret = serial_in();
|
|
|
|
if (ret == -1) {
|
|
|
|
return GETCHAR_ESCAPE;
|
|
|
|
}
|
|
|
|
if (ret == '[') {
|
|
|
|
return input_sequence();
|
|
|
|
}
|
|
|
|
goto again;
|
2022-03-08 00:09:33 +03:00
|
|
|
case 0x7f:
|
|
|
|
return '\b';
|
2022-03-01 19:53:46 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
}
|
2021-08-26 19:22:09 +03:00
|
|
|
|
2022-03-01 19:53:46 +03:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
#endif
|
2021-08-26 19:22:09 +03:00
|
|
|
|
2022-09-02 03:29:12 +03:00
|
|
|
#if defined (UEFI)
|
2022-03-01 19:53:46 +03:00
|
|
|
static int input_sequence(bool ext,
|
|
|
|
EFI_SIMPLE_TEXT_INPUT_EX_PROTOCOL *exproto,
|
|
|
|
EFI_SIMPLE_TEXT_IN_PROTOCOL *sproto) {
|
2021-08-26 19:22:09 +03:00
|
|
|
EFI_STATUS status;
|
2022-03-01 19:53:46 +03:00
|
|
|
EFI_KEY_DATA kd;
|
2021-08-25 23:28:32 +03:00
|
|
|
|
2022-03-01 19:53:46 +03:00
|
|
|
int val = 0;
|
|
|
|
|
|
|
|
for (;;) {
|
|
|
|
if (ext == false) {
|
|
|
|
status = sproto->ReadKeyStroke(sproto, &kd.Key);
|
|
|
|
} else {
|
|
|
|
status = exproto->ReadKeyStrokeEx(exproto, &kd);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (status != EFI_SUCCESS) {
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
switch (kd.Key.UnicodeChar) {
|
|
|
|
case 'A':
|
|
|
|
return GETCHAR_CURSOR_UP;
|
|
|
|
case 'B':
|
|
|
|
return GETCHAR_CURSOR_DOWN;
|
|
|
|
case 'C':
|
|
|
|
return GETCHAR_CURSOR_RIGHT;
|
|
|
|
case 'D':
|
|
|
|
return GETCHAR_CURSOR_LEFT;
|
|
|
|
case 'F':
|
|
|
|
return GETCHAR_END;
|
|
|
|
case 'H':
|
|
|
|
return GETCHAR_HOME;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (kd.Key.UnicodeChar > '9' || kd.Key.UnicodeChar < '0') {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
val *= 10;
|
|
|
|
val += kd.Key.UnicodeChar - '0';
|
2021-08-25 23:28:32 +03:00
|
|
|
}
|
|
|
|
|
2022-03-01 19:53:46 +03:00
|
|
|
switch (val) {
|
|
|
|
case 3:
|
|
|
|
return GETCHAR_DELETE;
|
|
|
|
case 5:
|
|
|
|
return GETCHAR_PGUP;
|
|
|
|
case 6:
|
|
|
|
return GETCHAR_PGDOWN;
|
|
|
|
case 21:
|
|
|
|
return GETCHAR_F10;
|
2021-08-25 23:28:32 +03:00
|
|
|
}
|
|
|
|
|
2022-03-01 19:53:46 +03:00
|
|
|
return 0;
|
|
|
|
}
|
2021-05-12 14:10:39 +03:00
|
|
|
|
2021-03-04 15:48:31 +03:00
|
|
|
int pit_sleep_and_quit_on_keypress(int seconds) {
|
2021-08-25 23:28:32 +03:00
|
|
|
EFI_KEY_DATA kd;
|
2021-03-04 15:48:31 +03:00
|
|
|
|
|
|
|
UINTN which;
|
|
|
|
|
|
|
|
EFI_EVENT events[2];
|
|
|
|
|
2021-08-26 19:22:09 +03:00
|
|
|
EFI_GUID exproto_guid = EFI_SIMPLE_TEXT_INPUT_EX_PROTOCOL_GUID;
|
|
|
|
EFI_GUID sproto_guid = EFI_SIMPLE_TEXT_INPUT_PROTOCOL_GUID;
|
|
|
|
EFI_SIMPLE_TEXT_INPUT_EX_PROTOCOL *exproto = NULL;
|
|
|
|
EFI_SIMPLE_TEXT_IN_PROTOCOL *sproto = NULL;
|
|
|
|
|
2022-04-22 17:48:17 +03:00
|
|
|
bool use_sproto = false;
|
|
|
|
|
2021-08-26 19:22:09 +03:00
|
|
|
if (gBS->HandleProtocol(gST->ConsoleInHandle, &exproto_guid, (void **)&exproto) != EFI_SUCCESS) {
|
|
|
|
if (gBS->HandleProtocol(gST->ConsoleInHandle, &sproto_guid, (void **)&sproto) != EFI_SUCCESS) {
|
2021-12-11 21:58:00 +03:00
|
|
|
panic(false, "Your input device doesn't have an input protocol!");
|
2021-08-26 19:22:09 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
events[0] = sproto->WaitForKey;
|
2022-04-22 17:48:17 +03:00
|
|
|
|
|
|
|
use_sproto = true;
|
2021-08-26 19:22:09 +03:00
|
|
|
} else {
|
|
|
|
events[0] = exproto->WaitForKeyEx;
|
|
|
|
}
|
2021-03-04 15:48:31 +03:00
|
|
|
|
2021-08-25 23:03:00 +03:00
|
|
|
gBS->CreateEvent(EVT_TIMER, TPL_CALLBACK, NULL, NULL, &events[1]);
|
2021-03-04 15:48:31 +03:00
|
|
|
|
2021-08-25 23:03:00 +03:00
|
|
|
gBS->SetTimer(events[1], TimerRelative, 10000000 * seconds);
|
2021-03-04 15:48:31 +03:00
|
|
|
|
2021-05-12 14:10:39 +03:00
|
|
|
again:
|
2021-08-26 19:22:09 +03:00
|
|
|
memset(&kd, 0, sizeof(EFI_KEY_DATA));
|
|
|
|
|
2021-08-25 23:03:00 +03:00
|
|
|
gBS->WaitForEvent(2, events, &which);
|
2021-03-04 15:48:31 +03:00
|
|
|
|
|
|
|
if (which == 1) {
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2021-08-26 19:22:09 +03:00
|
|
|
EFI_STATUS status;
|
2022-04-22 17:48:17 +03:00
|
|
|
if (use_sproto) {
|
2021-08-26 19:22:09 +03:00
|
|
|
status = sproto->ReadKeyStroke(sproto, &kd.Key);
|
|
|
|
} else {
|
|
|
|
status = exproto->ReadKeyStrokeEx(exproto, &kd);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (status != EFI_SUCCESS) {
|
|
|
|
goto again;
|
|
|
|
}
|
|
|
|
|
|
|
|
if ((kd.KeyState.KeyShiftState & EFI_SHIFT_STATE_VALID) == 0) {
|
|
|
|
kd.KeyState.KeyShiftState = 0;
|
|
|
|
}
|
2021-03-04 15:48:31 +03:00
|
|
|
|
2022-03-08 00:09:33 +03:00
|
|
|
if (kd.Key.ScanCode == 0x08) {
|
|
|
|
return '\b';
|
|
|
|
}
|
|
|
|
|
2022-03-01 19:53:46 +03:00
|
|
|
if (kd.Key.ScanCode == SCAN_ESC) {
|
|
|
|
gBS->CreateEvent(EVT_TIMER, TPL_CALLBACK, NULL, NULL, &events[1]);
|
|
|
|
|
|
|
|
gBS->SetTimer(events[1], TimerRelative, 100000);
|
|
|
|
|
|
|
|
gBS->WaitForEvent(2, events, &which);
|
|
|
|
|
|
|
|
if (which == 1) {
|
|
|
|
return GETCHAR_ESCAPE;
|
|
|
|
}
|
|
|
|
|
2022-04-22 17:48:17 +03:00
|
|
|
if (use_sproto) {
|
2022-03-01 19:53:46 +03:00
|
|
|
status = sproto->ReadKeyStroke(sproto, &kd.Key);
|
|
|
|
} else {
|
|
|
|
status = exproto->ReadKeyStrokeEx(exproto, &kd);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (status != EFI_SUCCESS) {
|
|
|
|
goto again;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (kd.Key.UnicodeChar == '[') {
|
2022-04-22 17:48:17 +03:00
|
|
|
return input_sequence(!use_sproto, exproto, sproto);
|
2022-03-01 19:53:46 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-08-25 23:28:32 +03:00
|
|
|
int ret = getchar_internal(kd.Key.ScanCode, kd.Key.UnicodeChar,
|
|
|
|
kd.KeyState.KeyShiftState);
|
2021-05-12 14:10:39 +03:00
|
|
|
|
2021-08-25 23:28:32 +03:00
|
|
|
if (ret == -1) {
|
2021-05-12 14:10:39 +03:00
|
|
|
goto again;
|
2021-08-25 23:28:32 +03:00
|
|
|
}
|
2021-05-12 14:10:39 +03:00
|
|
|
|
|
|
|
return ret;
|
2021-03-02 12:23:43 +03:00
|
|
|
}
|
|
|
|
#endif
|
2021-10-09 14:32:57 +03:00
|
|
|
|
|
|
|
static void reprint_string(int x, int y, const char *s) {
|
|
|
|
size_t orig_x, orig_y;
|
|
|
|
disable_cursor();
|
|
|
|
get_cursor_pos(&orig_x, &orig_y);
|
2022-02-07 04:10:57 +03:00
|
|
|
set_cursor_pos_helper(x, y);
|
|
|
|
print("%s", s);
|
|
|
|
set_cursor_pos_helper(orig_x, orig_y);
|
2021-10-09 14:32:57 +03:00
|
|
|
enable_cursor();
|
|
|
|
}
|
|
|
|
|
|
|
|
static void cursor_back(void) {
|
|
|
|
size_t x, y;
|
|
|
|
get_cursor_pos(&x, &y);
|
|
|
|
if (x) {
|
|
|
|
x--;
|
|
|
|
} else if (y) {
|
|
|
|
y--;
|
|
|
|
x = term_cols - 1;
|
|
|
|
}
|
2022-02-07 04:10:57 +03:00
|
|
|
set_cursor_pos_helper(x, y);
|
2021-10-09 14:32:57 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
static void cursor_fwd(void) {
|
|
|
|
size_t x, y;
|
|
|
|
get_cursor_pos(&x, &y);
|
|
|
|
if (x < term_cols - 1) {
|
|
|
|
x++;
|
|
|
|
} else if (y < term_rows - 1) {
|
|
|
|
y++;
|
|
|
|
x = 0;
|
|
|
|
}
|
2022-02-07 04:10:57 +03:00
|
|
|
set_cursor_pos_helper(x, y);
|
2021-10-09 14:32:57 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
void readline(const char *orig_str, char *buf, size_t limit) {
|
|
|
|
bool prev_autoflush = term_autoflush;
|
|
|
|
term_autoflush = false;
|
|
|
|
|
|
|
|
size_t orig_str_len = strlen(orig_str);
|
|
|
|
memmove(buf, orig_str, orig_str_len);
|
|
|
|
buf[orig_str_len] = 0;
|
|
|
|
|
|
|
|
size_t orig_x, orig_y;
|
|
|
|
get_cursor_pos(&orig_x, &orig_y);
|
|
|
|
|
2022-02-07 04:10:57 +03:00
|
|
|
print("%s", orig_str);
|
2021-10-09 14:32:57 +03:00
|
|
|
|
|
|
|
for (size_t i = orig_str_len; ; ) {
|
|
|
|
term_double_buffer_flush();
|
|
|
|
int c = getchar();
|
|
|
|
switch (c) {
|
|
|
|
case GETCHAR_CURSOR_LEFT:
|
|
|
|
if (i) {
|
|
|
|
i--;
|
|
|
|
cursor_back();
|
|
|
|
}
|
|
|
|
continue;
|
|
|
|
case GETCHAR_CURSOR_RIGHT:
|
|
|
|
if (i < strlen(buf)) {
|
|
|
|
i++;
|
|
|
|
cursor_fwd();
|
|
|
|
}
|
|
|
|
continue;
|
|
|
|
case '\b':
|
|
|
|
if (i) {
|
|
|
|
i--;
|
|
|
|
cursor_back();
|
|
|
|
case GETCHAR_DELETE:;
|
|
|
|
size_t j;
|
2022-01-29 09:54:49 +03:00
|
|
|
if (buf[i] == 0) {
|
|
|
|
continue;
|
|
|
|
}
|
2021-10-09 14:32:57 +03:00
|
|
|
for (j = i; ; j++) {
|
|
|
|
buf[j] = buf[j+1];
|
|
|
|
if (!buf[j]) {
|
|
|
|
buf[j] = ' ';
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
reprint_string(orig_x, orig_y, buf);
|
|
|
|
buf[j] = 0;
|
|
|
|
}
|
|
|
|
continue;
|
|
|
|
case '\n':
|
2022-02-07 04:10:57 +03:00
|
|
|
print("\n");
|
2021-10-09 14:32:57 +03:00
|
|
|
goto out;
|
2022-01-29 01:51:56 +03:00
|
|
|
case GETCHAR_END:
|
|
|
|
for (size_t j = 0; j < strlen(buf) - i; j++) {
|
|
|
|
cursor_fwd();
|
|
|
|
}
|
|
|
|
i = strlen(buf);
|
|
|
|
continue;
|
|
|
|
case GETCHAR_HOME:
|
|
|
|
for (size_t j = 0; j < i; j++) {
|
|
|
|
cursor_back();
|
|
|
|
}
|
|
|
|
i = 0;
|
|
|
|
continue;
|
2021-10-09 14:32:57 +03:00
|
|
|
default: {
|
2022-01-29 01:51:34 +03:00
|
|
|
if (strlen(buf) < limit - 1 && isprint(c)) {
|
2021-10-09 14:32:57 +03:00
|
|
|
for (size_t j = strlen(buf); ; j--) {
|
|
|
|
buf[j+1] = buf[j];
|
|
|
|
if (j == i)
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
buf[i] = c;
|
|
|
|
i++;
|
|
|
|
cursor_fwd();
|
|
|
|
reprint_string(orig_x, orig_y, buf);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
out:
|
|
|
|
term_double_buffer_flush();
|
|
|
|
term_autoflush = prev_autoflush;
|
|
|
|
}
|