-Te, a text editor
+Te, a textawq editor
=================
-
-This is the readme for te, a small text editor that tries to bring some innovation into a field
-that has been left still since the 70's. The Great Rock'n roll swindle !
\ No newline at end of file
+This is the readme for te, a small text editor thatsqs tries to bring some innovation into a field
+that has been left still since the 70's. I'm not really proud of it but it works.The Great Rock'n roll swindle !
\ No newline at end of file
bstring current_line_as_bstring(bstring b, int point)
{
- if (point > blength(b) - 1)
- point = blength(b) - 1;
+ if (point > blength(b))
+ point = blength(b);
int s_offset = bstrrchrp(b, '\n', max(point, 0));
if (s_offset == BSTR_ERR)
s_offset = 0;
- int e_offset = bstrchrp(b, '\n', point + 1);
+ int e_offset = bstrchrp(b, '\n', max(point + 1, 0));
if (e_offset == BSTR_ERR) {
e_offset = blength(b);
}
if (s_offset == 0) /* the first line of the file */
- return bmidstr(b, s_offset, e_offset - s_offset);
- else if (e_offset == blength(b)) {
- return bmidstr(b, s_offset + 1, e_offset + 1 - s_offset);
+ return bmidstr(b, 0, e_offset);
+/* else if (e_offset == blength(b)) { */
+
+/* return bmidstr(b, s_offset + 1, e_offset + 1 - s_offset); */
+
+/* } */
+ else { /* otherwise, skip the first '\n' character */
+ bstring s1 = bmidstr(b, s_offset + 1, e_offset - s_offset);
+ return s1;
}
- else /* otherwise, skip the first '\n' character */
- return bmidstr(b, s_offset + 1, e_offset - s_offset);
}
/*
free(c);
}
+/*
+ Is the point in the last line ?
+*/
+int is_last_line(bstring s, int point)
+{
+ if (bstrchrp(s, '\n', max(point, 0)) == BSTR_ERR)
+ return TRUE;
+ else
+ return FALSE;
+}
int move_left(struct te_buffer *buf);
void insert_char(struct te_buffer *buf, char c);
void delete_char(struct te_buffer *buf);
+int is_last_line(bstring s, int point);
#endif
bstring s;
int i = 0;
- int count = buf->top_char;
+ int count = max(buf->top_char - 1, 0);
for(i = 0; i < nlines; i++) {
s = current_line_as_bstring(buf->contents, count);
draw_line(s, i);
- count += blength(s) + 1;
-
+ count += blength(s);
bdestroy(s);
- if (count >= blength(buf->contents))
+
+ if (is_last_line(buf->contents, count) == TRUE)
break;
}
- miniprintf("count %d", count);
restoreyx();
refresh();
if (bchar(s, i) == '\t') {
for (j = 0; j < TAB_LEN; j++)
mvwaddch(buffer_win, y, screen_abs++, ' ');
- }
-/* else if (bchar(s, i) == '\n') { */
-/* mvwaddstr(buffer_win, y, screen_abs++, "\\n"); */
-/* screen_abs++; */
-/* mvwaddch(buffer_win, y, screen_abs++, '\n'); */
- /* } */
- else if (i == COLS - 1) {
+ } else if (i == COLS - 1) {
mvwaddch(buffer_win, y, screen_abs, '\\');
screen_next_line(current_buf);
} else {