summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--main.c66
1 files changed, 45 insertions, 21 deletions
diff --git a/main.c b/main.c
index 2ab4eba..f4d4ac4 100644
--- a/main.c
+++ b/main.c
@@ -247,8 +247,10 @@ void vui_on_sigwinch(int _) {
void vui_init(void) {
tcgetattr(STDIN_FILENO, &vui_init_stdin_tos);
vui_raw_stdin_tos = vui_init_stdin_tos;
- //vui_raw_stdin_tos.c_lflag &= ~(ECHO | ECHONL | ICANON | IEXTEN | ISIG);
- //vui_raw_stdin_tos.c_lflag |= IGNBRK;
+ /*
+ vui_raw_stdin_tos.c_lflag &= ~(ECHO | ECHONL | ICANON | IEXTEN | ISIG);
+ vui_raw_stdin_tos.c_lflag |= IGNBRK;
+ */
vui_raw_stdin_tos.c_iflag &= ~(IGNBRK | BRKINT | PARMRK | ISTRIP | INLCR | IGNCR | ICRNL | IXON);
vui_raw_stdin_tos.c_oflag &= ~OPOST;
@@ -291,15 +293,15 @@ static size_t vui_outn = 0;
static size_t vui_out_cap = 0;
void vui_fini(void) {
- tcsetattr(STDIN_FILENO, TCSANOW, &vui_init_stdin_tos);
- tcsetattr(STDOUT_FILENO, TCSANOW, &vui_init_stdout_tos);
vui_curs_vis(1);
free_buf(&vui_win.buf1);
free_buf(&vui_win.buf2);
free(vui_out);
vui_out = NULL;
vui_out_cap = 0;
- // printf(CSI "H" CSI "2J" CSI "0m");
+ printf(CSI "0m" CSI "H" CSI "2J");
+ tcsetattr(STDIN_FILENO, TCSANOW, &vui_init_stdin_tos);
+ tcsetattr(STDOUT_FILENO, TCSANOW, &vui_init_stdout_tos);
}
void vui_out_fit(size_t n) {
@@ -683,6 +685,7 @@ static inline u32 utf8_next(u32 *p, const char *s, u32 n) {
*p = i;
return c;
}
+ ASSUME(bits < 5);
u32 cp = c & ((1 << (7-bits)) - 1);
while (--bits) {
c = s[i++];
@@ -692,24 +695,26 @@ 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;) {
+unsigned vui_putsna(int x, int y, const char *s, unsigned n, VuiAttr a) {
+ if (n > COLS - x) n = COLS - x;
+ VuiChar *pc = &CHR(x, y);
+ for (unsigned i = 0; i < n;) {
u32 c = utf8_next(&i, s, n);
- CHR(x, y) = c;
- ATTR(x, y) = a;
- x++;
+ *pc++ = c;
}
+ for (uint16_t *pa = &ATTR(x, y); n--;) *pa++ = a;
+ return n;
}
-void vui_putsn(int x, int y, const char *s, unsigned n) {
+unsigned 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) {
+unsigned 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) {
+unsigned vui_puts(int x, int y, const char *s) {
return vui_putsn(x, y, s, strlen(s));
}
@@ -946,10 +951,10 @@ int main(int argc, const char **argv) {
return 0;
*/
- vui_curs_vis(1);
+ vui_curs_vis(0);
vui_win.redraw_fn = draw;
- int x = 10, y = 0;
+ int x = 0, y = 0;
int scroll_x = 0, scroll_y = 0;
for (;;) {
static int last_left = 0;
@@ -958,8 +963,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);
+ //vui_fill(' ', FG_WHITE | BG_BLUE);
+ //vui_fill_rect(' ', FG_BLACK | BG_BLACK, left + 2, top + 1, right - left, bottom - top);
+ //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; }
@@ -968,6 +974,7 @@ int main(int argc, const char **argv) {
last_left = left;
int sdx = scroll_x > 0 ? 1 : (scroll_x < 0 ? -1 : 0);
+ sdx = scroll_x;
int sdy = scroll_y > 0 ? 1 : (scroll_y < 0 ? -1 : 0);
vui_scroll(sdx, sdy);
x += sdx;
@@ -975,21 +982,38 @@ int main(int argc, const char **argv) {
scroll_x -= sdx;
scroll_y -= sdy;
- vui_curs_pos(x, y);
+ for (unsigned y = 0; y < LINES; y++) {
+ for (unsigned x = 0; x < COLS; x++) {
+ if (ATTR(x, y) == ATTR_DEFAULT || ATTR_FG(ATTR(x, y)) == ATTR_BG(ATTR(x, y)) ) {
+ int sx = x + scroll_x;
+ int sy = y + scroll_y;
+ int okx = sx >= left - 5 && sx <= right + 5;
+ int oky = sy >= top - 2 && sy <= bottom + 2;
+ if (okx && oky) {
+ ATTR(x, y) = FG_WHITE | BG_WHITE;
+ } else if (oky && sx == right + 6 || okx && sy == bottom + 3 || sx == right + 6 && sy == bottom + 3) {
+ ATTR(x, y) = FG_BLACK | BG_BLACK;
+ } else {
+ ATTR(x, y) = FG_BLUE | BG_BLUE;
+ }
+ }
+ }
+ }
+
+ vui_chra(x, y, '_', FG_BLUE | BG_WHITE);
draw(NULL);
int animating = !!scroll_x || !!scroll_y;
- if (animating && !wait_for_input(STDIN_FILENO, 33)) continue;
+ if (animating && !wait_for_input(STDIN_FILENO, 15)) continue;
VuiKey c = vui_key();
if (c == KEY_INVALID || c == KEY_ESC) goto done;
static unsigned i = 0;
- int x1 = x;
i++;
if (c > 0x1f && c < KEY_UTF8_MAX && x < right) {
vui_chra(x++, y, c, FG_BLACK | BG_WHITE);
} else if (c == KEY_RET) {
x = left;
- y++;
+ y += 2;
}
/*