Added backspace support for the interactive shell, updated it behavior slightly.

This commit is contained in:
2018-11-13 21:07:13 -06:00
parent 33ece46ac7
commit a51325cd7e
2 changed files with 26 additions and 4 deletions
+2
View File
@@ -86,6 +86,8 @@ void putch(unsigned char c)
if(c == 0x08) if(c == 0x08)
{ {
if(csr_x != 0) csr_x--; if(csr_x != 0) csr_x--;
where = textmemptr + (csr_y * 80 + csr_x);
*where = ' ' | att; /* Character AND attributes: color */
} }
/* Handles a tab by incrementing the cursor's x, but only /* Handles a tab by incrementing the cursor's x, but only
* to a point that will make it divisible by 8 */ * to a point that will make it divisible by 8 */
+22 -2
View File
@@ -15,16 +15,34 @@ void run_shell()
void key_pressed(unsigned char* character) void key_pressed(unsigned char* character)
{ {
int len = strlen(commandbuffer); int len = strlen(commandbuffer);
//Check to see if the backspace has been pressed.
if(character != '\b')
{
//If it has not then simply add the character
//to the commandbuffer, and don't forget the null byte.
commandbuffer[len] = character; commandbuffer[len] = character;
commandbuffer[len + 1] = '\0'; commandbuffer[len + 1] = '\0';
}
else
{
//Otherwise clear the last character from the command
//buffer.
commandbuffer[len - 1] = '\0';
}
putch(character); putch(character);
} }
void execmd() void execmd()
{ {
if(strlen(commandbuffer) == 0)
{
puts("\n#>");
return;
}
if(strcmp(commandbuffer, "version")) if(strcmp(commandbuffer, "version"))
{ {
puts("\nInteractive Shell Version 0.0.0.1\n"); puts("\nInteractive Shell Version 0.0.1.2\n");
} }
else if(strcmp(commandbuffer,"cls")) else if(strcmp(commandbuffer,"cls"))
{ {
@@ -32,7 +50,9 @@ void execmd()
} }
else else
{ {
puts("\nUnknown command\n"); puts("\nUnknown command: ");
puts(commandbuffer);
puts(".\n");
} }
puts("#>"); puts("#>");
commandbuffer[0] = '\0'; commandbuffer[0] = '\0';