void (*del_back)(void *cls);
void (*del_fwd)(void *cls);
void (*status)(char *s, void *cls);
+ void (*flush)(void *cls);
};
/* Create a new instance of the visor editor.
void vi_set_fileops(struct visor *vi, struct vi_fileops *fop);
void vi_set_ttyops(struct visor *vi, struct vi_ttyops *tty);
-void vi_window(struct visor *vi, int xsz, int ysz);
+void vi_term_size(struct visor *vi, int xsz, int ysz);
void vi_redraw(struct visor *vi);
/* vi_new_buf creates a new buffer and inserts it in the buffer list. If the
#define vi_del_back() vi->tty.del_back(vi->tty_cls)
#define vi_del_fwd() vi->tty.del_fwd(vi->tty_cls)
#define vi_status(s) vi->tty.status(s, vi->tty_cls)
+#define vi_flush() vi->tty.flush(vi->tty_cls)
static int remove_buf(struct visor *vi, struct vi_buffer *vb);
static int add_span(struct vi_buffer *vb, vi_addr at, int src, vi_addr start, unsigned long size);
void vi_redraw(struct visor *vi)
{
+ int i, col, cur_x = 0, cur_y = 0;
+ char c;
struct vi_buffer *vb;
- struct vi_span *sp, *spend;
- vi_addr spoffs;
+ struct vi_span *sp, *spans_end;
+ const char *tptr, *tend;
+ vi_addr spoffs, addr;
vb = vi->buflist;
- if(!(sp = vi_buf_find_span(vb, vi->view_start, &spoffs))) {
+ if(!(sp = vi_buf_find_span(vb, vb->view_start, &spoffs))) {
sp = vb->spans;
spoffs = 0;
}
- spend = vb->spans + vb->num_spans;
+ spans_end = vb->spans + vb->num_spans;
+
+ tptr = vi_buf_span_text(vb, sp);
+ tend = tptr + sp->size;
+ tptr += spoffs;
vi_clear();
- for(i=0; i<term_heig
+ addr = vb->view_start;
+ for(i=0; i<vi->term_height; i++) {
+ vi_setcursor(0, i);
+ col = -vb->view_xscroll - 1;
+ while(++col < vi->term_width && (c = (addr++, *tptr++)) != '\n') {
+ if(addr == vb->cursor) {
+ cur_x = col;
+ cur_y = i;
+ }
+
+ if(col >= 0) {
+ vi_putchar(c);
+ }
+ if(tptr >= tend) {
+ if(++sp >= spans_end) {
+ goto end;
+ }
+ tptr = vi_buf_span_text(vb, sp);
+ tend = tptr + sp->size;
+ }
+ }
+ }
+end:
+
+ while(i < vi->term_height) {
+ vi_setcursor(0, i++);
+ vi_putchar('~');
+ }
+
+ vi_setcursor(cur_x, cur_y);
+ vi_flush();
}
struct vi_buffer *vi_new_buf(struct visor *vi, const char *path)
static long file_read(vi_file *file, void *buf, long count);
static long file_write(vi_file *file, void *buf, long count);
static long file_seek(vi_file *file, long offs, int whence);
+/* tty operations */
+static void tty_clear(void *cls);
+static void tty_clear_line(void *cls);
+static void tty_clear_line_at(int y, void *cls);
+static void tty_setcursor(int x, int y, void *cls);
+static void tty_putchar(char c, void *cls);
+static void tty_putchar_at(int x, int y, char c, void *cls);
+static void tty_scroll(int nlines, void *cls);
+static void tty_del_back(void *cls);
+static void tty_del_fwd(void *cls);
+static void tty_status(char *s, void *cls);
+static void tty_flush(void *cls);
+
static struct visor *vi;
file_read, file_write, file_seek
};
-/*
static struct vi_ttyops ttyops = {
tty_clear, tty_clear_line, tty_clear_line_at,
tty_setcursor, tty_putchar, tty_putchar_at,
- tty_scroll, tty_del_back, tty_del_fwd, tty_status
+ tty_scroll, tty_del_back, tty_del_fwd, tty_status, tty_flush
};
-*/
int main(int argc, char **argv)
{
return -1;
}
vi_set_fileops(vi, &fops);
+ vi_set_ttyops(vi, &ttyops);
for(i=0; i<num_fpaths; i++) {
if(!vi_new_buf(vi, fpaths[i])) {
return -1;
}
}
+
+ term_resize_func(resized);
return 0;
}
term_cleanup();
}
+static void resized(int x, int y)
+{
+ vi_term_size(vi, x, y);
+}
+
static vi_file *file_open(const char *path, unsigned int flags)
{
struct file *file;
struct file *file = vif;
return lseek(file->fd, offs, whence);
}
+
+/* tty operations */
+
+static void tty_clear(void *cls)
+{
+ term_clear();
+}
+
+static void tty_clear_line(void *cls)
+{
+ /* TODO */
+}
+
+static void tty_clear_line_at(int y, void *cls)
+{
+ term_setcursor(y, 0);
+ /* TODO */
+}
+
+static void tty_setcursor(int x, int y, void *cls)
+{
+ term_setcursor(y, x);
+}
+
+static void tty_putchar(char c, void *cls)
+{
+ term_putchar(c);
+}
+
+static void tty_putchar_at(int x, int y, char c, void *cls)
+{
+ term_setcursor(y, x);
+ term_putchar(c);
+}
+
+static void tty_scroll(int nlines, void *cls)
+{
+ /* TODO */
+}
+
+static void tty_del_back(void *cls)
+{
+ /* TODO */
+}
+
+static void tty_del_fwd(void *cls)
+{
+ /* TODO */
+}
+
+static void tty_status(char *s, void *cls)
+{
+ /* TODO */
+}
+
+static void tty_flush(void *cls)
+{
+ term_flush();
+}
}
}
+void term_putchar(char c)
+{
+ term_send(&c, 1);
+}
+
void term_puts(const char *s)
{
term_send(s, strlen(s));
term_puts("\033[2J");
}
+void term_cursor(int show)
+{
+ term_printf("\033[?25%c", show ? 'h' : 'l');
+}
+
+void term_setcursor(int row, int col)
+{
+ term_printf("\033[%d;%dH", row + 1, col + 1);
+}
+
int term_getchar(void)
{
int res;
void term_resize_func(void (*func)(int, int));
void term_send(const char *s, int size);
+void term_putchar(char c);
void term_puts(const char *s);
void term_printf(const char *fmt, ...);
void term_flush(void);
void term_clear(void);
+void term_setcursor(int row, int col);
+
int term_getchar(void);
#endif /* TERM_H_ */