summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--main.c78
1 files changed, 60 insertions, 18 deletions
diff --git a/main.c b/main.c
index d2d5dff..2eff315 100644
--- a/main.c
+++ b/main.c
@@ -46,6 +46,13 @@ typedef enum {
MODE_REPLACE_MULT
} EditMode;
+static const char *mode_str[] = {
+ "N",
+ "I",
+ "R",
+ "R",
+};
+
typedef struct {
Arena scratch;
EditBuf buf[ED_BUF_MAX];
@@ -387,30 +394,28 @@ void draw(void *ctx) {
vui_clear();
int lmarg = 0;
- int x = lmarg, y = 1;
+ int x = lmarg, y = 0;
TxtLoc start, end;
find_view_window(eb->cur, &start, &end, LINES - 1);
- vui_aprintf(-1, 0, ODD_ATTR, "%u piece(s)", eb->txt->ptbl.n);
- for (u32 i = 0; i < eb->txt->ptbl.n; i++) {
- TxtPiece *p = &eb->txt->ptbl.v[i];
- VuiAttr a = i&1 ? ODD_ATTR : EVEN_ATTR;
- vui_aprintf(-1, i+1, a, "%u, %u (%s)", p->ofs, p->n, p->buf == TXT_ADD ? "add" : "src");
- }
+ VuiAttr norm = FG_CYAN | BG_BLACK;
+ VuiAttr sel = FG_BLACK | BG_CYAN;
+ VuiAttr txt = FG_WHITE | BG_BLACK;
+ vui_fill(' ', txt);
{
- VuiAttr norm = FG_WHITE | BG_BLACK;
- VuiAttr sel = FG_BLACK | BG_WHITE;
int x = 0;
+ int y = LINES-1;
+ x += vui_aprintf(x, y, norm, " %s ", mode_str[e.mode]);
for (u32 i = 0; i < e.bufn; i++) {
EditBuf *b = &e.buf[i];
VuiAttr a = i == e.bufi ? sel : norm;
- x += vui_aprintf(x, 0, a, " %.*s", (int)b->path.n, b->path.s);
- if (b->type == ED_BUF_FILE && b->txt->dirty) x += vui_putsa(x, 0, "* ", a);
- else vui_chra(x++, 0, ' ', a);
+ x += vui_aprintf(x, y, a, " %.*s", (int)b->path.n, b->path.s);
+ if (b->type == ED_BUF_FILE && b->txt->dirty) x += vui_putsa(x, y, "* ", a);
+ else vui_chra(x++, y, ' ', a);
}
int n = COLS;
- while (x < n) vui_chra(x++, 0, ' ', norm);
+ while (x < n) vui_chra(x++, y, ' ', norm);
}
TxtLoc l = eb->cur;
@@ -429,7 +434,7 @@ void draw(void *ctx) {
x = lmarg;
y++;
} else if (is_space(c)) {
- VuiAttr a = txt_chr(start) == '\n' ? (FG_WHITE | BG_BLUE) : (FG_WHITE | BG_BLACK);
+ VuiAttr a = txt_chr(start) == '\n' ? norm : txt;
if (c == '\t') {
u32 n = 1 + (-(x+1) & 7);
while (n--) vui_chra(x++, y, ' ', a);
@@ -437,7 +442,7 @@ void draw(void *ctx) {
vui_chra(x++, y, ' ', a);
}
} else if (c) {
- vui_chr(x++, y, c);
+ vui_chra(x++, y, c, txt);
}
}
@@ -583,7 +588,6 @@ int read_search(void) {
}
int motion(TxtLoc *lp, u32 c) {
-
TxtLoc l = *lp;
TxtLoc last_loc = l;
for (;;) {
@@ -914,6 +918,7 @@ int main(int argc, const char **argv) {
ed_init(&e);
if (argc > 1) {
+ ed_buf_close(&e, 0); /* close scratch buffer */
for (int i = 1; i < argc; i++) {
Str s = str_from_cstr(argv[i]);
Cut c = str_cut(s, '@');
@@ -928,8 +933,6 @@ int main(int argc, const char **argv) {
eb->cur = txt_at(eb->txt, ofs);
}
}
- } else {
- e.bufi = ed_buf_open(&e, "main.c");
}
vui_init();
@@ -1082,6 +1085,45 @@ int main(int argc, const char **argv) {
break;
}
break;
+
+ case '>': {
+ TxtLoc end = eb->cur;
+ VuiKey k = vui_key();
+ if (k == '>' || motion(&end, k)) {
+ if (k == '>') end = next_line_start(end);
+ u32 ofs = txt_ofs(eb->cur);
+ TxtLoc start = start_of_line(eb->cur);
+ u32 lines = 0;
+ for (TxtLoc t = start; txt_before(t, end); t = next_line_start(t)) lines++;
+ while (lines--) {
+ if (!empty_line(start))
+ start = txt_insert_c(start, '\t');
+ start = next_line_start(start);
+ }
+ eb->cur = txt_at(eb->txt, ofs);
+ }
+ } break;
+ case '<': {
+ TxtLoc end = eb->cur;
+ VuiKey k = vui_key();
+ if (k == '<' || motion(&end, k)) {
+ if (k == '<') end = next_line_start(end);
+ u32 ofs = txt_ofs(eb->cur);
+ TxtLoc start = start_of_line(eb->cur);
+ u32 lines = 0;
+ for (TxtLoc t = start; txt_before(t, end); t = next_line_start(t)) lines++;
+ while (lines--) {
+ if (txt_byte(start) == '\t')
+ start = txt_delete_c(cnext(start));
+ start = next_line_start(start);
+ }
+ eb->cur = txt_at(eb->txt, ofs);
+ }
+ } break;
+ case '=': {
+ Str s = get_input_line(S("File to open: "));
+ if (s.n > 0) e.bufi = ed_buf_open(&e, str_to_cstr(s, &e.scratch));
+ } break;
default:
motion(&eb->cur, c);
break;