[vte] widget: Strip off trailing unused cells in get_text()
- From: Egmont Koblinger <egmontkob src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [vte] widget: Strip off trailing unused cells in get_text()
- Date: Sun, 25 Nov 2018 23:39:22 +0000 (UTC)
commit 7124ade774e73d9a4210607e8666dc98ab200acb
Author: Egmont Koblinger <egmont gmail com>
Date: Mon Nov 26 00:37:11 2018 +0100
widget: Strip off trailing unused cells in get_text()
Restore the behavior of not including trailing unused cells as spaces,
not even when they have a custom background. This corresponds to the
false value of the former include_trailing_spaces flag.
This partially reverts commit 138baedc50bbbc455bbc16e76919af2d6f6d7492
https://gitlab.gnome.org/GNOME/vte/issues/38
https://gitlab.gnome.org/GNOME/vte/issues/68
src/vte.cc | 39 +++++++++++++++++++++++++++++++++++++++
1 file changed, 39 insertions(+)
---
diff --git a/src/vte.cc b/src/vte.cc
index d30aaf73..7f8e10b5 100644
--- a/src/vte.cc
+++ b/src/vte.cc
@@ -6095,8 +6095,13 @@ Terminal::get_text(vte::grid::row_t start_row,
vte::grid::row_t row;
for (row = start_row; row < end_row + 1; row++, col = next_first_column) {
VteRowData const* row_data = find_row_data(row);
+ gsize last_empty, last_nonempty;
+ vte::grid::column_t last_emptycol, last_nonemptycol;
vte::grid::column_t line_last_column = (block || row == end_row) ? end_col : G_MAXLONG;
+ last_empty = last_nonempty = string->len;
+ last_emptycol = last_nonemptycol = -1;
+
attr.row = row;
attr.column = col;
pcell = NULL;
@@ -6128,9 +6133,16 @@ Terminal::get_text(vte::grid::row_t start_row,
/* Store the cell string */
if (pcell->c == 0) {
+ /* Empty cells of nondefault background color are
+ * stored as NUL characters. Treat them as spaces,
+ * but make a note of the last occurrence. */
g_string_append_c (string, ' ');
+ last_empty = string->len;
+ last_emptycol = col;
} else {
_vte_unistr_append_to_string (pcell->c, string);
+ last_nonempty = string->len;
+ last_nonemptycol = col;
}
/* If we added text to the string, record its
@@ -6145,6 +6157,33 @@ Terminal::get_text(vte::grid::row_t start_row,
}
}
+ /* Empty cells of nondefault background color can appear anywhere in a line,
+ * not just at the end, e.g. between "foo" and "bar" here:
+ * echo -e '\e[46mfoo\e[K\e[7Gbar\e[m'
+ * Strip off the trailing ones, preserve the middle ones. */
+ if (last_empty > last_nonempty) {
+
+ col = last_emptycol + 1;
+
+ if (row_data != NULL) {
+ while ((pcell = _vte_row_data_get (row_data, col))) {
+ col++;
+
+ if (pcell->attr.fragment())
+ continue;
+
+ if (pcell->c != 0)
+ break;
+ }
+ }
+ if (pcell == NULL) {
+ g_string_truncate(string, last_nonempty);
+ if (attributes)
+ g_array_set_size(attributes, string->len);
+ attr.column = last_nonemptycol;
+ }
+ }
+
/* Adjust column, in case we want to append a newline */
//FIXMEchpe MIN ?
attr.column = MAX(m_column_count, attr.column + 1);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]