newline support in putch

This commit is contained in:
shockrahwow 2019-11-29 16:50:33 -08:00
parent df5058ad4c
commit abcef63c21

31
stlio.c
View File

@ -1,5 +1,9 @@
#include "types.h"
#include "kbd.h"
#include "stlio.h" #include "stlio.h"
extern char kbd_prev_key;
extern int kbd_prev_active;
static u8 COLOR_FG = Green; static u8 COLOR_FG = Green;
static u8 COLOR_BG = White; static u8 COLOR_BG = White;
@ -30,6 +34,26 @@ u32 write(const char* buffer, const u32 size) {
return i; return i;
} }
u32 read(char* buffer, u32 size) {
// Read up to size-1 characters or until a \n is written
// once we reacch size -1 bytes read then we change the last char to a \0
kbd_prev_active = false; // we only do this to discard the leftovers from
u32 bytes_read = 0;
while(bytes_read < size-1) {
if(kbd_prev_active) {
bytes_read++;
if(kbd_prev_key == '\n') {
break;
}
else {
buffer[bytes_read] = kbd_prev_key;
}
}
}
printf("You entered: "); printf(buffer);
return bytes_read;
}
void printf(const char* fmt) { void printf(const char* fmt) {
// Variadic fuller version of print on seperate branch but its nowhere near stable/ready/working // Variadic fuller version of print on seperate branch but its nowhere near stable/ready/working
u32 size = strlen(fmt); u32 size = strlen(fmt);
@ -56,5 +80,10 @@ void printhex(u32 num) {
} }
void putch(const char c) { void putch(const char c) {
write_char(c); if(c == '\n') {
frame_buffer_newline();
}
else {
write_char(c);
}
} }