summaryrefslogtreecommitdiff
path: root/main.c
diff options
context:
space:
mode:
Diffstat (limited to 'main.c')
-rw-r--r--main.c33
1 files changed, 27 insertions, 6 deletions
diff --git a/main.c b/main.c
index 2eff315..e20ff27 100644
--- a/main.c
+++ b/main.c
@@ -2,6 +2,8 @@
#include <stdint.h>
#include <stddef.h>
+#include <stdarg.h>
+#include <stdio.h>
#include <err.h>
#include <fcntl.h>
@@ -61,6 +63,7 @@ typedef struct {
EditMode mode;
u32 count;
+ Str msg;
Str input_line, input_prompt;
Str search;
@@ -129,6 +132,18 @@ int ed_buf_save(Editor *e, u32 i) {
}
}
+Str str_printf(Arena *a, const char *fmt, ...) {
+ va_list ap;
+ va_start(ap, fmt);
+ int n = vsnprintf(NULL, 0, fmt, ap);
+ va_end(ap);
+ va_start(ap, fmt);
+ char *buf = new_arr(a, char, n + 1);
+ vsnprintf(buf, n + 1, fmt, ap);
+ va_end(ap);
+ return (Str) { buf, n };
+}
+
static inline int is_space(u32 c) {
return c <= 0x20 && c != 0;
}
@@ -415,6 +430,10 @@ void draw(void *ctx) {
else vui_chra(x++, y, ' ', a);
}
int n = COLS;
+ if (e.msg.n) {
+ x += vui_aprintf(x, y, norm, " %.*s", (int)e.msg.n, e.msg.s);
+ e.msg = (Str) { 0, 0 };
+ }
while (x < n) vui_chra(x++, y, ' ', norm);
}
@@ -450,13 +469,15 @@ void draw(void *ctx) {
if (!cur_found) vui_curs_pos(x, y);
if (e.input_line.n > 0 || e.input_prompt.n > 0) {
+ VuiAttr a = norm;
u32 x = 0;
- x += vui_putsn(0, 0, e.input_prompt.s, e.input_prompt.n);
- x += vui_putsn(x, 0, e.input_line.s, e.input_line.n);
- vui_curs_pos(x, 0);
+ u32 y = LINES - 1;
+ x += vui_putsna(0, y, e.input_prompt.s, e.input_prompt.n, a);
+ x += vui_putsna(x, y, e.input_line.s, e.input_line.n, a);
+ vui_curs_pos(x, y);
vui_curs_shape(VUI_CURS_BAR);
u32 c = COLS;
- while (x < c) vui_chr(x++, 0, ' ');
+ while (x < c) vui_chra(x++, y, ' ', a);
}
}
@@ -940,9 +961,9 @@ int main(int argc, const char **argv) {
vui_redraw_fn(draw);
while (e.bufn > 0) {
- arena_reset(&e.scratch);
EditBuf *eb = &e.buf[e.bufi];
draw(NULL);
+ arena_reset(&e.scratch); /* must happen after draw, so e.msg can persist */
switch (e.mode) {
case MODE_NORMAL:
@@ -980,7 +1001,7 @@ int main(int argc, const char **argv) {
case 'Z':
case 0x13 /* ^S */:
ed_buf_save(&e, e.bufi);
- //txt_load(&txt, "test.txt");
+ e.msg = str_printf(&e.scratch, "%.02fk written", eb->txt->len / 1024.0);
if (c == 'Z') e.bufi = ed_buf_close(&e, e.bufi);
break;
case 'i':