"introduce msh_move_cursor so we can abstrace backspace"
This commit is contained in:
parent
ab3ef8bb8b
commit
0ed0d32b27
3 changed files with 34 additions and 14 deletions
|
|
@ -19,6 +19,15 @@ MSH_ENTRY_POINT {
|
||||||
|
|
||||||
while ((out = msh_read_input(buf, &sz, 2048)), out > 0) {
|
while ((out = msh_read_input(buf, &sz, 2048)), out > 0) {
|
||||||
switch (out) {
|
switch (out) {
|
||||||
|
case 0x7F:
|
||||||
|
if (sz > 0) {
|
||||||
|
msh_move_cursor(1);
|
||||||
|
msh_write(" ", 1);
|
||||||
|
msh_move_cursor(1);
|
||||||
|
buf[sz--] = '\0';
|
||||||
|
}
|
||||||
|
|
||||||
|
break;
|
||||||
/* Ctrl-C */
|
/* Ctrl-C */
|
||||||
case 0x3:
|
case 0x3:
|
||||||
msh_print_string("^C\n\r");
|
msh_print_string("^C\n\r");
|
||||||
|
|
|
||||||
|
|
@ -3,16 +3,14 @@
|
||||||
#include "syscall.h"
|
#include "syscall.h"
|
||||||
|
|
||||||
#include <linux/kd.h>
|
#include <linux/kd.h>
|
||||||
#include <signal.h>
|
|
||||||
#include <sys/file.h>
|
#include <sys/file.h>
|
||||||
#include <sys/ioctl.h>
|
#include <sys/ioctl.h>
|
||||||
#include <sys/select.h>
|
#include <sys/select.h>
|
||||||
|
#include <sys/signal.h>
|
||||||
#include <sys/stat.h>
|
#include <sys/stat.h>
|
||||||
#include <sys/termios.h>
|
#include <sys/termios.h>
|
||||||
#include <sys/wait.h>
|
#include <sys/wait.h>
|
||||||
|
|
||||||
#include <termios.h>
|
|
||||||
|
|
||||||
char msh_path_seperator = '/';
|
char msh_path_seperator = '/';
|
||||||
|
|
||||||
int msh_read_input(char *ptr, SIZE_TYPE *size, SIZE_TYPE n) {
|
int msh_read_input(char *ptr, SIZE_TYPE *size, SIZE_TYPE n) {
|
||||||
|
|
@ -34,13 +32,6 @@ int msh_read_input(char *ptr, SIZE_TYPE *size, SIZE_TYPE n) {
|
||||||
return -1;
|
return -1;
|
||||||
break;
|
break;
|
||||||
/* backspace */
|
/* backspace */
|
||||||
case 127:
|
|
||||||
if (*size <= 0) {
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
SYSCALL(write, 1, "\33[D \33[D", 7);
|
|
||||||
*size -= 1;
|
|
||||||
break;
|
|
||||||
default:
|
default:
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
@ -54,11 +45,27 @@ int msh_read_input(char *ptr, SIZE_TYPE *size, SIZE_TYPE n) {
|
||||||
return ch;
|
return ch;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
void msh_move_cursor(signed int offset) {
|
||||||
|
int i;
|
||||||
|
char *cmd = "\33[D";
|
||||||
|
if (offset <= 0) {
|
||||||
|
offset &= ~0xffffffff;
|
||||||
|
cmd = "\33[C";
|
||||||
|
}
|
||||||
|
for (i = 0; i < offset; i++) {
|
||||||
|
SYSCALL(write, 1, cmd, 3);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
void msh_write(char *st, SIZE_TYPE size) { SYSCALL(write, 1, st, size); }
|
void msh_write(char *st, SIZE_TYPE size) { SYSCALL(write, 1, st, size); }
|
||||||
|
|
||||||
int msh_execute(char *cmd, char **args) {
|
int msh_execute(char *cmd, char **args) {
|
||||||
SIZE_TYPE fork;
|
SIZE_TYPE fork;
|
||||||
|
|
||||||
|
if (*cmd == '\0') {
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
fork = (SIZE_TYPE)SYSCALL(fork, 0);
|
fork = (SIZE_TYPE)SYSCALL(fork, 0);
|
||||||
|
|
||||||
if (fork == 0) {
|
if (fork == 0) {
|
||||||
|
|
|
||||||
|
|
@ -59,14 +59,18 @@ void msh_file_read(msh_file *file, char *ptr, SIZE_TYPE n);
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Read user input into ptr, stopping if it has reached n characters.
|
* Read user input into ptr, stopping if it has reached n characters.
|
||||||
* Also has to handle backspace since erasing characters is system-dependent.
|
|
||||||
* RETURNS:
|
* RETURNS:
|
||||||
* -2 = if it ran out of space.
|
* * -2 = if it ran out of space.
|
||||||
* -1 = if finished reading
|
* * -1 = if finished reading
|
||||||
* 0 < ascii character
|
* * 0 < ascii character
|
||||||
*/
|
*/
|
||||||
int msh_read_input(char *ptr, SIZE_TYPE *size, SIZE_TYPE n);
|
int msh_read_input(char *ptr, SIZE_TYPE *size, SIZE_TYPE n);
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Move terminal cursor x characters to the right. Pass in negative to go left.
|
||||||
|
*/
|
||||||
|
void msh_move_cursor(signed int offset);
|
||||||
|
|
||||||
/* Write characters to terminal. */
|
/* Write characters to terminal. */
|
||||||
void msh_write(char *st, SIZE_TYPE size);
|
void msh_write(char *st, SIZE_TYPE size);
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue