diff options
| -rw-r--r-- | main.c | 20 | ||||
| -rw-r--r-- | vui.c | 39 | ||||
| -rw-r--r-- | vui.h | 78 |
3 files changed, 72 insertions, 65 deletions
@@ -393,9 +393,6 @@ int shell_run(const char *cmd) { /* main */ -#define ODD_ATTR (FG_CYAN | BG_BLACK) -#define EVEN_ATTR (FG_WHITE | BG_BLACK) - void find_view_window(TxtLoc l, TxtLoc *start, TxtLoc *end, u32 lines) { u32 u = lines / 2; TxtLoc a = l; @@ -419,9 +416,9 @@ void draw(void *ctx) { TxtLoc start, end; find_view_window(eb->cur, &start, &end, LINES - 1); - VuiAttr norm = FG_CYAN | BG_BLACK; - VuiAttr sel = FG_BLACK | BG_CYAN; - VuiAttr txt = FG_WHITE | BG_BLACK; + VuiAttr norm = A_DEFAULT; + VuiAttr sel = norm | A_REVERSE; + VuiAttr txt = A_DEFAULT; vui_fill(' ', txt); { @@ -1089,6 +1086,15 @@ int main(int argc, const char **argv) { eb->cur = txt_delete_range(start, end); e.mode = 1; } break; + case 'J': { + TxtLoc l = end_of_line(eb->cur); + if (txt_byte(l) == '\n') { + do l = txt_delete_c(cnext(l)); + while (is_space(txt_chr(l))); + l = cprev(txt_insert_c(l, ' ')); + eb->cur = l; + } + } break; case 'c': { TxtLoc before = eb->cur; if (motion(&eb->cur, vui_key())) { @@ -1245,4 +1251,4 @@ int main(int argc, const char **argv) { vui_fini(); arena_free(&e.scratch); return 0; -} +}
\ No newline at end of file @@ -108,7 +108,7 @@ static void vui_clrspan(VuiBuffer *buf, unsigned x0, unsigned x1, unsigned y) { BCHR(buf, x, y) = ' '; } for (unsigned x = x0; x < x1; x++) { - BATTR(buf, x, y) = ATTR_DEFAULT; + BATTR(buf, x, y) = A_DEFAULT; } } @@ -244,7 +244,6 @@ void vui_redraw(void) { void vui_init(void) { /* set white:black to default */ - printf(CSI "40;37m" CSI "8]"); vui_curs_vis(0); vui_enable(); vui_redraw(); @@ -420,10 +419,10 @@ static void attr_chg(VuiAttr *ptr, VuiAttr to) { if (!chg_attr) goto chg_colors; /* deduct color changes */ - attr_chg_count -= (ATTR_FG(to) == ATTR_FG(from)) && (ATTR_FG(to) != ATTR_DEFAULT); - attr_chg_count -= (ATTR_BG(to) == ATTR_BG(from)) && (ATTR_BG(to) != ATTR_DEFAULT); + attr_chg_count -= (ATTR_FG(to) == ATTR_FG(from)) && (ATTR_FG(to) != FG_DEFAULT); + attr_chg_count -= (ATTR_BG(to) == ATTR_BG(from)) && (ATTR_BG(to) != FG_DEFAULT); - int should_rebuild = (attr_chg_count > 1) || to == ATTR_DEFAULT; + int should_rebuild = (attr_chg_count > 1) || to == A_DEFAULT; if (should_rebuild) { vui_outs(CSI "0"); @@ -433,9 +432,7 @@ static void attr_chg(VuiAttr *ptr, VuiAttr to) { if (to & A_UNDERSCORE) vui_outs(";4"); if (to & A_BLINK) vui_outs(";5"); if (to & A_REVERSE) vui_outs(";7"); - from = ATTR_DEFAULT; - assert(ATTR_FG(from) == FG_WHITE); - assert(ATTR_BG(from) == BG_BLACK); + from = A_DEFAULT; } else { int sep = 0; vui_outs(CSI); @@ -472,17 +469,17 @@ chg_colors:; if (chg_attr) vui_outc(';'); else vui_outs(CSI); if (chg_fg) { - vui_outc(t_fg > 7 ? '9' : '3'); - vui_outc((t_fg & 7) + '0'); + vui_outc(t_fg > 9 ? '9' : '3'); + vui_outc((t_fg > 9 ? t_fg - 9 : t_fg) + '0'); } if (chg_bg) { if (chg_fg) vui_outc(';'); - if (t_bg > 7) { + if (t_bg > 9) { vui_outs("10"); } else { vui_outc('4'); } - vui_outc((t_bg & 7) + '0'); + vui_outc((t_bg > 9 ? t_bg - 9 : t_bg) + '0'); } } @@ -492,19 +489,19 @@ chg_colors:; void vui_scroll_buf(VuiBuffer *b, int dx, int dy); -static VuiAttr attr_last = ATTR_DEFAULT; +static VuiAttr attr_last = A_DEFAULT; static unsigned cur_x = 0; static unsigned cur_y = 0; static void emit_scroll_x(u32 y) { if (win.scroll_x < 0) { /* delete chars at start of line */ - attr_chg(&attr_last, ATTR_DEFAULT); + attr_chg(&attr_last, A_DEFAULT); curs_move(&cur_x, &cur_y, 0, y); vui_outf(CSI "%dP", -win.scroll_x); } else if (win.scroll_x > 0) { /* insert spaces at start of line */ - attr_chg(&attr_last, ATTR_DEFAULT); + attr_chg(&attr_last, A_DEFAULT); curs_move(&cur_x, &cur_y, 0, y); vui_outf(CSI "%d@", win.scroll_x); } @@ -516,13 +513,13 @@ static void emit_scroll_y(void) { if (win.scroll_y < 0) { /* delete lines at top */ curs_move(&cur_x, &cur_y, 0, 0); - attr_chg(&attr_last, ATTR_DEFAULT); + attr_chg(&attr_last, A_DEFAULT); if (win.scroll_y == -1) vui_outs(CSI "M"); else vui_outf(CSI "%dM", -win.scroll_y); } else if (win.scroll_y > 0) { /* insert blank lines at top */ curs_move(&cur_x, &cur_y, 0, 0); - attr_chg(&attr_last, ATTR_DEFAULT); + attr_chg(&attr_last, A_DEFAULT); if (win.scroll_y == 1) vui_outs(CSI "L"); else vui_outf(CSI "%dL", win.scroll_y); } @@ -534,7 +531,7 @@ void vui_blit(void) { if (win.redraw_all) { vui_outs(CSI "H" CSI "2J" CSI "0m"); - attr_last = ATTR_DEFAULT; + attr_last = A_DEFAULT; unsigned max = COLS * LINES; for (unsigned i = 0; i < max; i++) { attr_chg(&attr_last, front->attr[i]); @@ -593,7 +590,7 @@ void vui_chra(int x, int y, VuiChar c, VuiAttr a) { } void vui_chr(int x, int y, VuiChar c) { - vui_chra(x, y, c, ATTR_DEFAULT); + vui_chra(x, y, c, A_DEFAULT); } static void truncate_span(int *x, unsigned *nptr) { @@ -628,7 +625,7 @@ u32 vui_putsna(int x, int y, const char *s, unsigned srcn, VuiAttr a) { } u32 vui_putsn(int x, int y, const char *s, unsigned n) { - return vui_putsna(x, y, s, n, ATTR_DEFAULT); + return vui_putsna(x, y, s, n, A_DEFAULT); } u32 vui_putsa(int x, int y, const char *s, VuiAttr a) { @@ -666,7 +663,7 @@ int vui_aprintf(int x, int y, VuiAttr a, const char *fmt, ...) { int vui_printf(int x, int y, const char *fmt, ...) { va_list ap; va_start(ap, fmt); - int r = vui_avprintf(x, y, ATTR_DEFAULT, fmt, ap); + int r = vui_avprintf(x, y, A_DEFAULT, fmt, ap); va_end(ap); return r; } @@ -38,42 +38,47 @@ typedef enum { FG_MAGENTA = 5, FG_CYAN = 6, FG_WHITE = 7, - - FG_BBLACK = FG_BLACK + 8, - FG_BRED = FG_RED + 8, - FG_BGREEN = FG_GREEN + 8, - FG_BYELLOW = FG_YELLOW + 8, - FG_BBLUE = FG_BLUE + 8, - FG_BMAGENTA = FG_MAGENTA + 8, - FG_BCYAN = FG_CYAN + 8, - FG_BWHITE = FG_WHITE + 8, - - BG_BLACK = FG_BLACK << 4, - BG_RED = FG_RED << 4, - BG_GREEN = FG_GREEN << 4, - BG_YELLOW = FG_YELLOW << 4, - BG_BLUE = FG_BLUE << 4, - BG_MAGENTA = FG_MAGENTA << 4, - BG_CYAN = FG_CYAN << 4, - BG_WHITE = FG_WHITE << 4, - - BG_BBLACK = FG_BBLACK << 4, - BG_BRED = FG_BRED << 4, - BG_BGREEN = FG_BGREEN << 4, - BG_BYELLOW = FG_BYELLOW << 4, - BG_BBLUE = FG_BBLUE << 4, - BG_BMAGENTA = FG_BMAGENTA << 4, - BG_BCYAN = FG_BCYAN << 4, - BG_BWHITE = FG_BWHITE << 4, - - A_BOLD = 1 << 8, - A_DIM = 1 << 9, - A_ITALIC = 1 << 10, - A_UNDERSCORE = 1 << 11, - A_BLINK = 1 << 12, - A_REVERSE = 1 << 13, + FG_DEFAULT = 9, + + FG_BBLACK = FG_BLACK + 9, + FG_BRED = FG_RED + 9, + FG_BGREEN = FG_GREEN + 9, + FG_BYELLOW = FG_YELLOW + 9, + FG_BBLUE = FG_BLUE + 9, + FG_BMAGENTA = FG_MAGENTA + 9, + FG_BCYAN = FG_CYAN + 9, + FG_BWHITE = FG_WHITE + 9, + + BG_BLACK = FG_BLACK << 5, + BG_RED = FG_RED << 5, + BG_GREEN = FG_GREEN << 5, + BG_YELLOW = FG_YELLOW << 5, + BG_BLUE = FG_BLUE << 5, + BG_MAGENTA = FG_MAGENTA << 5, + BG_CYAN = FG_CYAN << 5, + BG_WHITE = FG_WHITE << 5, + + BG_DEFAULT = FG_DEFAULT << 5, + + BG_BBLACK = FG_BBLACK << 5, + BG_BRED = FG_BRED << 5, + BG_BGREEN = FG_BGREEN << 5, + BG_BYELLOW = FG_BYELLOW << 5, + BG_BBLUE = FG_BBLUE << 5, + BG_BMAGENTA = FG_BMAGENTA << 5, + BG_BCYAN = FG_BCYAN << 5, + BG_BWHITE = FG_BWHITE << 5, + + A_BOLD = 1 << 9, + A_DIM = 1 << 10, + A_ITALIC = 1 << 11, + A_UNDERSCORE = 1 << 12, + A_BLINK = 1 << 13, + A_REVERSE = 1 << 14, } VuiAttr; +#define A_DEFAULT (FG_DEFAULT | BG_DEFAULT) + typedef enum { VUI_CURS_BLOCK_BLINK, VUI_CURS_DEFAULT, @@ -84,10 +89,9 @@ typedef enum { VUI_CURS_BAR, } VuiCursorShape; -#define ATTR_FG(a) ((a) & 0xf) -#define ATTR_BG(a) (((a)>>4) & 0xf) +#define ATTR_FG(a) ((a) & 0x1f) +#define ATTR_BG(a) (((a)>>5) & 0x1f) #define ATTR_A(a) ((a) & ~0xff) -#define ATTR_DEFAULT (FG_WHITE | BG_BLACK) typedef uint32_t VuiChar; |
