diff --git a/src/console.c b/src/console.c index 6009361..7533215 100644 --- a/src/console.c +++ b/src/console.c @@ -63,6 +63,12 @@ struct kmscon_console { /* console cells */ struct kmscon_buffer *cells; + unsigned int cells_x; + unsigned int cells_y; + + /* cursor */ + unsigned int cursor_x; + unsigned int cursor_y; /* active font */ struct kmscon_font *font; @@ -99,6 +105,9 @@ int kmscon_console_new(struct kmscon_console **out) if (ret) goto err_free; + con->cells_x = kmscon_buffer_get_width(con->cells); + con->cells_y = kmscon_buffer_get_height(con->cells); + ret = kmscon_console_set_res(con, 800, 600); if (ret) goto err_buf; @@ -286,3 +295,22 @@ void kmscon_console_map(struct kmscon_console *con) glVertex2f(-1.0f, 1.0f); glEnd(); } + +void kmscon_console_write(struct kmscon_console *con, + const struct kmscon_char *ch) +{ + if (!con) + return; + + if (con->cursor_x == con->cells_x) { + con->cursor_x = 0; + con->cursor_y++; + if (con->cursor_y == con->cells_y) { + con->cursor_y--; + kmscon_buffer_rotate(con->cells); + } + } + + kmscon_buffer_write(con->cells, con->cursor_x, con->cursor_y, ch); + con->cursor_x++; +} diff --git a/src/console.h b/src/console.h index c4826a0..2ddb9b8 100644 --- a/src/console.h +++ b/src/console.h @@ -95,3 +95,6 @@ void kmscon_console_unref(struct kmscon_console *con); int kmscon_console_set_res(struct kmscon_console *con, uint32_t x, uint32_t y); void kmscon_console_draw(struct kmscon_console *con); void kmscon_console_map(struct kmscon_console *con); + +void kmscon_console_write(struct kmscon_console *con, + const struct kmscon_char *ch); diff --git a/tests/test_console.c b/tests/test_console.c index c29ecd8..9b99d46 100644 --- a/tests/test_console.c +++ b/tests/test_console.c @@ -198,6 +198,8 @@ static void destroy_eloop(struct console *con) static int setup_eloop(struct console *con) { int ret; + unsigned int i; + struct kmscon_char *ch; ret = kmscon_eloop_new(&con->loop); if (ret) @@ -229,6 +231,15 @@ static int setup_eloop(struct console *con) if (ret) goto err_loop; + ret = kmscon_char_new_u8(&ch, "J", 1); + if (ret) + goto err_loop; + + for (i = 0; i < 80 * 24 - 1; ++i) + kmscon_console_write(con->con, ch); + + kmscon_char_free(ch); + ret = kmscon_compositor_new(&con->comp); if (ret) goto err_loop;