Added caps lock support to readline

This commit is contained in:
Xnoe 2021-09-03 12:02:37 +01:00
parent d9d3abbf62
commit 8f1e13e749
Signed by: xnoe
GPG Key ID: 45AC398F44F0DAFE

View File

@ -1,6 +1,5 @@
#include "keyboard.h" #include "keyboard.h"
char key_to_char[128] = { char key_to_char[128] = {
0, 0, '1', '2', '3', '4', '5', '6', '7', '8', '9', '0', '-', '=', 0, 0, 0, 0, '1', '2', '3', '4', '5', '6', '7', '8', '9', '0', '-', '=', 0, 0,
'q', 'w', 'e', 'r', 't', 'y', 'u', 'i', 'o', 'p', '[', ']', 0, 'q', 'w', 'e', 'r', 't', 'y', 'u', 'i', 'o', 'p', '[', ']', 0,
@ -60,9 +59,8 @@ void readline(int max, char* buffer) {
int index = 0; int index = 0;
uint8_t scancode = current_scancode; uint8_t scancode = 0;
while (scancode != 0x1c || index == 0) { while (scancode != 0x1c && index < max) {
while (scancode == current_scancode);
scancode = current_scancode; scancode = current_scancode;
char decoded = 0; char decoded = 0;
@ -70,21 +68,28 @@ void readline(int max, char* buffer) {
if ((scancode&0x7f) == 0x2a) if ((scancode&0x7f) == 0x2a)
shift_on = !(scancode&0x80); shift_on = !(scancode&0x80);
if (scancode == 0x3a)
caps_on ^= 1;
if (scancode == 0x0e && index > 0) { if (scancode == 0x0e && index > 0) {
set_curpos_raw(get_curpos()-1); set_curpos_raw(get_curpos()-1);
non_moving_put(' '); non_moving_put(' ');
index--; buffer[--index] = 0;
} }
if (!shift_on) if (shift_on)
decoded = key_to_char[scancode&0x7f];
else
decoded = key_to_char_shift[scancode&0x7f]; decoded = key_to_char_shift[scancode&0x7f];
else if (caps_on)
decoded = key_to_char_caps[scancode&0x7f];
else
decoded = key_to_char[scancode&0x7f];
if (decoded && scancode < 0x80) { if (decoded && scancode < 0x80) {
buffer[index++] = decoded; buffer[index++] = decoded;
printf("%c", decoded); printf("%c", decoded);
} }
while (scancode == current_scancode);
} }
printf("\n"); printf("\n");
} }