summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--main.c54
1 files changed, 45 insertions, 9 deletions
diff --git a/main.c b/main.c
index f380d97..2ab4eba 100644
--- a/main.c
+++ b/main.c
@@ -21,9 +21,8 @@
/* TODO
*
- * - utf-8 input
- * - arrow keys
- * - KEY_RESIZE or draw callback
+ * - clean up keyboard input
+ * - separate out library interface
* - maybe some custom colors
*/
@@ -165,6 +164,24 @@ static void vui_clear(void) {
clear_buf(vui_win.front);
}
+void vui_fill_rect(VuiChar c, VuiAttr a, int x0, int y0, int width, int height) {
+ if (x0 < 0) { width += x0; x0 = 0; }
+ if (y0 < 0) { height += y0; y0 = 0; }
+ if (x0 + width >= COLS) width = (COLS - 1) - x0;
+ if (y0 + height >= LINES) height = (LINES - 1) - y0;
+ if (width < 1 || height < 1) return;
+ for (int y = y0; y < y0 + height; y++) {
+ for (int x = x0; x < x0 + width; x++) {
+ CHR(x, y) = c;
+ ATTR(x, y) = a;
+ }
+ }
+}
+
+void vui_fill(VuiChar c, VuiAttr a) {
+ vui_fill_rect(c, a, 0, 0, COLS, LINES);
+}
+
static void resize_buf(VuiBuffer *buf, unsigned nw, unsigned nh) {
VuiChar *nchr = calloc(nw * nh, sizeof(*buf->chr));
uint16_t *nattr = calloc(nw * nh, sizeof(*buf->attr));
@@ -675,6 +692,27 @@ static inline u32 utf8_next(u32 *p, const char *s, u32 n) {
return cp;
}
+void vui_putsna(int x, int y, const char *s, unsigned n, VuiAttr a) {
+ for (unsigned i = 0; i < n && x < COLS;) {
+ u32 c = utf8_next(&i, s, n);
+ CHR(x, y) = c;
+ ATTR(x, y) = a;
+ x++;
+ }
+}
+
+void vui_putsn(int x, int y, const char *s, unsigned n) {
+ return vui_putsna(x, y, s, n, ATTR_DEFAULT);
+}
+
+void vui_putsa(int x, int y, const char *s, VuiAttr a) {
+ return vui_putsna(x, y, s, strlen(s), a);
+}
+
+void vui_puts(int x, int y, const char *s) {
+ return vui_putsn(x, y, s, strlen(s));
+}
+
int vui_avprintf(int x, int y, VuiAttr a, const char *fmt, va_list ap) {
va_list ap2;
va_copy(ap2, ap);
@@ -685,12 +723,7 @@ int vui_avprintf(int x, int y, VuiAttr a, const char *fmt, va_list ap) {
if (n > 0) {
char buf[n + 1];
vsnprintf(buf, n + 1, fmt, ap2);
- for (unsigned i = 0; i < n && x < COLS;) {
- u32 c = utf8_next(&i, buf, n);
- CHR(x, y) = c;
- ATTR(x, y) = a;
- x++;
- }
+ vui_putsna(x, y, buf, n, a);
}
return n;
}
@@ -925,6 +958,9 @@ int main(int argc, const char **argv) {
int top = 5;
int bottom = LINES - 5;
+ vui_fill(' ', FG_BLACK | BG_BLUE);
+ vui_fill_rect(' ', FG_BLACK | BG_WHITE, left, top, right - left, bottom - top);
+
if (y < top) { scroll_y = top - y; }
if (y > bottom) { scroll_y = bottom - y; }