Beispiel #1
0
/**
 * Start Tiny Shell process.
 */
void tiny_shell_init() {

	uint32_t 	buff_position = 0;
	uint8_t 	prompt_line = 0;

	parse_prompt();
	print_prompt();

	// start scan keyboard...
	while(1) {
		enum KEYCODE key = scan_keyboard();
		switch (key) {
			case KEY_RETURN:
				// terminate command_buffer string
				command_buffer[buff_position] = 0;
				vga_text_mode_putc('\n');
				if (!tsh_exec()) {
					kprintf("tshell: %s: command not found", command_buffer);
				}
				// reset buffer position
				buff_position = 0;
				print_prompt();
				prompt_line = 0;
				break;
			case KEY_BACKSPACE:
				// delete previous character on line
				if (vga_text_mode_cursor_getX() >= _prompt_info.prompt_len && prompt_line==0) {
					vga_text_mode_putc(kbrd_key_to_ascii(key));
					if (buff_position>0)
						buff_position--;
				}
				// roll-back cursor to previous line and delete character
				if (prompt_line>0) {
					if (prompt_line>0 && ((buff_position+_prompt_info.prompt_len-1) == (prompt_line)*COLS))
						prompt_line--;
					vga_text_mode_putc(kbrd_key_to_ascii(key));
					if (buff_position>0)
						buff_position--;
				}
				break;
			default :
				if (isascii(key)) {
					if (buff_position <= max_len_com_buffer-1) {
						command_buffer[buff_position++] = kbrd_key_to_ascii(key);
						if (prompt_line>0 && ((buff_position+_prompt_info.prompt_len-2) == (prompt_line+1)*COLS))
							prompt_line++;
						if (prompt_line==0 && (buff_position+_prompt_info.prompt_len-1 > COLS))
							prompt_line++;
						vga_text_mode_putc(kbrd_key_to_ascii(key));
					}
				}
		}
	}
}
Beispiel #2
0
int syscall_read(unsigned int fd, char * buf, unsigned int size)
{
	int read = -1;
	enum KEYCODE keycode = KEY_UNKNOWN;
	char code;

	/* this function will return when the buffer gets consumed! */
	while ((keycode = kbrd_get_key()) != KEY_UNKNOWN) {
		read++;
		/* Most naive version to get keys working */
		code = kbrd_key_to_ascii(keycode);
		if(code != 0)
		{
			buf[read] = code;
		}
	}

	return read;
}