Make backspace work

This commit is contained in:
apio 2022-10-30 10:08:52 +01:00
parent e640c6e245
commit 6df5b8a703
3 changed files with 31 additions and 8 deletions

View File

@ -15,7 +15,6 @@ A simple kernel and userspace for the x86_64 platform, written mostly in C++ and
## Notes ## Notes
- The default user is named 'selene' and you can log into it with the password 'moon'. - The default user is named 'selene' and you can log into it with the password 'moon'.
- Beware of backspace, as it looks like it works but it doesn't work except when entering shell commands. So if you make a mistake while entering a username or password, you'll have to try again.
## Setup ## Setup
To build and run Luna, you will need to build a [GCC Cross-Compiler](https://wiki.osdev.org/Why_do_I_need_a_Cross_Compiler%3F) and cross-binutils for `x86_64-luna`. (Yes, Luna is advanced enough that it can use its own [OS-Specific Toolchain](https://wiki.osdev.org/OS_Specific_Toolchain), instead of a bare metal target like `x86_64-elf`. It is the first of my OS projects to be able to do so. The patches for Binutils and GCC are [binutils.patch](tools/binutils.patch) and [gcc.patch](tools/gcc.patch)). To build and run Luna, you will need to build a [GCC Cross-Compiler](https://wiki.osdev.org/Why_do_I_need_a_Cross_Compiler%3F) and cross-binutils for `x86_64-luna`. (Yes, Luna is advanced enough that it can use its own [OS-Specific Toolchain](https://wiki.osdev.org/OS_Specific_Toolchain), instead of a bare metal target like `x86_64-elf`. It is the first of my OS projects to be able to do so. The patches for Binutils and GCC are [binutils.patch](tools/binutils.patch) and [gcc.patch](tools/gcc.patch)).

View File

@ -10,6 +10,7 @@ static char* echoing_fgets(char* buf, size_t size, FILE* stream)
{ {
char* s = buf; char* s = buf;
memset(buf, 0, size); memset(buf, 0, size);
size_t oldsize = size;
while (size) while (size)
{ {
int c = fgetc(stream); int c = fgetc(stream);
@ -23,12 +24,24 @@ static char* echoing_fgets(char* buf, size_t size, FILE* stream)
return NULL; return NULL;
}; };
} }
size--; if ((char)c == '\b')
*buf = (char)c; {
buf++; if (size != oldsize)
{
buf--;
size++;
putchar('\b');
}
}
else
{
size--;
*buf = (char)c;
buf++;
putchar((char)c);
if ((char)c == '\n') return s;
}
*buf = 0; *buf = 0;
putchar((char)c);
if ((char)c == '\n') return s;
} }
return s; return s;
} }

View File

@ -154,8 +154,19 @@ extern "C"
buf++; buf++;
break; break;
} }
buf++; if (*buf == '\b')
size--; {
if (size != original_size)
{
buf--;
size++;
}
}
else
{
buf++;
size--;
}
} }
else else
{ {