Skip to content

Commit 756906a

Browse files
committed
[lib][gfxconsole] Implement backspace
Includes codestyle changes
1 parent 467960e commit 756906a

File tree

1 file changed

+25
-12
lines changed

1 file changed

+25
-12
lines changed

lib/gfxconsole/gfxconsole.c

Lines changed: 25 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -15,14 +15,14 @@
1515
* @ingroup graphics
1616
*/
1717

18-
#include <lk/debug.h>
1918
#include <assert.h>
20-
#include <lib/io.h>
21-
#include <lk/init.h>
19+
#include <dev/display.h>
20+
#include <lib/font.h>
2221
#include <lib/gfx.h>
2322
#include <lib/gfxconsole.h>
24-
#include <lib/font.h>
25-
#include <dev/display.h>
23+
#include <lib/io.h>
24+
#include <lk/debug.h>
25+
#include <lk/init.h>
2626

2727
/** @addtogroup graphics
2828
* @{
@@ -43,14 +43,25 @@ static struct {
4343
} gfxconsole;
4444

4545
static void gfxconsole_putc(char c) {
46-
static enum { NORMAL, ESCAPE } state = NORMAL;
46+
static enum { NORMAL,
47+
ESCAPE } state = NORMAL;
4748
static uint32_t p_num = 0;
4849

4950
switch (state) {
5051
case NORMAL: {
5152
if (c == '\n' || c == '\r') {
5253
gfxconsole.x = 0;
5354
gfxconsole.y++;
55+
} else if (c == '\b') {
56+
if (gfxconsole.x > 0) {
57+
gfxconsole.x--;
58+
}
59+
60+
gfx_fillrect(gfxconsole.surface, gfxconsole.x * FONT_X, gfxconsole.y * FONT_Y,
61+
FONT_X, FONT_Y, gfxconsole.back_color);
62+
63+
gfx_flush_rows(gfxconsole.surface, gfxconsole.y * FONT_Y,
64+
(gfxconsole.y * FONT_Y) + FONT_Y);
5465
} else if (c == 0x1b) {
5566
p_num = 0;
5667
state = ESCAPE;
@@ -65,8 +76,9 @@ static void gfxconsole_putc(char c) {
6576
if (c >= '0' && c <= '9') {
6677
p_num = (p_num * 10) + (c - '0');
6778
} else if (c == 'D') {
68-
if (p_num <= gfxconsole.x)
79+
if (p_num <= gfxconsole.x) {
6980
gfxconsole.x -= p_num;
81+
}
7082
state = NORMAL;
7183
} else if (c == '[') {
7284
// eat this character
@@ -99,10 +111,9 @@ void gfxconsole_print_callback(print_callback_t *cb, const char *str, size_t len
99111
}
100112

101113
static print_callback_t cb = {
102-
.entry = { 0 },
114+
.entry = {0},
103115
.print = gfxconsole_print_callback,
104-
.context = NULL
105-
};
116+
.context = NULL};
106117

107118
/**
108119
* @brief Initialize graphics console on given drawing surface.
@@ -141,13 +152,15 @@ void gfxconsole_start(gfx_surface *surface) {
141152
void gfxconsole_start_on_display(void) {
142153
static bool started = false;
143154

144-
if (started)
155+
if (started) {
145156
return;
157+
}
146158

147159
/* pop up the console */
148160
struct display_framebuffer fb;
149-
if (display_get_framebuffer(&fb) < 0)
161+
if (display_get_framebuffer(&fb) < 0) {
150162
return;
163+
}
151164

152165
gfx_surface *s = gfx_create_surface_from_display(&fb);
153166
gfxconsole_start(s);

0 commit comments

Comments
 (0)