Skip to content

Commit

Permalink
fix y leveling
Browse files Browse the repository at this point in the history
  • Loading branch information
jwt2706 committed Aug 24, 2024
1 parent 2cca12b commit a3d6599
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 6 deletions.
2 changes: 2 additions & 0 deletions kernel/include/terminal.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@

struct terminal {
struct limine_framebuffer *framebuffer;
int start_x;
int start_y;
int cursor_x;
int cursor_y;
uint32_t color;
Expand Down
2 changes: 1 addition & 1 deletion kernel/src/kernel.c
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ void _start(void) {
struct terminal term;
terminal_init(&term, framebuffer, COLOR_WHITE, 2);

terminal_write(&term, "BaboscOS booted up successfully!BaboscOS booted up successfully!BaboscOS booted up successfully!BaboscOS booted up successfully!BaboscOS booted up successfully!");
terminal_write(&term, "BaboscOS booted up successfully!BaboscOS booted up successfully!BaboscOS booted up successfully!");
terminal_edit(&term, COLOR_RED, 3);
terminal_write(&term, "red color and scalesadasdasdsads 3");

Expand Down
10 changes: 5 additions & 5 deletions kernel/src/terminal.c
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,10 @@

void terminal_init(struct terminal *term, struct limine_framebuffer *framebuffer, uint32_t color, int scale) {
term->framebuffer = framebuffer;
term->cursor_x = 4;
term->cursor_y = 4;
term->start_x = 4;
term->start_y = 4;
term->cursor_x = term->start_x;
term->cursor_y = term->start_y;
term->color = color;
term->scale = scale;
}
Expand All @@ -19,20 +21,18 @@ void terminal_edit(struct terminal *term, uint32_t color, int scale) {
but take into account, special things like '\n' for new lines.
*/
void terminal_write(struct terminal *term, const char *str) {
int start_x = term->cursor_x;
int max_x = term->framebuffer->width - 8 * term->scale; // maximum x position before wrapping
while (*str) {
if (*str == '\n' || term->cursor_x > max_x) { // if the character is a newline or cursor exceeds max_x..
term->cursor_y += 8 * term->scale; // ..offset y
term->cursor_x = start_x; // ..and reset x
term->cursor_x = term->start_x; // ..and reset x
}
if (*str != '\n') {
terminal_write_char(term, *str);
term->cursor_x += 8 * term->scale; // offset x for each new character so they don't just print on top of each other
}
str++;
}
term->cursor_x = start_x;
}

/*
Expand Down

0 comments on commit a3d6599

Please sign in to comment.