From 8f0b000da1a82653727cd87b5cdd600fc80e4c99 Mon Sep 17 00:00:00 2001 From: khamidou Date: Tue, 23 Jun 2009 22:23:31 +0200 Subject: [PATCH] still trying to nail this display bug... --- buffer.c | 2 +- buffer.h | 6 +----- keyb.c | 16 +++++++--------- screen.c | 44 ++++++++++++++++++++++++++++---------------- util.h | 1 + 5 files changed, 38 insertions(+), 31 deletions(-) diff --git a/buffer.c b/buffer.c index 387055d..088865a 100644 --- a/buffer.c +++ b/buffer.c @@ -79,7 +79,7 @@ int line_length(bstring b, int point) bstring current_line_as_bstring(bstring b, int point) { - int s_offset = bstrrchrp(b, '\n', point - 1); + int s_offset = bstrrchrp(b, '\n', max(point - 1, 0)); if (s_offset == BSTR_ERR) s_offset = 0; diff --git a/buffer.h b/buffer.h index 85aa93f..70a59a3 100644 --- a/buffer.h +++ b/buffer.h @@ -14,20 +14,16 @@ struct te_buffer { int lineno; /* the number of '\n' seen so far */ bstring contents; int point; /* offset in "contents" */ - struct te_char *scr_top, *scr_bottom; /* the first and last char of the screen */ + int top_char, bottom_char; /* the char at the top and at the bottom of the screen */ PyObject *pyBuffer; /* pointer to the buffer object */ - TAILQ_HEAD(te_chars_head, te_char) chars_head; TAILQ_ENTRY(te_buffer) buffers; }; TAILQ_HEAD(te_buffers_head, te_buffer) buffers_head; -struct te_char *alloc_and_insert_char(struct te_buffer *buf, char contents); struct te_buffer *alloc_and_insert_buffer(void); -struct te_char *nth_char(struct te_char *c, int n); -void free_char(struct te_buffer *b, struct te_char *c); void free_buffer(struct te_buffer *b); struct te_buffer* load_buffer(char *filename); diff --git a/keyb.c b/keyb.c index ae20df4..82900eb 100644 --- a/keyb.c +++ b/keyb.c @@ -9,33 +9,31 @@ void input_loop(void) case 'q': exit(0); - case 'k': case KEY_LEFT: screen_move_left(current_buf); break; - case 'l': case KEY_RIGHT: screen_move_right(current_buf); break; - case 'd': case KEY_DOWN: screen_move_down(current_buf); break; - case 'v': - screen_insert_char(current_buf, 'X'); + default: + screen_insert_char(current_buf, c); paint_buffer(current_buf); + refresh(); break; } refresh(); - miniprintf("%c, line length: %d, y: %d, x%d", - (bchar(current_buf->contents, current_buf->point) == '\n') ? 'N' : bchar(current_buf->contents, current_buf->point), - screen_line_length(current_buf->contents, current_buf->point), - current_buf->y, current_buf->x); +/* miniprintf("%c, line length: %d, y: %d, x%d", */ +/* (bchar(current_buf->contents, current_buf->point) == '\n') ? 'N' : bchar(current_buf->contents, current_buf->point), */ +/* screen_line_length(current_buf->contents, current_buf->point), */ +/* current_buf->y, current_buf->x); */ } diff --git a/screen.c b/screen.c index f172a56..9885f7a 100644 --- a/screen.c +++ b/screen.c @@ -3,6 +3,9 @@ static int y, x; +#define saveyx() getyx(stdscr, y,x) +#define restoreyx() move(y, x) + void init_windows(void) { initscr(); @@ -35,19 +38,23 @@ void paint_buffer(struct te_buffer *buf) if (buf == NULL) return; + saveyx(); wmove(buffer_win, 0, 0); bstring s; int i = 0; - int pos = 0; + int count = 0; for(i = 0; i < (LINES - 3); i++) { - s = current_line_as_bstring(buf->contents, pos); + s = current_line_as_bstring(buf->contents, count); draw_line(s, i); - pos += line_length(s, pos); + count += blength(s); + + if (count >= blength(buf->contents)) + break; } - wmove(buffer_win, 0, 0); + restoreyx(); refresh(); } @@ -57,11 +64,13 @@ void draw_line(bstring s, int y) int j; /* FIXME : wrap line if we go beyond COLS */ for (i = 0; i < blength(s); i++) - if (bchar(s, i) == '\t') - for (j = 0; j < TAB_LEN; j++) - mvwaddch(buffer_win, y, i, ' '); - else - mvwaddch(buffer_win, y, i, bchar(s, i)); + /* if (bchar(s, i) == '\t') */ +/* for (j = 0; j < TAB_LEN; j++) */ +/* mvwaddch(buffer_win, y, j, ' '); */ +/* else */ +// mvwaddch(buffer_win, y, i, bchar(s, i)); + waddch(buffer_win, bchar(s, i)); + } void scroll_up(struct te_buffer *buf) @@ -93,6 +102,8 @@ void screen_next_line(struct te_buffer *buf) buf->x = 0; if (buf->y < LINES) buf->y++; + + /* FIXME: scroll the screen if possible */ } void screen_move_left(struct te_buffer *buf) @@ -191,6 +202,7 @@ void screen_insert_char(struct te_buffer *buf, char c) insert_char(buf, c); bstring s = current_line_as_bstring(buf->contents, buf->point); + miniprintf("%s", bstr2cstr(s, '\0')); draw_line(s, buf->y); @@ -202,7 +214,7 @@ void screen_insert_char(struct te_buffer *buf, char c) void statusprintf(char *fmt, ...) { - getyx(stdscr, y, x); + saveyx(); werase(status_win); wmove(status_win, 0, 0); @@ -225,7 +237,8 @@ void statusprintf(char *fmt, ...) wrefresh(status_win); - move(y, x); + restoreyx(); + } @@ -247,11 +260,10 @@ void miniprintf(char *fmt, ...) void console_signal_handler(int sig) { switch(sig) { - case SIGWINCH: - default: - refresh(); - break; - + case SIGWINCH: + default: + refresh(); + break; } } diff --git a/util.h b/util.h index 0f16877..f80b65c 100644 --- a/util.h +++ b/util.h @@ -4,4 +4,5 @@ #define decrement_or_nullify(x) (x = (x > 0) ? x - 1 : 0) #define increment_or_maximize(x, max) (x = (x > max) ? x + 1 : max) +#define max(a, b) (a > b) ? a : b #endif -- 2.43.0