Use byteloader for printable char ranges

This commit is contained in:
Kovid Goyal 2023-11-14 07:15:09 +05:30
parent 93430cd5f4
commit 2dffad1d8e
No known key found for this signature in database
GPG key ID: 06BC317B515ACE7C
3 changed files with 16 additions and 17 deletions

View file

@ -657,9 +657,8 @@ screen_continue_to_next_line(Screen *self) {
}
void
screen_draw_printable_ascii(Screen *self, const uint8_t *chars, size_t num) {
screen_draw_printable_ascii(Screen *self, ByteLoader *it) {
screen_on_input(self);
self->last_graphic_char = chars[num-1];
self->is_dirty = true;
const CPUCell cc = {.hyperlink_id=self->active_hyperlink_id};
GPUCell g = {.attrs=cursor_to_attrs(self->cursor, 1), .fg=self->cursor->fg & COL_MASK, .bg=self->cursor->bg & COL_MASK, .decoration_fg=self->cursor->decoration_fg & COL_MASK};
@ -668,41 +667,39 @@ screen_draw_printable_ascii(Screen *self, const uint8_t *chars, size_t num) {
g.attrs.decoration = OPT(url_style);
}
#define fill_single_line(chars, num) { \
#define fill_single_line(num) { \
linebuf_init_line(self->linebuf, self->cursor->y); \
if (self->modes.mIRM) line_right_shift(self->linebuf->line, self->cursor->x, num); \
const unsigned limit = self->cursor->x + num; \
const uint8_t *p = chars; \
GPUCell *gp = self->linebuf->line->gpu_cells; \
CPUCell *cp = self->linebuf->line->cpu_cells; \
for (; self->cursor->x < limit; self->cursor->x++, p++) { \
for (; self->cursor->x < limit; self->cursor->x++) { \
memcpy(gp + self->cursor->x, &g, sizeof(g)); \
memcpy(cp + self->cursor->x, &cc, sizeof(cc)); \
cp[self->cursor->x].ch = *p; \
cp[self->cursor->x].ch = byte_loader_next(it); \
} \
if (selection_has_screen_line(&self->selections, self->cursor->y)) clear_selection(&self->selections); \
linebuf_mark_line_dirty(self->linebuf, self->cursor->y); \
}
int avail = self->columns - self->cursor->x;
if (avail >= (int)num) {
fill_single_line(chars, num);
if (avail >= (int)it->num_left) {
fill_single_line(it->num_left);
} else {
if (self->modes.mDECAWM) {
while (num) {
while (it->num_left) {
avail = self->columns - self->cursor->x;
if (!avail) { screen_continue_to_next_line(self); avail = self->columns; }
unsigned nc = MIN((unsigned)avail, num);
fill_single_line(chars, nc);
num -= nc;
chars += nc;
unsigned nc = MIN((unsigned)avail, it->num_left);
fill_single_line(nc);
}
} else {
if (avail > 1) { fill_single_line(chars, avail - 1); }
if (avail > 1) { fill_single_line(avail - 1); }
else if (avail == 0) self->cursor->x--;
fill_single_line(chars + num - 1, 1);
fill_single_line(1);
}
}
self->last_graphic_char = self->linebuf->line->cpu_cells[self->cursor->x-1].ch;
}
static void

View file

@ -9,6 +9,7 @@
#include "vt-parser.h"
#include "graphics.h"
#include "monotonic.h"
#include "simd-string.h"
typedef enum ScrollTypes { SCROLL_LINE = -999999, SCROLL_PAGE, SCROLL_FULL } ScrollType;
@ -167,7 +168,7 @@ void screen_cursor_back(Screen *self, unsigned int count/*=1*/, int move_directi
void screen_erase_in_line(Screen *, unsigned int, bool);
void screen_erase_in_display(Screen *, unsigned int, bool);
void screen_draw(Screen *screen, uint32_t codepoint);
void screen_draw_printable_ascii(Screen *self, const uint8_t *chars, size_t num);
void screen_draw_printable_ascii(Screen *self, ByteLoader* );
void screen_ensure_bounds(Screen *self, bool use_margins, bool cursor_was_within_margins);
void screen_toggle_screen_buffer(Screen *self, bool, bool);
void screen_normal_keypad_mode(Screen *self);

View file

@ -277,7 +277,8 @@ dispatch_normal_mode_byte(PS *self, uint8_t ch) {
static void
dispatch_printable_ascii(PS *self, const size_t sz) {
REPORT_DRAW_ASCII(self->buf + self->read.pos, sz);
screen_draw_printable_ascii(self->screen, self->buf + self->read.pos, sz);
ByteLoader b; byte_loader_init(&b, self->buf + self->read.pos, sz);
screen_draw_printable_ascii(self->screen, &b);
self->read.pos += sz;
}