tb Handle keyboard inside of the shell interactive mode

This commit is contained in:
2025-09-19 19:09:54 +02:00
parent d7153bf0b6
commit 24a90b24e8
2 changed files with 35 additions and 23 deletions

View File

@ -15,6 +15,11 @@
#include <util/util.h>
#include "interp.h"
// keys
#define C(X) ((X)-'@')
#define LINEBUF_MAX 1024
uint64_t PID;
struct {
@ -26,8 +31,6 @@ struct {
bool logcmds;
} CONFIG;
#define LINEBUF_MAX 1024
static Arg ARGS[] = {
ARG("-m", ARG_STRING, &CONFIG.modestr),
ARG("-f", ARG_STRING, &CONFIG.filepath),
@ -99,19 +102,40 @@ void do_mode_interactive(void) {
char linebuf[LINEBUF_MAX];
size_t cursor;
for(;;) {
begin:
uprintf("tb# ");
cursor = 0;
string_memset(linebuf, 0, LINEBUF_MAX);
char c = 0;
while (c != '\n') {
int32_t rd = ipcpipe(PID, IPCPIPE_IN, IPCPIPE_READ, (uint8_t *)&c, 1);
if (rd > 0 && cursor < LINEBUF_MAX) {
linebuf[cursor++] = c;
uprintf("%c", c);
int32_t kbchr = 0;
for (;;) {
int32_t nrd = ipcpipe(PID, IPCPIPE_IN, IPCPIPE_READ, (uint8_t *)&kbchr, sizeof(kbchr));
if (nrd > 0) {
switch (kbchr) {
case C('C'):
case 0xE9:
uprintf("\n");
goto begin;
break;
}
char chr = kbchr & 0xFF;
if (chr == '\n') {
break;
}
if (string_chr_isascii(chr) && chr != 0 && cursor < LINEBUF_MAX) {
linebuf[cursor++] = chr;
uprintf("%c", chr);
}
}
}
linebuf[cursor - 1] = '\0';
if (cursor < LINEBUF_MAX) {
linebuf[cursor] = '\0';
}
uprintf("\n");
InterpResult *res;
if (!interp_runstring(linebuf, &res, CONFIG.logcmds)) {