/*
* Command Handlers
- * This is the inofficial documentation of all the TERM_CMD_* definitions. Each
+ * This is the unofficial documentation of all the TERM_CMD_* definitions. Each
* handled command has a separate function with an extensive comment on the
* semantics of the command.
* Note that many semantics are unknown and need to be verified. This is mostly
/*
* DECELR - enable-locator-reporting
* This changes the locator-reporting mode. @args[0] specifies the mode
- * to set, 0 disables locator-reporting, 1 enables it continously, 2
+ * to set, 0 disables locator-reporting, 1 enables it continuously, 2
* enables it for a single report. @args[1] specifies the
* precision-mode. 0 and 2 set the reporting to cell-precision, 1 sets
* pixel-precision.
return 0;
}
+unsigned int term_screen_get_width(term_screen *screen) {
+ assert_return(screen, -EINVAL);
+
+ return screen->page->width;
+}
+
+unsigned int term_screen_get_height(term_screen *screen) {
+ assert_return(screen, -EINVAL);
+
+ return screen->page->height;
+}
+
int term_screen_feed_text(term_screen *screen, const uint8_t *in, size_t size) {
- const uint32_t *ucs4_str;
+ uint32_t *ucs4_str;
size_t i, j, ucs4_len;
const term_seq *seq;
int r;
* 8bit mode if the stream is not valid UTF-8. This should be more than
* enough to support old 7bit/8bit modes. */
for (i = 0; i < size; ++i) {
- ucs4_str = term_utf8_decode(&screen->utf8, &ucs4_len, in[i]);
+ ucs4_len = term_utf8_decode(&screen->utf8, &ucs4_str, in[i]);
for (j = 0; j < ucs4_len; ++j) {
r = term_parser_feed(screen->parser, &seq, ucs4_str[j]);
if (r < 0) {
return 0;
}
+
+int term_screen_draw(term_screen *screen,
+ int (*draw_fn) (term_screen *screen,
+ void *userdata,
+ unsigned int x,
+ unsigned int y,
+ const term_attr *attr,
+ const uint32_t *ch,
+ size_t n_ch,
+ unsigned int ch_width),
+ void *userdata,
+ uint64_t *fb_age) {
+ uint64_t cell_age, line_age, age = 0;
+ term_charbuf_t ch_buf;
+ const uint32_t *ch_str;
+ unsigned int i, j, cw;
+ term_page *page;
+ term_line *line;
+ term_cell *cell;
+ size_t ch_n;
+ int r;
+
+ assert(screen);
+ assert(draw_fn);
+
+ if (fb_age)
+ age = *fb_age;
+
+ page = screen->page;
+
+ for (j = 0; j < page->height; ++j) {
+ line = page->lines[j];
+ line_age = MAX(line->age, page->age);
+
+ for (i = 0; i < page->width; ++i) {
+ cell = &line->cells[i];
+ cell_age = MAX(cell->age, line_age);
+
+ if (age != 0 && cell_age <= age)
+ continue;
+
+ ch_str = term_char_resolve(cell->ch, &ch_n, &ch_buf);
+
+ /* Character-width of 0 is used for cleared cells.
+ * Always treat this as single-cell character, so
+ * renderers can assume ch_width is set properpy. */
+ cw = MAX(cell->cwidth, 1U);
+
+ r = draw_fn(screen,
+ userdata,
+ i,
+ j,
+ &cell->attr,
+ ch_str,
+ ch_n,
+ cw);
+ if (r != 0)
+ return r;
+ }
+ }
+
+ if (fb_age)
+ *fb_age = screen->age++;
+
+ return 0;
+}