This commit is contained in:
Julian Barathieu 2020-02-06 15:01:37 +01:00
parent f340f7698f
commit 974211dc43
6 changed files with 44 additions and 8 deletions

View File

@ -45,8 +45,12 @@ struct Command_t
extern int shcol; extern int shcol;
extern int shargc; extern int shargc;
extern char **shargv; extern char **shargv;
extern char *shprompt;
extern size_t shpromptlen;
extern Command_t shcmdtable[]; extern Command_t shcmdtable[];
#define SHPROMPT_MAXLEN (BStdOut->lineLen / 2)
//----------------------------------------------------------------------------// //----------------------------------------------------------------------------//
void ShStartShell(void); void ShStartShell(void);

View File

@ -33,4 +33,3 @@ volatile bool KeIsPanicking = 0;
volatile CpuCore_t *KeCurCPU = &_KeCPUTable[0]; volatile CpuCore_t *KeCurCPU = &_KeCPUTable[0];
volatile CpuInfo_t CpuInfo = { 0 }; volatile CpuInfo_t CpuInfo = { 0 };

View File

@ -112,6 +112,7 @@ const uint RegularScanCodes[2 * 256] =
ENTRY (0x51, '3', NONE), ENTRY (0x51, '3', NONE),
ENTRY (0x52, '0', NONE), ENTRY (0x52, '0', NONE),
ENTRY (0x53, '.', NONE), ENTRY (0x53, '.', NONE),
ENTRY (0x56, '<', NONE),
ENTRY (0xE0, 0, INVISIBLE), ENTRY (0xE0, 0, INVISIBLE),
}; };
@ -193,6 +194,8 @@ const uint LeftShiftScanCodes[2 * 256] =
ENTRY (0x52, K_INSERT, INVISIBLE), ENTRY (0x52, K_INSERT, INVISIBLE),
ENTRY (0x53, K_DEL, INVISIBLE), ENTRY (0x53, K_DEL, INVISIBLE),
ENTRY (0x56, '>', NONE),
ENTRY (0xE0, 0, INVISIBLE), ENTRY (0xE0, 0, INVISIBLE),
}; };

View File

@ -189,6 +189,7 @@ error_t IoInitVGABuffer(void)
BEnableAutoScroll(BStdOut); BEnableAutoScroll(BStdOut);
#ifndef NDEBUG
BStdDbg = &bdbgbufstruct; BStdDbg = &bdbgbufstruct;
BOpenTermBufEx(&BStdDbg, BOpenTermBufEx(&BStdDbg,
@ -198,6 +199,9 @@ error_t IoInitVGABuffer(void)
10, NULL); 10, NULL);
BEnableAutoScroll(BStdDbg); BEnableAutoScroll(BStdDbg);
#else
BStdDbg = NULL;
#endif
return EOK; return EOK;
} }

View File

@ -151,6 +151,21 @@ error_t CmdMemMap(int argc, char **argv, char *cmdline)
return EOK; 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) error_t CmdQuit(int argc, char **argv, char *cmdline)
{ {
PoShutdown(); PoShutdown();
@ -216,10 +231,12 @@ Command_t shcmdtable[] =
{ "march", CmdStarWars, "Play the Imperial March" }, { "march", CmdStarWars, "Play the Imperial March" },
{ "mmap", CmdMemMap, "Show memory map" }, { "mmap", CmdMemMap, "Show memory map" },
{ "musage", CmdMemUsage, "Show memory statistics" }, { "musage", CmdMemUsage, "Show memory statistics" },
{ "prompt", CmdPrompt, "Change shell prompt" },
{ "quit", CmdQuit, "Alias for 'exit'" }, { "quit", CmdQuit, "Alias for 'exit'" },
{ "sleep", CmdSleep, "Sleep N ms" }, { "sleep", CmdSleep, "Sleep N ms" },
{ "time", CmdTime, "Print time" }, { "time", CmdTime, "Print time" },
{ "test", CmdTest, "Launch a test" }, { "test", CmdTest, "Launch a test" },
{ "ver", CmdVersion, "Version and legal infos" }, { "ver", CmdVersion, "Version and legal infos" },
{ NULL, NULL, NULL } { NULL, NULL, NULL },
}; };

View File

@ -35,6 +35,9 @@ int shargc = 0;
char **shargv = 0; char **shargv = 0;
int shcol = VGA_COLOR_LIGHT_GREY; int shcol = VGA_COLOR_LIGHT_GREY;
char *shprompt = "shell> ";
size_t shpromptlen = 7;
static char *argvbuf = 0; static char *argvbuf = 0;
void ExecuteCommand(char *cmdbuf, Command_t *cmdtable) 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) void ShStartShell(void)
{ {
@ -87,12 +90,17 @@ void ShStartShell(void)
int historyScroll = 0; int historyScroll = 0;
bool insertMode = 0; bool insertMode = 0;
size_t nLines;
argvbuf = malloc(ARG_MAX * 2); argvbuf = malloc(ARG_MAX * 2);
memzero(argvbuf, ARG_MAX * 2); memzero(argvbuf, ARG_MAX * 2);
shargv = (char **)argvbuf; 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); BFlushBuf(BStdOut);
while ((rc = BGetFromBuf(BStdIn, &ch)) == EOK || rc == EENDF) { while ((rc = BGetFromBuf(BStdIn, &ch)) == EOK || rc == EENDF) {
@ -105,7 +113,7 @@ void ShStartShell(void)
memzero(cmdbuf, CMDBUFSIZE); memzero(cmdbuf, CMDBUFSIZE);
BFlushBuf(BStdIn); BFlushBuf(BStdIn);
KernLog("%Cshell> %C", VGA_COLOR_WHITE, shcol); KernLog("%C%s%C", VGA_COLOR_WHITE, shprompt, shcol);
BFlushBuf(BStdOut); BFlushBuf(BStdOut);
} }
else break; else break;
@ -242,7 +250,8 @@ void ShStartShell(void)
BStdOut->wp -= BStdOut->lastLF; BStdOut->wp -= BStdOut->lastLF;
BStdOut->size -= BStdOut->lastLF; BStdOut->size -= BStdOut->lastLF;
BStdOut->lastLF = 0; 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); BUnlockBuf(BStdOut);
@ -286,7 +295,7 @@ void ShStartShell(void)
memzero(cmdbuf, CMDBUFSIZE); memzero(cmdbuf, CMDBUFSIZE);
} }
KernLog("%Cshell> %C", VGA_COLOR_WHITE, shcol); KernLog("%C%s%C", VGA_COLOR_WHITE, shprompt, shcol);
BFlushBuf(BStdIn); BFlushBuf(BStdIn);
BFlushBuf(BStdOut); BFlushBuf(BStdOut);
break; break;