mirror of
https://github.com/wichtounet/thor-os.git
synced 2025-09-17 08:37:17 -04:00
Implement real canonical mode
This commit is contained in:
parent
4f44367468
commit
9eb9c5e4ea
@ -18,7 +18,6 @@ constexpr const size_t MAX_TERMINALS = 2;
|
||||
size_t active_terminal;
|
||||
|
||||
bool shift = false;
|
||||
bool ctrl = false;
|
||||
|
||||
std::array<stdio::virtual_terminal, MAX_TERMINALS> terminals;
|
||||
|
||||
@ -36,22 +35,17 @@ void stdio::virtual_terminal::send_input(char key){
|
||||
key &= ~(0x80);
|
||||
if(key == keyboard::KEY_LEFT_SHIFT || key == keyboard::KEY_RIGHT_SHIFT){
|
||||
shift = false;
|
||||
} else if(key == keyboard::KEY_LEFT_CTRL){
|
||||
ctrl = false;
|
||||
}
|
||||
}
|
||||
//Key pressed
|
||||
else {
|
||||
if(key == keyboard::KEY_LEFT_SHIFT || key == keyboard::KEY_RIGHT_SHIFT){
|
||||
shift = true;
|
||||
} else if(key == keyboard::KEY_LEFT_CTRL){
|
||||
ctrl = true;
|
||||
} else if(key == keyboard::KEY_BACKSPACE){
|
||||
if(!input_buffer.empty() || !canonical_buffer.empty()){
|
||||
if(!input_buffer.empty()){
|
||||
input_buffer.pop_last();
|
||||
print('\b');
|
||||
}
|
||||
|
||||
input_buffer.push('\b');
|
||||
} else {
|
||||
auto qwertz_key =
|
||||
shift
|
||||
@ -59,16 +53,19 @@ void stdio::virtual_terminal::send_input(char key){
|
||||
: keyboard::key_to_ascii(key);
|
||||
|
||||
if(qwertz_key){
|
||||
if(ctrl && qwertz_key == 'c'){
|
||||
input_buffer.push(200);
|
||||
} else {
|
||||
input_buffer.push(qwertz_key);
|
||||
input_buffer.push(qwertz_key);
|
||||
|
||||
print(qwertz_key);
|
||||
}
|
||||
print(qwertz_key);
|
||||
|
||||
if(!input_queue.empty()){
|
||||
input_queue.wake_up();
|
||||
if(qwertz_key == '\n'){
|
||||
// Transfer current line to the canonical buffer
|
||||
while(!input_buffer.empty()){
|
||||
canonical_buffer.push(input_buffer.pop());
|
||||
}
|
||||
|
||||
if(!input_queue.empty()){
|
||||
input_queue.wake_up();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -80,42 +77,18 @@ void stdio::virtual_terminal::send_input(char key){
|
||||
|
||||
size_t stdio::virtual_terminal::read_input(char* buffer, size_t max){
|
||||
size_t read = 0;
|
||||
char c;
|
||||
|
||||
while(true){
|
||||
while(read < max && !input_buffer.empty()){
|
||||
c = input_buffer.pop();
|
||||
while(!canonical_buffer.empty()){
|
||||
auto c = canonical_buffer.pop();
|
||||
|
||||
canonical_buffer.push(c);
|
||||
buffer[read++] = c;
|
||||
|
||||
if(c == '\b'){
|
||||
if(read > 0){
|
||||
--read;
|
||||
}
|
||||
} else {
|
||||
++read;
|
||||
|
||||
if(c == '\n'){
|
||||
break;
|
||||
}
|
||||
if(read >= max || c == '\n'){
|
||||
return read;
|
||||
}
|
||||
}
|
||||
|
||||
if(read > 0 && (c == '\n' || c == 200 || read == max)){
|
||||
read = 0;
|
||||
while(!canonical_buffer.empty()){
|
||||
auto value = canonical_buffer.pop();
|
||||
|
||||
if(value == '\b'){
|
||||
--read;
|
||||
} else {
|
||||
buffer[read++] = value;
|
||||
}
|
||||
}
|
||||
|
||||
return read;
|
||||
}
|
||||
|
||||
input_queue.sleep();
|
||||
}
|
||||
}
|
||||
|
@ -113,17 +113,13 @@ void pwd_command(const std::vector<std::string>&){
|
||||
int main(){
|
||||
get_console_information();
|
||||
|
||||
char input_buffer[128];
|
||||
char input_buffer[256];
|
||||
std::string current_input;
|
||||
|
||||
print("thor> ");
|
||||
|
||||
while(true){
|
||||
auto c = read_input(input_buffer, 127);
|
||||
|
||||
if(input_buffer[c-1] == 200){
|
||||
input_buffer[c-1] = '\n';
|
||||
}
|
||||
auto c = read_input(input_buffer, 255 );
|
||||
|
||||
if(input_buffer[c-1] == '\n'){
|
||||
if(c > 1){
|
||||
|
Loading…
x
Reference in New Issue
Block a user