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)
free(b);
}
-
struct te_buffer* load_buffer(char *filename)
{
FILE *fp = fopen(filename, "r");
}
/* Compute the length of a string between two '\n' */
-
int line_length(bstring b, int point)
{
if (b == NULL)
for (i = 0; i < len; i++) {
if (bchar(b, point - i) == '\t')
- count += 8;
+ count += TAB_LEN;
else
count += 1;
}
}
+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)
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;
/* 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++;