From: khamidou Date: Sun, 17 May 2009 20:25:43 +0000 (+0200) Subject: still modifying the cursor movement code X-Git-Url: http://git.khamidou.com/?a=commitdiff_plain;h=aa102f66583c09bf1039d50d72b2ae49570e6be5;p=te.git still modifying the cursor movement code --- diff --git a/buffer.c b/buffer.c index 3e8241f..76b9fcd 100644 --- a/buffer.c +++ b/buffer.c @@ -26,14 +26,6 @@ struct te_buffer *alloc_and_insert_buffer(void) return b; } -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) { if (b == NULL) @@ -44,7 +36,6 @@ void free_buffer(struct te_buffer *b) free(b); } - struct te_buffer* load_buffer(char *filename) { FILE *fp = fopen(filename, "r"); @@ -67,7 +58,6 @@ struct te_buffer* load_buffer(char *filename) } /* Compute the length of a string between two '\n' */ - int line_length(bstring b, int point) { if (b == NULL) @@ -98,7 +88,7 @@ int screen_line_length(bstring b, int point) for (i = 0; i < len; i++) { if (bchar(b, point - i) == '\t') - count += 8; + count += TAB_LEN; else count += 1; } diff --git a/keyb.c b/keyb.c index 7ec0df3..13a741f 100644 --- a/keyb.c +++ b/keyb.c @@ -10,10 +10,12 @@ void input_loop(void) exit(0); case 'k': + case KEY_LEFT: move_left(current_buf); break; case 'l': + case KEY_RIGHT: move_right(current_buf); break; } diff --git a/screen.c b/screen.c index aac2adf..3606918 100644 --- a/screen.c +++ b/screen.c @@ -55,24 +55,55 @@ void scroll_down(struct te_buffer *buf) } +void screen_prev_line(struct te_buffer *buf) +{ + if (buf == NULL) + return; + + buf->x = 0; + if (buf->y > 0) + buf->y--; +} + +void screen_next_line(struct te_buffer *buf) +{ + if (buf == NULL) + return; + + buf->x = 0; + if (buf->y < LINES) + buf->y++; +} + void move_left(struct te_buffer *buf) { if (buf == NULL) return; + if (bchar(buf->contents, buf->point) == '\n') { + screen_prev_line(buf); + prev_char(buf); + return; + } + + if(prev_char(buf) == ERR) + return; + if (buf->x > 0) if (bchar(buf->contents, buf->point) == '\t') buf->x -= TAB_LEN; - else + else { buf->x--; + } else if (buf->y > 0) { buf->y--; buf->x = screen_line_length(buf->contents, buf->point); } - prev_char(buf); move(buf->y, buf->x); + refresh(); + miniprintf("%c, y: %d, x%d", bchar(buf->contents, buf->point), buf->y, buf->x); } void move_right(struct te_buffer *buf) @@ -80,6 +111,12 @@ void move_right(struct te_buffer *buf) if (buf == NULL) return; + if (bchar(buf->contents, buf->point) == '\n') { + screen_next_line(buf); + next_char(buf); + return; + } + if (next_char(buf) == ERR) /* last char of the document */ return; @@ -87,8 +124,9 @@ void move_right(struct te_buffer *buf) /* tab is the only character larger than 1 */ if (bchar(buf->contents, buf->point) == '\t') buf->x += TAB_LEN; - else + else { buf->x++; + } } else if (buf->y < LINES - 3) { buf->y++;