Add support for UP and DOWN history navigation

This commit is contained in:
Baptiste Wicht 2013-11-10 21:55:04 +01:00
parent 6617f9ed8c
commit 9fd2b0c64b
5 changed files with 54 additions and 4 deletions

View File

@ -134,7 +134,7 @@ second_step:
; Loading the assembly kernel from floppy
KERNEL_BASE equ 0x100 ; 0x100:0x0 = 0x1000
sectors equ 0x40 ; sectors to read
sectors equ 0x42 ; sectors to read
bootdev equ 0x0
mov ax, KERNEL_BASE

View File

@ -1,5 +1,5 @@
#!/bin/bash
size=`stat -c%s kernel/kernel.bin`
let filler_size=16384-$size
let filler_size=17408-$size
dd if=/dev/zero of=filler.bin bs=1 count=$filler_size

View File

@ -15,6 +15,7 @@ namespace keyboard {
const char KEY_ENTER = 0x1C;
const char KEY_BACKSPACE = 0x0E;
const char KEY_UP = 0x48;
const char KEY_DOWN = 0x50;
void install_driver();
char get_char();

View File

@ -60,6 +60,14 @@ public:
return _capacity;
}
const value_type& operator[](size_type pos) const {
return data[pos];
}
value_type& operator[](size_type pos){
return data[pos];
}
//Modifiers
void push_back(value_type& element){

View File

@ -88,8 +88,42 @@ void start_shell(){
}
k_print("thor> ");
} else if(key == keyboard::KEY_UP){
//TODO
} else if(key == keyboard::KEY_UP || key == keyboard::KEY_DOWN){
if(history.size() > 0){
if(key == keyboard::KEY_UP){
if(history_index == 0){
continue;
}
--history_index;
} else { //KEY_DOWN
if(history_index == history.size()){
continue;
}
++history_index;
}
set_column(6);
for(uint64_t i = 0; i < current_input_length; ++i){
k_print(' ');
}
set_column(6);
current_input_length = 0;
if(history_index < history.size()){
auto saved = history[history_index];
while(*saved){
current_input[current_input_length++] = *saved;
k_print(*saved);
++saved;
}
}
}
} else if(key == keyboard::KEY_BACKSPACE){
if(current_input_length > 0){
k_print('\b');
@ -111,6 +145,13 @@ void start_shell(){
void exec_command(){
char buffer[50];
auto saved = new char[current_input_length + 1];
memcopy(saved, current_input, current_input_length);
saved[current_input_length] = '\0';
history.push_back(saved);
history_index = history.size();
for(auto& command : commands){
const char* input_command = current_input;
if(str_contains(current_input, ' ')){