diff options
Diffstat (limited to 'src/user/terminal')
-rw-r--r-- | src/user/terminal/main.c | 48 |
1 files changed, 28 insertions, 20 deletions
diff --git a/src/user/terminal/main.c b/src/user/terminal/main.c index 3c9eb04..b3e1d9f 100644 --- a/src/user/terminal/main.c +++ b/src/user/terminal/main.c @@ -11,22 +11,23 @@ #include <pland/pcrt.h> #define FONT_HARDCODE "fixed-10" +#define PADDING 2 _window_handle_t window; -uint8_t *pixbuf; +_pixel_t *pixbuf; char *termbuf; struct font_info *font; uint32_t width; uint32_t height; -uint32_t cols = 50; -uint32_t rows = 15; +uint32_t cols = 100; +uint32_t rows = 30; uint32_t cursor_y = 0; uint32_t cursor_x = 0; -uint8_t bg_color = 0x10; -uint8_t fg_color = 0x07; +_pixel_t bg_color = (_pixel_t){.r = 0, .g = 0, .b = 0}; +_pixel_t fg_color = (_pixel_t){.r = 0xff, .g = 0xff, .b = 0xff}; struct waiting_for_key_record { _task_handle_t task; @@ -35,7 +36,7 @@ struct waiting_for_key_record { static void draw_char(uint32_t y, uint32_t x, bool inverted) { //syslogf("drawing 0x%2h%s at %u, %u", termbuf[y * cols + x], inverted ? " inverted" : "", y, x); - put_char(font, termbuf[y * cols + x], pixbuf + y * font->space_height * width + x * font->space_width, width, inverted ? fg_color : bg_color, inverted ? bg_color : fg_color); + put_char(font, termbuf[y * cols + x], pixbuf + (y * font->space_height + PADDING) * width + (x * font->space_width + PADDING), width, inverted ? fg_color : bg_color, inverted ? bg_color : fg_color); } static void clear() { @@ -52,9 +53,9 @@ static void scroll_fw() { for (; i < cols * rows; ++i) termbuf[i] = ' '; const uint32_t row_height = font->space_height; - for (i = 0; i < width * (height - row_height); ++i) + for (i = width * PADDING; i < width * (height - PADDING - row_height); ++i) pixbuf[i] = pixbuf[i + width * row_height]; - for (; i < width * height; ++i) + for (; i < width * (height - PADDING); ++i) pixbuf[i] = bg_color; } @@ -187,9 +188,9 @@ static void set_dimensions(uint32_t new_rows, uint32_t new_cols) { cols = new_cols; termbuf = get_block(rows * cols); - width = cols * font->space_width; - height = cols * font->space_height; - pixbuf = get_block(width * height); + width = cols * font->space_width + PADDING * 2; + height = cols * font->space_height + PADDING * 2; + pixbuf = get_block(width * height * 4); cursor_y = 0; cursor_x = 0; @@ -199,27 +200,34 @@ static void set_dimensions(uint32_t new_rows, uint32_t new_cols) { } void draw_all() { + for (uint32_t y = 0; y < PADDING; ++y) + for (uint32_t x = 0; x < width; ++x) + pixbuf[y * width + x] = bg_color; + for (uint32_t y = height - PADDING; y < height; ++y) + for (uint32_t x = 0; x < width; ++x) + pixbuf[y * width + x] = bg_color; + for (uint32_t x = 0; x < PADDING; ++x) + for (uint32_t y = PADDING; y < height - PADDING; ++y) + pixbuf[y * width + x] = bg_color; + for (uint32_t x = width - PADDING; x < width; ++x) + for (uint32_t y = PADDING; y < height - PADDING; ++y) + pixbuf[y * width + x] = bg_color; + for (uint32_t y = 0; y < rows; ++y) for (uint32_t x = 0; x < cols; ++x) draw_char(y, x, false); draw_char(cursor_y, cursor_x, true); } -//#include <knob/format.h> - void main(const char *cmd) { -//syslogf(" this task: 0x%2h", this_task); -//syslogf(" stdio task: 0x%2h", stdio_task); -//syslogf("calling task: 0x%2h", calling_task); - font = get_font(FONT_HARDCODE); if (!font) return; termbuf = get_block(cols * rows); - width = cols * font->space_width; - height = rows * font->space_height; - pixbuf = get_block(width * height); + width = cols * font->space_width + PADDING * 2; + height = rows * font->space_height + PADDING * 2; + pixbuf = get_block(width * height * 4); clear(); add_sz_ww("Portland Terminal\n"); window = _new_window(width, height, pixbuf); |