aboutsummaryrefslogtreecommitdiff
path: root/grid.c
diff options
context:
space:
mode:
authorDaniel Eklöf <daniel@ekloef.se>2024-02-06 11:13:27 +0000
committerDaniel Eklöf <daniel@ekloef.se>2024-02-06 11:13:27 +0000
commit0a302265ec36b1cbdeb752ed9a87cb19b188017c (patch)
treecbe215dad8862bd348c4233dd6469ac6732561f4 /grid.c
parentMerge branch 'modifiers' (diff)
parentgrid: resize with reflow: reflow FTCS_COMMAND_{EXECUTED,FINISHED} (diff)
Merge branch 'pipe-command-output'
Diffstat (limited to 'grid.c')
-rw-r--r--grid.c70
1 files changed, 39 insertions, 31 deletions
diff --git a/grid.c b/grid.c
index ea103c65..e7cdedc5 100644
--- a/grid.c
+++ b/grid.c
@@ -1,5 +1,6 @@
#include "grid.h"
+#include <limits.h>
#include <stdlib.h>
#include <string.h>
@@ -231,7 +232,7 @@ grid_snapshot(const struct grid *grid)
clone_row->cells = xmalloc(grid->num_cols * sizeof(clone_row->cells[0]));
clone_row->linebreak = row->linebreak;
clone_row->dirty = row->dirty;
- clone_row->prompt_marker = row->prompt_marker;
+ clone_row->shell_integration = row->shell_integration;
for (int c = 0; c < grid->num_cols; c++)
clone_row->cells[c] = row->cells[c];
@@ -366,7 +367,9 @@ grid_row_alloc(int cols, bool initialize)
row->dirty = false;
row->linebreak = false;
row->extra = NULL;
- row->prompt_marker = false;
+ row->shell_integration.prompt_marker = false;
+ row->shell_integration.cmd_start = -1;
+ row->shell_integration.cmd_end = -1;
if (initialize) {
row->cells = xcalloc(cols, sizeof(row->cells[0]));
@@ -425,7 +428,9 @@ grid_resize_without_reflow(
new_row->dirty = old_row->dirty;
new_row->linebreak = false;
- new_row->prompt_marker = old_row->prompt_marker;
+ new_row->shell_integration.prompt_marker = old_row->shell_integration.prompt_marker;
+ new_row->shell_integration.cmd_start = min(old_row->shell_integration.cmd_start, new_cols - 1);
+ new_row->shell_integration.cmd_end = min(old_row->shell_integration.cmd_end, new_cols - 1);
if (new_cols > old_cols) {
/* Clear "new" columns */
@@ -587,7 +592,9 @@ _line_wrap(struct grid *old_grid, struct row **new_grid, struct row *row,
/* Scrollback is full, need to reuse a row */
grid_row_reset_extra(new_row);
new_row->linebreak = false;
- new_row->prompt_marker = false;
+ new_row->shell_integration.prompt_marker = false;
+ new_row->shell_integration.cmd_start = -1;
+ new_row->shell_integration.cmd_end = -1;
tll_foreach(old_grid->sixel_images, it) {
if (it->item.pos.row == *row_idx) {
@@ -831,35 +838,26 @@ grid_resize_and_reflow(
int end;
bool tp_break = false;
bool uri_break = false;
+ bool ftcs_break = false;
- /*
- * Set end-coordinate for this chunk, by finding the next
- * point-of-interest on this row.
- *
- * If there are no more tracking points, or URI ranges,
- * the end-coordinate will be at the end of the row,
- */
- if (range != range_terminator) {
- int uri_col = (range->start >= start ? range->start : range->end) + 1;
+ /* Figure out where to end this chunk */
+ {
+ const int uri_col = range != range_terminator
+ ? ((range->start >= start ? range->start : range->end) + 1)
+ : INT_MAX;
+ const int tp_col = tp != NULL ? tp->col + 1 : INT_MAX;
+ const int ftcs_col = old_row->shell_integration.cmd_start >= start
+ ? old_row->shell_integration.cmd_start + 1
+ : old_row->shell_integration.cmd_end >= start
+ ? old_row->shell_integration.cmd_end + 1
+ : INT_MAX;
- if (tp != NULL) {
- int tp_col = tp->col + 1;
- end = min(tp_col, uri_col);
+ end = min(col_count, min(min(tp_col, uri_col), ftcs_col));
- tp_break = end == tp_col;
- uri_break = end == uri_col;
- LOG_DBG("tp+uri break at %d (%d, %d)", end, tp_col, uri_col);
- } else {
- end = uri_col;
- uri_break = true;
- LOG_DBG("uri break at %d", end);
- }
- } else if (tp != NULL) {
- end = tp->col + 1;
- tp_break = true;
- LOG_DBG("TP break at %d", end);
- } else
- end = col_count;
+ uri_break = end == uri_col;
+ tp_break = end == tp_col;
+ ftcs_break = end == ftcs_col;
+ }
int cols = end - start;
xassert(cols > 0);
@@ -920,7 +918,7 @@ grid_resize_and_reflow(
xassert(from + amount <= old_cols);
if (from == 0)
- new_row->prompt_marker = old_row->prompt_marker;
+ new_row->shell_integration.prompt_marker = old_row->shell_integration.prompt_marker;
memcpy(
&new_row->cells[new_col_idx], &old_row->cells[from],
@@ -979,6 +977,16 @@ grid_resize_and_reflow(
}
}
+ if (ftcs_break) {
+ xassert(old_row->shell_integration.cmd_start == start + cols - 1 ||
+ old_row->shell_integration.cmd_end == start + cols - 1);
+
+ if (old_row->shell_integration.cmd_start == start + cols - 1)
+ new_row->shell_integration.cmd_start = new_col_idx - 1;
+ if (old_row->shell_integration.cmd_end == start + cols - 1)
+ new_row->shell_integration.cmd_end = new_col_idx - 1;
+ }
+
left -= cols;
start += cols;
}