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;
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);
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); */
}
static int y, x;
+#define saveyx() getyx(stdscr, y,x)
+#define restoreyx() move(y, x)
+
void init_windows(void)
{
initscr();
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();
}
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)
buf->x = 0;
if (buf->y < LINES)
buf->y++;
+
+ /* FIXME: scroll the screen if possible */
}
void screen_move_left(struct te_buffer *buf)
insert_char(buf, c);
bstring s = current_line_as_bstring(buf->contents, buf->point);
+ miniprintf("%s", bstr2cstr(s, '\0'));
draw_line(s, buf->y);
void statusprintf(char *fmt, ...)
{
- getyx(stdscr, y, x);
+ saveyx();
werase(status_win);
wmove(status_win, 0, 0);
wrefresh(status_win);
- move(y, x);
+ restoreyx();
+
}
void console_signal_handler(int sig)
{
switch(sig) {
- case SIGWINCH:
- default:
- refresh();
- break;
-
+ case SIGWINCH:
+ default:
+ refresh();
+ break;
}
}
#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