prompt
This commit is contained in:
parent
f340f7698f
commit
974211dc43
|
@ -45,8 +45,12 @@ struct Command_t
|
|||
extern int shcol;
|
||||
extern int shargc;
|
||||
extern char **shargv;
|
||||
extern char *shprompt;
|
||||
extern size_t shpromptlen;
|
||||
extern Command_t shcmdtable[];
|
||||
|
||||
#define SHPROMPT_MAXLEN (BStdOut->lineLen / 2)
|
||||
|
||||
//----------------------------------------------------------------------------//
|
||||
|
||||
void ShStartShell(void);
|
||||
|
|
|
@ -33,4 +33,3 @@ volatile bool KeIsPanicking = 0;
|
|||
volatile CpuCore_t *KeCurCPU = &_KeCPUTable[0];
|
||||
volatile CpuInfo_t CpuInfo = { 0 };
|
||||
|
||||
|
||||
|
|
|
@ -112,6 +112,7 @@ const uint RegularScanCodes[2 * 256] =
|
|||
ENTRY (0x51, '3', NONE),
|
||||
ENTRY (0x52, '0', NONE),
|
||||
ENTRY (0x53, '.', NONE),
|
||||
ENTRY (0x56, '<', NONE),
|
||||
|
||||
ENTRY (0xE0, 0, INVISIBLE),
|
||||
};
|
||||
|
@ -193,6 +194,8 @@ const uint LeftShiftScanCodes[2 * 256] =
|
|||
ENTRY (0x52, K_INSERT, INVISIBLE),
|
||||
ENTRY (0x53, K_DEL, INVISIBLE),
|
||||
|
||||
ENTRY (0x56, '>', NONE),
|
||||
|
||||
ENTRY (0xE0, 0, INVISIBLE),
|
||||
};
|
||||
|
||||
|
|
|
@ -189,6 +189,7 @@ error_t IoInitVGABuffer(void)
|
|||
|
||||
BEnableAutoScroll(BStdOut);
|
||||
|
||||
#ifndef NDEBUG
|
||||
BStdDbg = &bdbgbufstruct;
|
||||
|
||||
BOpenTermBufEx(&BStdDbg,
|
||||
|
@ -198,6 +199,9 @@ error_t IoInitVGABuffer(void)
|
|||
10, NULL);
|
||||
|
||||
BEnableAutoScroll(BStdDbg);
|
||||
#else
|
||||
BStdDbg = NULL;
|
||||
#endif
|
||||
|
||||
return EOK;
|
||||
}
|
||||
|
|
|
@ -151,6 +151,21 @@ error_t CmdMemMap(int argc, char **argv, char *cmdline)
|
|||
return EOK;
|
||||
}
|
||||
|
||||
error_t CmdPrompt(int argc, char **argv, char *cmdline)
|
||||
{
|
||||
if (cmdline[6] == 0) {
|
||||
shprompt[0] = 0;
|
||||
shpromptlen = 0;
|
||||
}
|
||||
|
||||
else {
|
||||
strnzcpy(shprompt, &cmdline[7], SHPROMPT_MAXLEN);
|
||||
shpromptlen = strlen(shprompt);
|
||||
}
|
||||
|
||||
return EOK;
|
||||
}
|
||||
|
||||
error_t CmdQuit(int argc, char **argv, char *cmdline)
|
||||
{
|
||||
PoShutdown();
|
||||
|
@ -216,10 +231,12 @@ Command_t shcmdtable[] =
|
|||
{ "march", CmdStarWars, "Play the Imperial March" },
|
||||
{ "mmap", CmdMemMap, "Show memory map" },
|
||||
{ "musage", CmdMemUsage, "Show memory statistics" },
|
||||
{ "prompt", CmdPrompt, "Change shell prompt" },
|
||||
{ "quit", CmdQuit, "Alias for 'exit'" },
|
||||
{ "sleep", CmdSleep, "Sleep N ms" },
|
||||
{ "time", CmdTime, "Print time" },
|
||||
{ "test", CmdTest, "Launch a test" },
|
||||
{ "ver", CmdVersion, "Version and legal infos" },
|
||||
{ NULL, NULL, NULL }
|
||||
{ NULL, NULL, NULL },
|
||||
};
|
||||
|
||||
|
|
|
@ -35,6 +35,9 @@ int shargc = 0;
|
|||
char **shargv = 0;
|
||||
int shcol = VGA_COLOR_LIGHT_GREY;
|
||||
|
||||
char *shprompt = "shell> ";
|
||||
size_t shpromptlen = 7;
|
||||
|
||||
static char *argvbuf = 0;
|
||||
|
||||
void ExecuteCommand(char *cmdbuf, Command_t *cmdtable)
|
||||
|
@ -66,7 +69,7 @@ void ExecuteCommand(char *cmdbuf, Command_t *cmdtable)
|
|||
}
|
||||
}
|
||||
|
||||
#define CMDBUFSIZE (BStdOut->lineLen - 9) // strlen("%Cshell> %C" = 9
|
||||
#define CMDBUFSIZE (BStdOut->lineLen - shpromptlen - 2)
|
||||
|
||||
void ShStartShell(void)
|
||||
{
|
||||
|
@ -81,18 +84,23 @@ void ShStartShell(void)
|
|||
|
||||
// History...
|
||||
// We use a basic N-entries command history
|
||||
#define N 10 // must be >1
|
||||
#define N 10 // must be >1
|
||||
char *history = malloc(CMDBUFSIZE * N);
|
||||
int historyIndex = 0;
|
||||
int historyScroll = 0;
|
||||
|
||||
bool insertMode = 0;
|
||||
size_t nLines;
|
||||
|
||||
argvbuf = malloc(ARG_MAX * 2);
|
||||
memzero(argvbuf, ARG_MAX * 2);
|
||||
shargv = (char **)argvbuf;
|
||||
|
||||
KernLog("\n%Cshell> %C", VGA_COLOR_WHITE, shcol);
|
||||
shprompt = malloc(SHPROMPT_MAXLEN);
|
||||
strcpy(shprompt, "shell> ");
|
||||
shpromptlen = 7;
|
||||
|
||||
KernLog("\n%C%s%C", VGA_COLOR_WHITE, shprompt, shcol);
|
||||
BFlushBuf(BStdOut);
|
||||
|
||||
while ((rc = BGetFromBuf(BStdIn, &ch)) == EOK || rc == EENDF) {
|
||||
|
@ -105,7 +113,7 @@ void ShStartShell(void)
|
|||
|
||||
memzero(cmdbuf, CMDBUFSIZE);
|
||||
BFlushBuf(BStdIn);
|
||||
KernLog("%Cshell> %C", VGA_COLOR_WHITE, shcol);
|
||||
KernLog("%C%s%C", VGA_COLOR_WHITE, shprompt, shcol);
|
||||
BFlushBuf(BStdOut);
|
||||
}
|
||||
else break;
|
||||
|
@ -242,7 +250,8 @@ void ShStartShell(void)
|
|||
BStdOut->wp -= BStdOut->lastLF;
|
||||
BStdOut->size -= BStdOut->lastLF;
|
||||
BStdOut->lastLF = 0;
|
||||
bprintf(BStdOut, "%Cshell> %C%s", VGA_COLOR_WHITE, shcol, cmdbuf);
|
||||
bprintf(BStdOut, "%C%s%C%s",
|
||||
VGA_COLOR_WHITE, shprompt, shcol, cmdbuf);
|
||||
|
||||
BUnlockBuf(BStdOut);
|
||||
|
||||
|
@ -286,7 +295,7 @@ void ShStartShell(void)
|
|||
memzero(cmdbuf, CMDBUFSIZE);
|
||||
}
|
||||
|
||||
KernLog("%Cshell> %C", VGA_COLOR_WHITE, shcol);
|
||||
KernLog("%C%s%C", VGA_COLOR_WHITE, shprompt, shcol);
|
||||
BFlushBuf(BStdIn);
|
||||
BFlushBuf(BStdOut);
|
||||
break;
|
||||
|
|
Loading…
Reference in New Issue