summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorWormHeamer2026-01-02 03:37:06 -0500
committerWormHeamer2026-01-02 03:37:06 -0500
commit5898b883c8cb2817dade1b234ad29ceeab624c0e (patch)
tree313736c0e9c60e418350be60f57b303b6b3440f5
parent228e08259b7c2bb666c2dc0fdd09d9a82a105eb9 (diff)
clean up some rendering code
-rw-r--r--main.c61
1 files changed, 32 insertions, 29 deletions
diff --git a/main.c b/main.c
index 4e31e6f..80628d4 100644
--- a/main.c
+++ b/main.c
@@ -512,45 +512,48 @@ static Str basename(Str s) {
}
}
+#define STYLE_BUF (A_DEFAULT)
+#define STYLE_BUF_SEL (STYLE_BUF | A_REVERSE)
+#define STYLE_TXT (A_DEFAULT)
+#define STYLE_TRAILSP (BG_BLUE | FG_DEFAULT)
+
+void draw_status_line(Editor *e) {
+ int x = 0;
+ int y = 0;
+ x += vui_aprintf(x, y, STYLE_BUF, " %s ", mode_key_str[e->mode]);
+ for (u32 i = 0; i < e->bufn; i++) {
+ EditBuf *b = &e->buf[i];
+ VuiAttr a = i == e->bufi ? STYLE_BUF_SEL : STYLE_BUF;
+ Str p = basename(b->path);
+ x += vui_aprintf(x, y, a, " %.*s", (int)p.n, p.s);
+ if (b->type != ED_BUF_SCRATCH && b->txt->ptbl.dirty) vui_chra(x++, y, '*', a);
+ vui_chra(x++, y, ' ', a);
+ }
+ int n = COLS;
+ if (e->msg.n) {
+ x += vui_aprintf(x, y, STYLE_BUF, " %.*s",
+ (int)e->msg.n, e->msg.s);
+ e->msg = (Str) { 0, 0 };
+ }
+ while (x < n) vui_chra(x++, y, ' ', STYLE_BUF);
+}
+
void draw_buf(EditBuf *eb) {
u32 lmarg = 0;
u32 tmarg = 1;
u32 bmarg = 0;
- u32 status_y = 0;
u32 x = lmarg, y = tmarg;
- TxtLoc start, end;
- find_view_window(eb->cur, &start, &end, LINES - (tmarg + bmarg));
- VuiAttr norm = A_DEFAULT;
- VuiAttr txt = A_DEFAULT;
- VuiAttr trailsp = BG_BLUE | FG_DEFAULT;
- VuiAttr sel = norm | A_REVERSE;
+ VuiAttr txt = STYLE_TXT;
if (eb->txt->readonly) txt = FG_CYAN | BG_DEFAULT;
vui_clear();
- {
- int x = 0;
- int y = status_y;
- x += vui_aprintf(x, y, norm, " %s ", mode_key_str[e.mode]);
- for (u32 i = 0; i < e.bufn; i++) {
- EditBuf *b = &e.buf[i];
- VuiAttr a = i == e.bufi ? sel : norm;
- Str p = basename(b->path);
- x += vui_aprintf(x, y, a, " %.*s", (int)p.n, p.s);
- if (b->type != ED_BUF_SCRATCH && b->txt->ptbl.dirty) vui_chra(x++, y, '*', a);
- 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);
- }
+ draw_status_line(&e);
TxtLoc l = eb->cur;
int cur_found = 0;
+ TxtLoc start, end;
+ find_view_window(eb->cur, &start, &end, LINES - (tmarg + bmarg));
while (txt_before(start, end)) {
if (l.p == start.p && l.i == start.i) {
cur_found = 1;
@@ -566,7 +569,7 @@ void draw_buf(EditBuf *eb) {
y++;
} else if (c == '\n' || c == '\t' || c == ' ') {
int trail = txt_chr(start) == '\n' && !(l.p == start.p && l.i == start.i);
- VuiAttr a = trail ? trailsp : txt;
+ VuiAttr a = trail ? STYLE_TRAILSP : txt;
if (c == '\t') {
u32 n = 1 + (-(x+1) & 7);
while (n--) vui_chra(x++, y, ' ', a);
@@ -601,7 +604,7 @@ void draw_buf(EditBuf *eb) {
}
if (e.input_line.n > 0 || e.input_prompt.n > 0) {
- VuiAttr a = norm;
+ VuiAttr a = STYLE_BUF;
u32 x = 0;
u32 y = LINES - 1;
x += vui_putsna(0, y, e.input_prompt.s, e.input_prompt.n, a);