console: support writing to console
Add kmscon_console_write() to write a character to the current position of the cursor. The cursor is automatically moved to the next cell. Also extend the test_console example to use this new function. Signed-off-by: David Herrmann <dh.herrmann@googlemail.com>
This commit is contained in:
parent
7402e5e753
commit
d75404742b
@ -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++;
|
||||
}
|
||||
|
@ -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);
|
||||
|
@ -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;
|
||||
|
Loading…
x
Reference in New Issue
Block a user