tb Handle keyboard inside of the shell interactive mode
This commit is contained in:
@ -16,23 +16,11 @@ void tb_runinitscript(void) {
|
|||||||
char *tbargs[] = { "-m", "runfile", "-f", "base:/scripts/init.tb", "-logcmds", "yes" };
|
char *tbargs[] = { "-m", "runfile", "-f", "base:/scripts/init.tb", "-logcmds", "yes" };
|
||||||
int32_t tb = processctl(-1, PCTL_SPAWN, (uint64_t)"base:/bin/tb", (uint64_t)&tbargs, ARRLEN(tbargs));
|
int32_t tb = processctl(-1, PCTL_SPAWN, (uint64_t)"base:/bin/tb", (uint64_t)&tbargs, ARRLEN(tbargs));
|
||||||
|
|
||||||
ipcpipe(IPCPIPE_SELFPID, 10, IPCPIPE_MAKE, NULL, 0);
|
ipcpipe(tb, IPCPIPE_IN, IPCPIPE_ADD_BCAST, NULL, 1);
|
||||||
ipcpipe(IPCPIPE_SELFPID, 10, IPCPIPE_ADD_BCAST, NULL, 1);
|
|
||||||
|
|
||||||
processctl(tb, PCTL_RUN, 0, 0, 0);
|
processctl(tb, PCTL_RUN, 0, 0, 0);
|
||||||
|
|
||||||
while(processctl(tb, PCTL_POLLSTATE, 0, 0, 0) != 4) {
|
while(processctl(tb, PCTL_POLLSTATE, 0, 0, 0) != 4);
|
||||||
int32_t kbchr;
|
|
||||||
int32_t read = ipcpipe(IPCPIPE_SELFPID, 10, IPCPIPE_READ, (uint8_t *)&kbchr, sizeof(kbchr));
|
|
||||||
if (read > 0) {
|
|
||||||
uint8_t c = kbchr & 0xff;
|
|
||||||
if (string_chr_isascii(c)) {
|
|
||||||
if (c != 0) {
|
|
||||||
ipcpipe(tb, IPCPIPE_IN, IPCPIPE_WRITE, &c, 1);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void main(void) {
|
void main(void) {
|
||||||
|
@ -15,6 +15,11 @@
|
|||||||
#include <util/util.h>
|
#include <util/util.h>
|
||||||
#include "interp.h"
|
#include "interp.h"
|
||||||
|
|
||||||
|
// keys
|
||||||
|
#define C(X) ((X)-'@')
|
||||||
|
|
||||||
|
#define LINEBUF_MAX 1024
|
||||||
|
|
||||||
uint64_t PID;
|
uint64_t PID;
|
||||||
|
|
||||||
struct {
|
struct {
|
||||||
@ -26,8 +31,6 @@ struct {
|
|||||||
bool logcmds;
|
bool logcmds;
|
||||||
} CONFIG;
|
} CONFIG;
|
||||||
|
|
||||||
#define LINEBUF_MAX 1024
|
|
||||||
|
|
||||||
static Arg ARGS[] = {
|
static Arg ARGS[] = {
|
||||||
ARG("-m", ARG_STRING, &CONFIG.modestr),
|
ARG("-m", ARG_STRING, &CONFIG.modestr),
|
||||||
ARG("-f", ARG_STRING, &CONFIG.filepath),
|
ARG("-f", ARG_STRING, &CONFIG.filepath),
|
||||||
@ -99,19 +102,40 @@ void do_mode_interactive(void) {
|
|||||||
char linebuf[LINEBUF_MAX];
|
char linebuf[LINEBUF_MAX];
|
||||||
size_t cursor;
|
size_t cursor;
|
||||||
for(;;) {
|
for(;;) {
|
||||||
|
begin:
|
||||||
uprintf("tb# ");
|
uprintf("tb# ");
|
||||||
|
|
||||||
cursor = 0;
|
cursor = 0;
|
||||||
string_memset(linebuf, 0, LINEBUF_MAX);
|
string_memset(linebuf, 0, LINEBUF_MAX);
|
||||||
char c = 0;
|
|
||||||
while (c != '\n') {
|
int32_t kbchr = 0;
|
||||||
int32_t rd = ipcpipe(PID, IPCPIPE_IN, IPCPIPE_READ, (uint8_t *)&c, 1);
|
for (;;) {
|
||||||
if (rd > 0 && cursor < LINEBUF_MAX) {
|
int32_t nrd = ipcpipe(PID, IPCPIPE_IN, IPCPIPE_READ, (uint8_t *)&kbchr, sizeof(kbchr));
|
||||||
linebuf[cursor++] = c;
|
if (nrd > 0) {
|
||||||
uprintf("%c", c);
|
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");
|
uprintf("\n");
|
||||||
InterpResult *res;
|
InterpResult *res;
|
||||||
if (!interp_runstring(linebuf, &res, CONFIG.logcmds)) {
|
if (!interp_runstring(linebuf, &res, CONFIG.logcmds)) {
|
||||||
|
Reference in New Issue
Block a user