smallish change of plans actually, msh_read_input should return the ascii character input'd so that things like ^C can be abstracted per platform

This commit is contained in:
IoIxD 2026-01-20 17:23:31 -07:00
commit 039d581c45
3 changed files with 11 additions and 9 deletions

View file

@ -17,7 +17,7 @@ MSH_ENTRY_POINT {
msh_print_strings(msh_working_directory(), " %> ", 0);
while ((out = msh_read_input(buf, &sz, 2048)), !out) {
while ((out = msh_read_input(buf, &sz, 2048)), out > 0) {
}
if (*buf != '\0') {

View file

@ -31,26 +31,27 @@ int msh_read_input(char *ptr, SIZE_TYPE *size, SIZE_TYPE n) {
case '\r':
ptr[*size] = '\0';
SYSCALL(write, 1, "\n\r", 2);
return 1;
return -1;
break;
/* backspace */
case '\177':
case 127:
if (*size <= 0) {
return 0;
}
SYSCALL(write, 1, "\33[D \33[D", 7);
*size -= 1;
break;
default:
break;
}
}
}
if (*size >= n) {
return 2;
return -2;
}
return 0;
return ch;
};
void msh_write(char *st, SIZE_TYPE size) { SYSCALL(write, 1, st, size); }

View file

@ -59,10 +59,11 @@ void msh_file_read(msh_file *file, char *ptr, SIZE_TYPE n);
/*
* Read user input into ptr, stopping if it has reached n characters.
* Also responsible for handling backspace.
* Also has to handle backspace since erasing characters is system-dependent.
* RETURNS:
* - 1 if finished reading
* - 2 if it ran out of space.
* -2 = if it ran out of space.
* -1 = if finished reading
* 0 < ascii character
*/
int msh_read_input(char *ptr, SIZE_TYPE *size, SIZE_TYPE n);