X-Git-Url: http://git.mutantstargoat.com/user/nuclear/?p=visor;a=blobdiff_plain;f=libvisor%2Finclude%2Fvisor.h;h=c17e7d8af9f3cdf6494b4a65c36ddde7954e1ee6;hp=2846218eb4368a53fd9015b9a6bcec51379b8ae5;hb=HEAD;hpb=9f0326a07930f909b44433f5d0e3b556d0b16a51 diff --git a/libvisor/include/visor.h b/libvisor/include/visor.h index 2846218..c17e7d8 100644 --- a/libvisor/include/visor.h +++ b/libvisor/include/visor.h @@ -1,5 +1,5 @@ /* -This file is part of the visor text editor and text editor framework +visor - lightweight system-independent text editor and framework Copyright (C) 2019 John Tsiombikas This program is free software: you can redistribute it and/or modify @@ -26,8 +26,9 @@ struct visor; struct vi_buffer; struct vi_span { - vi_addr beg; + vi_addr start; unsigned long size; + int src; }; enum vi_motdir { @@ -68,10 +69,16 @@ struct vi_alloc { void *(*realloc)(void*, unsigned long); /* can be null, will use malloc/free */ }; +/* open flags (same as POSIX O_*) */ +enum { VI_RDONLY, VI_WRONLY, VI_RDWR, VI_CREAT = 0x100 }; +/* seek origin (same as C SEEK_*) */ +enum { VI_SEEK_SET, VI_SEEK_CUR, VI_SEEK_END }; + + struct vi_fileops { - vi_file *(*open)(const char *path); - long (*size)(vi_file *file); + vi_file *(*open)(const char *path, unsigned int flags); void (*close)(vi_file *file); + long (*size)(vi_file *file); void *(*map)(vi_file *file); void (*unmap)(vi_file *file); long (*read)(vi_file *file, void *buf, long count); @@ -90,6 +97,7 @@ struct vi_ttyops { 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. @@ -104,6 +112,9 @@ void vi_destroy(struct visor *vi); void vi_set_fileops(struct visor *vi, struct vi_fileops *fop); void vi_set_ttyops(struct visor *vi, struct vi_ttyops *tty); +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 * path pointer is null, the new buffer will be empty, otherwise it's as if it * was followed by a vi_buf_read call to read a file into the buffer. @@ -135,6 +146,13 @@ int vi_buf_read(struct vi_buffer *vb, const char *path); int vi_buf_write(struct vi_buffer *vb, const char *path); long vi_buf_size(struct vi_buffer *vb); +/* find the span which corresponds to the specified text position + * if soffs is not null, the relative offset of the specified address from the + * start of the span is stored there. + */ +struct vi_span *vi_buf_find_span(struct vi_buffer *vb, vi_addr at, vi_addr *soffs); +const char *vi_buf_span_text(struct vi_buffer *vb, struct vi_span *span); + void vi_buf_ins_begin(struct vi_buffer *vb, vi_motion mot); void vi_buf_insert(struct vi_buffer *vb, char *s); void vi_buf_ins_end(struct vi_buffer *vb); @@ -142,4 +160,8 @@ void vi_buf_ins_end(struct vi_buffer *vb); void vi_buf_del(struct vi_buffer *vb, vi_motion mot); void vi_buf_yank(struct vi_buffer *vb, vi_motion mot); + +/* high level user input handling */ +void vi_keypress(struct visor *vi, int key); + #endif /* LIB_VISOR_TEXTED_CORE_H_ */