1 #ifndef __TEXTBUFFER_VIEW_H 2 #define __TEXTBUFFER_VIEW_H 3 4 #include "textbuffer.h" 5 #include "term.h" 6 7 typedef struct _TEXT_BUFFER_VIEW_REC TEXT_BUFFER_VIEW_REC; 8 9 /* if ypos == -1, don't print anything, just return the indent size */ 10 typedef int (*INDENT_FUNC) (TEXT_BUFFER_VIEW_REC *view, 11 LINE_REC *line, int ypos); 12 13 typedef struct { 14 const unsigned char *start; 15 int indent; 16 INDENT_FUNC indent_func; 17 int color; 18 #ifdef TERM_TRUECOLOR 19 unsigned int fg24, bg24; 20 #endif 21 22 /* first word in line belong to the end of the last word in 23 previous line */ 24 unsigned int continues:1; 25 } LINE_CACHE_SUB_REC; 26 27 typedef struct { 28 time_t last_access; 29 30 int count; /* number of real lines */ 31 32 /* variable sized array, actually. starts from the second line, 33 so size of it is count-1 */ 34 LINE_CACHE_SUB_REC lines[1]; 35 } LINE_CACHE_REC; 36 37 typedef struct { 38 int refcount; 39 int width; 40 41 GHashTable *line_cache; 42 43 /* should contain the same value for each cache that uses the 44 same buffer */ 45 unsigned char update_counter; 46 /* number of real lines used by the last line in buffer */ 47 int last_linecount; 48 } TEXT_BUFFER_CACHE_REC; 49 50 struct _TEXT_BUFFER_VIEW_REC { 51 TEXT_BUFFER_REC *buffer; 52 /* other views that use the same buffer */ 53 GSList *siblings; 54 55 TERM_WINDOW *window; 56 int width, height; 57 58 int default_indent; 59 INDENT_FUNC default_indent_func; 60 61 TEXT_BUFFER_CACHE_REC *cache; 62 /* cursor position - visible area is 0..height-1 */ 63 int ypos; 64 65 /* line at the top of the screen */ 66 LINE_REC *startline; 67 /* number of "real lines" to skip from `startline' */ 68 int subline; 69 70 /* marks the bottom of the text buffer */ 71 LINE_REC *bottom_startline; 72 int bottom_subline; 73 74 /* Bookmarks to the lines in the buffer - removed automatically 75 when the line gets removed from buffer */ 76 GHashTable *bookmarks; 77 78 /* these levels should be hidden */ 79 int hidden_level; 80 /* how many empty lines are in screen. a screenful when started 81 or used /CLEAR */ 82 int empty_linecount; 83 84 unsigned int longword_noindent:1; 85 /* scroll down automatically when at bottom */ 86 unsigned int scroll:1; 87 /* use UTF8 in this view */ 88 unsigned int utf8:1; 89 /* Break wide chars in this view */ 90 unsigned int break_wide:1; 91 /* window is at the bottom of the text buffer */ 92 unsigned int bottom:1; 93 /* if !bottom - new text has been printed since we were at bottom */ 94 unsigned int more_text:1; 95 /* Window needs a redraw */ 96 unsigned int dirty:1; 97 }; 98 99 /* Create new view. */ 100 TEXT_BUFFER_VIEW_REC *textbuffer_view_create(TEXT_BUFFER_REC *buffer, 101 int width, int height, 102 int scroll, int utf8); 103 /* Destroy the view. */ 104 void textbuffer_view_destroy(TEXT_BUFFER_VIEW_REC *view); 105 /* Change the default indent position */ 106 void textbuffer_view_set_default_indent(TEXT_BUFFER_VIEW_REC *view, 107 int default_indent, 108 int longword_noindent, 109 INDENT_FUNC indent_func); 110 void textbuffer_views_unregister_indent_func(INDENT_FUNC indent_func); 111 void textbuffer_view_set_break_wide(TEXT_BUFFER_VIEW_REC *view, 112 gboolean break_wide); 113 114 void textbuffer_view_set_scroll(TEXT_BUFFER_VIEW_REC *view, int scroll); 115 void textbuffer_view_set_utf8(TEXT_BUFFER_VIEW_REC *view, int utf8); 116 117 /* Resize the view. */ 118 void textbuffer_view_resize(TEXT_BUFFER_VIEW_REC *view, int width, int height); 119 /* Clear the view, don't actually remove any lines from buffer. */ 120 void textbuffer_view_clear(TEXT_BUFFER_VIEW_REC *view); 121 122 #define textbuffer_view_get_lines(view) \ 123 ((view)->buffer->first_line) 124 125 /* Scroll the view up/down */ 126 void textbuffer_view_scroll(TEXT_BUFFER_VIEW_REC *view, int lines); 127 /* Scroll to specified line */ 128 void textbuffer_view_scroll_line(TEXT_BUFFER_VIEW_REC *view, LINE_REC *line); 129 /* Return line cache */ 130 LINE_CACHE_REC *textbuffer_view_get_line_cache(TEXT_BUFFER_VIEW_REC *view, 131 LINE_REC *line); 132 /* Reset the whole line cache */ 133 void textbuffer_view_reset_cache(TEXT_BUFFER_VIEW_REC *view); 134 135 /* 136 Functions for manipulating the text buffer, using these commands update 137 all views that use the buffer. 138 */ 139 140 /* Update some line in the buffer which has been modified using 141 textbuffer_append() or textbuffer_insert(). */ 142 void textbuffer_view_insert_line(TEXT_BUFFER_VIEW_REC *view, LINE_REC *line); 143 /* Remove one line from buffer. */ 144 void textbuffer_view_remove_line(TEXT_BUFFER_VIEW_REC *view, LINE_REC *line); 145 /* Remove all lines from buffer. */ 146 void textbuffer_view_remove_all_lines(TEXT_BUFFER_VIEW_REC *view); 147 void textbuffer_view_remove_lines_by_level(TEXT_BUFFER_VIEW_REC *view, int level); 148 149 /* Set a bookmark in view */ 150 void textbuffer_view_set_bookmark(TEXT_BUFFER_VIEW_REC *view, 151 const char *name, LINE_REC *line); 152 /* Set a bookmark in view to the bottom line */ 153 void textbuffer_view_set_bookmark_bottom(TEXT_BUFFER_VIEW_REC *view, 154 const char *name); 155 /* Return the line for bookmark */ 156 LINE_REC *textbuffer_view_get_bookmark(TEXT_BUFFER_VIEW_REC *view, 157 const char *name); 158 /* Set hidden level for view */ 159 void textbuffer_view_set_hidden_level(TEXT_BUFFER_VIEW_REC *view, int level); 160 161 /* Specify window where the changes in view should be drawn, 162 NULL disables it. */ 163 void textbuffer_view_set_window(TEXT_BUFFER_VIEW_REC *view, 164 TERM_WINDOW *window); 165 /* Redraw the view */ 166 void textbuffer_view_redraw(TEXT_BUFFER_VIEW_REC *view); 167 168 void textbuffer_view_init(void); 169 void textbuffer_view_deinit(void); 170 171 #endif 172