X-Git-Url: http://git.dujemihanovic.xyz/%7B%7B%20%24style.RelPermalink%20%7D%7D?a=blobdiff_plain;f=kernel%2Farch%2Fx86%2Ftty%2Ftty.c;h=ca0c3e7df95466878a7a933fc487c073e126b680;hb=41cf62fc4e0ab87d8fbb584678a2d2e1dccdc065;hp=07d734e54fc00f1919e51e0efe624271158c2e01;hpb=b87962874082db4093c960cf613eedae918180fc;p=nameless-os.git diff --git a/kernel/arch/x86/tty/tty.c b/kernel/arch/x86/tty/tty.c index 07d734e..ca0c3e7 100644 --- a/kernel/arch/x86/tty/tty.c +++ b/kernel/arch/x86/tty/tty.c @@ -1,6 +1,7 @@ #include #include #include +#include #define VGA_WIDTH 80 #define VGA_HEIGHT 25 @@ -11,6 +12,7 @@ static int cursor_x = 0; /* keep track of where cursor is */ static int cursor_y = 0; char *hex_chars = "0123456789ABCDEF"; +char kgets_buffer[100]; void screen_clear(void) { @@ -74,6 +76,16 @@ void kprintc(const char character, uint8_t color) uint16_t crtc_port; if ( character == '\n') { cursor_x = 0; cursor_y++; } + if (character == 0x7f) { + cursor_x--; + if (cursor_x < 0) { + if (cursor_y > 0) { + cursor_x = VGA_WIDTH - 1; + cursor_y--; + } else cursor_x = 0; + } + video_memory[(cursor_y * VGA_WIDTH + cursor_x) * 2] = ' '; + } else { video_memory[(cursor_y * VGA_WIDTH + cursor_x) * 2] = character; video_memory[((cursor_y * VGA_WIDTH + cursor_x++) * 2)+ 1] = color != 0 ? color : VGA_COLOR_LIGHT_GRAY; } if ( cursor_x >= VGA_WIDTH ) { cursor_x = 0; cursor_y++; } if ( cursor_y >= VGA_HEIGHT ) { scroll_up(); } @@ -137,3 +149,29 @@ void kprintd(uint32_t dword) temp = dword & 0xF; kprintc(hex_chars[temp], VGA_COLOR_LIGHT_GRAY); } + +char *kgets() +{ + for (int i=0; i<100; i++) { + kgets_buffer[i] = '\0'; + } + + int i=0; + while (i<100) { + char temp = ps2_get_keystroke(); + if (temp == '\n') break; + if (temp == 0x7f) { + if (i>0) { + i-=1; + kgets_buffer[i] = '\0'; + kprintc(temp, 0); + } + continue; + } + kgets_buffer[i] = temp; + kprintc(temp, 0); + i++; + } + + return kgets_buffer; +}