Home | History | Annotate | Download | only in src

Lines Matching defs:vt

38   VTerm *vt = (*funcs->malloc)(sizeof(VTerm), allocdata);
40 vt->allocator = funcs;
41 vt->allocdata = allocdata;
43 vt->rows = rows;
44 vt->cols = cols;
46 vt->parser.state = NORMAL;
48 vt->parser.callbacks = NULL;
49 vt->parser.cbdata = NULL;
51 vt->parser.strbuffer_len = 64;
52 vt->parser.strbuffer_cur = 0;
53 vt->parser.strbuffer = vterm_allocator_malloc(vt, vt->parser.strbuffer_len);
55 vt->outbuffer_len = 64;
56 vt->outbuffer_cur = 0;
57 vt->outbuffer = vterm_allocator_malloc(vt, vt->outbuffer_len);
59 return vt;
62 void vterm_free(VTerm *vt)
64 if(vt->screen)
65 vterm_screen_free(vt->screen);
67 if(vt->state)
68 vterm_state_free(vt->state);
70 vterm_allocator_free(vt, vt->parser.strbuffer);
71 vterm_allocator_free(vt, vt->outbuffer);
73 vterm_allocator_free(vt, vt);
76 INTERNAL void *vterm_allocator_malloc(VTerm *vt, size_t size)
78 return (*vt->allocator->malloc)(size, vt->allocdata);
81 INTERNAL void vterm_allocator_free(VTerm *vt, void *ptr)
83 (*vt->allocator->free)(ptr, vt->allocdata);
86 void vterm_get_size(const VTerm *vt, int *rowsp, int *colsp)
89 *rowsp = vt->rows;
91 *colsp = vt->cols;
94 void vterm_set_size(VTerm *vt, int rows, int cols)
96 vt->rows = rows;
97 vt->cols = cols;
99 if(vt->parser.callbacks && vt->parser.callbacks->resize)
100 (*vt->parser.callbacks->resize)(rows, cols, vt->parser.cbdata);
103 int vterm_get_utf8(const VTerm *vt)
105 return vt->mode.utf8;
108 void vterm_set_utf8(VTerm *vt, int is_utf8)
110 vt->mode.utf8 = is_utf8;
113 INTERNAL void vterm_push_output_bytes(VTerm *vt, const char *bytes, size_t len)
115 if(len > vt->outbuffer_len - vt->outbuffer_cur) {
117 len = vt->outbuffer_len - vt->outbuffer_cur;
120 memcpy(vt->outbuffer + vt->outbuffer_cur, bytes, len);
121 vt->outbuffer_cur += len;
124 static int outbuffer_is_full(VTerm *vt)
126 return vt->outbuffer_cur >= vt->outbuffer_len - 1;
129 INTERNAL void vterm_push_output_vsprintf(VTerm *vt, const char *format, va_list args)
131 if(outbuffer_is_full(vt)) {
136 int written = vsnprintf(vt->outbuffer + vt->outbuffer_cur,
137 vt->outbuffer_len - vt->outbuffer_cur,
140 if(written == vt->outbuffer_len - vt->outbuffer_cur) {
142 vt->outbuffer_cur = vt->outbuffer_len - 1;
145 vt->outbuffer_cur += written;
148 INTERNAL void vterm_push_output_sprintf(VTerm *vt, const char *format, ...)
152 vterm_push_output_vsprintf(vt, format, args);
156 INTERNAL void vterm_push_output_sprintf_ctrl(VTerm *vt, unsigned char ctrl, const char *fmt, ...)
158 size_t orig_cur = vt->outbuffer_cur;
160 if(ctrl >= 0x80 && !vt->mode.ctrl8bit)
161 vterm_push_output_sprintf(vt, ESC_S "%c", ctrl - 0x40);
163 vterm_push_output_sprintf(vt, "%c", ctrl);
167 vterm_push_output_vsprintf(vt, fmt, args);
170 if(outbuffer_is_full(vt))
171 vt->outbuffer_cur = orig_cur;
174 INTERNAL void vterm_push_output_sprintf_dcs(VTerm *vt, const char *fmt, ...)
176 size_t orig_cur = vt->outbuffer_cur;
178 if(!vt->mode.ctrl8bit)
179 vterm_push_output_sprintf(vt, ESC_S "%c", C1_DCS - 0x40);
181 vterm_push_output_sprintf(vt, "%c", C1_DCS);
185 vterm_push_output_vsprintf(vt, fmt, args);
188 vterm_push_output_sprintf_ctrl(vt, C1_ST, "");
190 if(outbuffer_is_full(vt))
191 vt->outbuffer_cur = orig_cur;
194 size_t vterm_output_get_buffer_size(const VTerm *vt)
196 return vt->outbuffer_len;
199 size_t vterm_output_get_buffer_current(const VTerm *vt)
201 return vt->outbuffer_cur;
204 size_t vterm_output_get_buffer_remaining(const VTerm *vt)
206 return vt->outbuffer_len - vt->outbuffer_cur;
209 size_t vterm_output_read(VTerm *vt, char *buffer, size_t len)
211 if(len > vt->outbuffer_cur)
212 len = vt->outbuffer_cur;
214 memcpy(buffer, vt->outbuffer, len);
216 if(len < vt->outbuffer_cur)
217 memmove(vt->outbuffer, vt->outbuffer + len, vt->outbuffer_cur - len);
219 vt->outbuffer_cur -= len;