From 4be3c937e35ba127ebf42d5ecd421cdc06afac82 Mon Sep 17 00:00:00 2001 From: khamidou Date: Thu, 25 Jun 2009 10:05:23 +0200 Subject: [PATCH] fixed this horrible display bug at last --- buffer.c | 9 ++++++--- keyb.c | 5 ++--- screen.c | 25 ++++++++++++++----------- 3 files changed, 22 insertions(+), 17 deletions(-) diff --git a/buffer.c b/buffer.c index 088865a..f2e7418 100644 --- a/buffer.c +++ b/buffer.c @@ -79,15 +79,18 @@ int line_length(bstring b, int point) bstring current_line_as_bstring(bstring b, int point) { - int s_offset = bstrrchrp(b, '\n', max(point - 1, 0)); + int s_offset = bstrrchrp(b, '\n', max(point, 0)); if (s_offset == BSTR_ERR) s_offset = 0; - int e_offset = bstrchrp(b, '\n', point); + int e_offset = bstrchrp(b, '\n', point + 1); if (e_offset == BSTR_ERR) e_offset = blength(b); - return bmidstr(b, s_offset, e_offset - s_offset); + if (s_offset > 0) + return bmidstr(b, s_offset + 1, e_offset - s_offset); + else + return bmidstr(b, s_offset, e_offset - s_offset); } /* diff --git a/keyb.c b/keyb.c index 82900eb..df14d38 100644 --- a/keyb.c +++ b/keyb.c @@ -23,15 +23,14 @@ void input_loop(void) 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), */ +/* 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 9885f7a..a03bed5 100644 --- a/screen.c +++ b/screen.c @@ -1,10 +1,10 @@ #include "screen.h" -static int y, x; +static int scr_y, scr_x; -#define saveyx() getyx(stdscr, y,x) -#define restoreyx() move(y, x) +#define saveyx() getyx(stdscr, scr_y, scr_x) +#define restoreyx() move(scr_y, scr_x) void init_windows(void) { @@ -62,15 +62,19 @@ void draw_line(bstring s, int y) { int i; int j; + saveyx(); + move(y, 0); + clrtoeol(); + /* FIXME : wrap line if we go beyond COLS */ for (i = 0; i < blength(s); i++) - /* if (bchar(s, i) == '\t') */ +/* if (bchar(s, i) == '\t') */ /* for (j = 0; j < TAB_LEN; j++) */ -/* mvwaddch(buffer_win, y, j, ' '); */ +/* mvwaddch(buffer_win, y, i++, ' '); */ /* else */ -// mvwaddch(buffer_win, y, i, bchar(s, i)); - waddch(buffer_win, bchar(s, i)); + mvwaddch(buffer_win, y, i, bchar(s, i)); + restoreyx(); } void scroll_up(struct te_buffer *buf) @@ -198,13 +202,12 @@ void screen_insert_char(struct te_buffer *buf, char c) if (buf == NULL) return; - statusprintf("buf x : %d, y : %d", buf->x, buf->y); insert_char(buf, c); bstring s = current_line_as_bstring(buf->contents, buf->point); miniprintf("%s", bstr2cstr(s, '\0')); draw_line(s, buf->y); - + screen_move_right(buf); } @@ -244,7 +247,7 @@ void statusprintf(char *fmt, ...) void miniprintf(char *fmt, ...) { - getyx(stdscr, y, x); + saveyx(); va_list ap; va_start(ap, fmt); @@ -254,7 +257,7 @@ void miniprintf(char *fmt, ...) wrefresh(minibuffer_win); - move(y, x); + restoreyx(); } void console_signal_handler(int sig) -- 2.43.0