]> khamidou — GitHub mirrors - te.git/commitdiff
still trying to nail this display bug...
authorkhamidou <karim@lambda-expr.org>
Tue, 23 Jun 2009 20:23:31 +0000 (22:23 +0200)
committerkhamidou <karim@lambda-expr.org>
Tue, 23 Jun 2009 20:23:31 +0000 (22:23 +0200)
buffer.c
buffer.h
keyb.c
screen.c
util.h

index 387055d054fde75bc8b568d32ace17f2974f6a4e..088865a3550873fdaabb8dde31c1becb826dabe2 100644 (file)
--- 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;
 
index 85aa93f55ec335a29b7babfc8695b4bad12ca06f..70a59a3736bbbe46bc5a578675b8f01213e51bce 100644 (file)
--- 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 ae20df4ee7b8069db151ba7318deb14f8f0c112f..82900eb0a0dda7e353faf8f5e2699bf259dda1fd 100644 (file)
--- 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); */
 
        }
 
index f172a56937473599175d97029ebe591649703b6d..9885f7a2f38ac1c92bd1d81badf47822b0045cfc 100644 (file)
--- 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 0f1687765f557ec5b75e97a879b06229a5384182..f80b65c811ce8e91bb98f43be8c679d67af6b2b4 100644 (file)
--- 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