More tests for multicell selections

This commit is contained in:
Kovid Goyal
2025-01-11 05:40:37 +05:30
parent da1626090a
commit 2423c2166e
5 changed files with 32 additions and 8 deletions

View File

@@ -268,6 +268,7 @@ pagerhist_push(HistoryBuf *self, ANSIBuf *as_ansi_buf) {
Line l = {.xnum=self->xnum, .text_cache=self->text_cache};
init_line(self, self->start_of_data, &l);
ANSILineState s = {.output_buf=as_ansi_buf};
as_ansi_buf->len = 0;
line_as_ansi(&l, &s, 0, l.xnum, 0, true);
pagerhist_write_bytes(ph, (const uint8_t*)"\x1b[m", 3);
if (pagerhist_write_ucs4(ph, as_ansi_buf->buf, as_ansi_buf->len)) {
@@ -351,6 +352,7 @@ as_ansi(HistoryBuf *self, PyObject *callback) {
ANSIBuf output = {0}; ANSILineState s = {.output_buf=&output};
for(unsigned int i = 0; i < self->count; i++) {
init_line(self, i, &l);
output.len = 0;
line_as_ansi(&l, &s, 0, l.xnum, 0, true);
if (!l.cpu_cells[l.xnum - 1].next_char_was_wrapped) {
ensure_space_for(&output, buf, Py_UCS4, output.len + 1, capacity, 2048, false);

View File

@@ -470,6 +470,7 @@ as_ansi(LineBuf *self, PyObject *callback) {
ANSIBuf output = {0}; ANSILineState s = {.output_buf=&output};
do {
init_line(self, &l, self->line_map[ylimit]);
output.len = 0;
line_as_ansi(&l, &s, 0, l.xnum, 0, true);
if (output.len) break;
ylimit--;
@@ -477,6 +478,7 @@ as_ansi(LineBuf *self, PyObject *callback) {
for(index_type i = 0; i <= ylimit; i++) {
bool output_newline = !linebuf_line_ends_with_continuation(self, i);
output.len = 0;
init_line(self, &l, self->line_map[i]);
line_as_ansi(&l, &s, 0, l.xnum, 0, true);
if (output_newline) {

View File

@@ -364,11 +364,17 @@ cell_as_utf8_for_fallback(const ListOfChars *lc, char *buf) {
bool
unicode_in_range(const Line *self, const index_type start, const index_type limit, const bool include_cc, const bool add_trailing_newline, const bool skip_zero_cells, bool skip_multiline_non_zero_lines, ANSIBuf *buf) {
static const size_t initial_cap = 4096;
ListOfChars lc;
if (!buf->buf) {
buf->buf = malloc(initial_cap * sizeof(buf->buf[0]));
if (!buf->buf) return false;
buf->capacity = initial_cap;
}
for (index_type i = start; i < limit; i++) {
lc.chars = buf->buf + buf->len; lc.capacity = buf->capacity - buf->len;
while (!text_in_cell_without_alloc(self->cpu_cells + i, self->text_cache, &lc)) {
size_t ns = MAX(4096u, 2 * buf->capacity);
size_t ns = MAX(initial_cap, 2 * buf->capacity);
char_type *np = realloc(buf->buf, ns);
if (!np) return false;
buf->capacity = ns; buf->buf = np;
@@ -485,7 +491,6 @@ write_mark_to_ansi_buf(ANSILineState *s, const char *m) {
bool
line_as_ansi(Line *self, ANSILineState *s, index_type start_at, index_type stop_before, char_type prefix_char, bool skip_multiline_non_zero_lines) {
s->output_buf->len = 0;
s->limit = MIN(stop_before, xlimit_for_line(self));
s->current_multicell_state = NULL;
s->escape_code_written = false;
@@ -554,11 +559,9 @@ set_wrapped_flag(Line* self, PyObject *is_wrapped) {
static PyObject*
__repr__(Line* self) {
RAII_ANSIBuf(buf);
PyObject *s = line_as_unicode(self, false, &buf);
if (s == NULL) return NULL;
PyObject *ans = PyObject_Repr(s);
Py_CLEAR(s);
return ans;
RAII_PyObject(s, line_as_unicode(self, false, &buf));
if (s != NULL) return PyObject_Repr(s);
return NULL;
}
static PyObject*
@@ -972,6 +975,7 @@ as_text_generic(PyObject *args, void *container, get_line_func get_line, index_t
Line *line = get_line(container, y);
if (!line) { if (PyErr_Occurred()) return NULL; break; }
if (need_newline) APPEND(nl);
ansibuf->len = 0;
if (as_ansi) {
// less has a bug where it resets colors when it sees a \r, so work
// around it by resetting SGR at the start of every line. This is

View File

@@ -9,7 +9,6 @@
#include "text-cache.h"
// TODO: Handle selection with multicell
// TODO: URL detection with multicell
typedef union CellAttrs {