aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDaniel Eklöf <daniel@ekloef.se>2021-02-16 18:11:38 +0000
committerDaniel Eklöf <daniel@ekloef.se>2021-02-23 09:36:02 +0000
commit03c675c6e2d9152da363eefcb1a2c3b059aac2ba (patch)
treee6b4e6c85be33e749cde0880a2765be6c64b46cf
parentMerge branch 'sixel-private-color-registers' (diff)
sixel: implement private mode 8452 - cursor positioning after sixel
When disabled (the default), the cursor is positioned on a new line after emitting a sixel image. When enabled, the cursor is positioned to the right of the sixel image. Closes #363
-rw-r--r--CHANGELOG.md2
-rw-r--r--csi.c7
-rw-r--r--doc/foot-ctlseqs.5.scd3
-rw-r--r--sixel.c24
-rw-r--r--terminal.h3
5 files changed, 37 insertions, 2 deletions
diff --git a/CHANGELOG.md b/CHANGELOG.md
index e4a00be3..1473707b 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -47,6 +47,8 @@
(https://codeberg.org/dnkl/foot/issues/347)
* `DECSET 1070` - sixel private color palette
(https://codeberg.org/dnkl/foot/issues/362).
+* `DECSET 8452` - position cursor to the right of sixels
+ (https://codeberg.org/dnkl/foot/issues/363).
### Changed
diff --git a/csi.c b/csi.c
index d7a26e3c..b05327b1 100644
--- a/csi.c
+++ b/csi.c
@@ -552,6 +552,10 @@ decset_decrst(struct terminal *term, unsigned param, bool enable)
term->bracketed_paste = enable;
break;
+ case 8452:
+ term->sixel.cursor_right_of_graphics = enable;
+ break;
+
case 27127:
term->modify_escape_key = enable;
break;
@@ -613,6 +617,7 @@ decrqm(const struct terminal *term, unsigned param, bool *enabled)
case 1049: *enabled = term->grid == &term->alt; return true;
case 1079: *enabled = term->sixel.use_private_palette; return true;
case 2004: *enabled = term->bracketed_paste; return true;
+ case 8452: *enabled = term->sixel.cursor_right_of_graphics; return true;
case 27127: *enabled = term->modify_escape_key; return true;
case 737769: *enabled = term_ime_is_enabled(term); return true;
}
@@ -653,6 +658,7 @@ xtsave(struct terminal *term, unsigned param)
case 1049: term->xtsave.alt_screen = term->grid == &term->alt; break;
case 1070: term->xtsave.sixel_private_palette = term->sixel.use_private_palette; break;
case 2004: term->xtsave.bracketed_paste = term->bracketed_paste; break;
+ case 8452: term->xtsave.sixel_cursor_right_of_graphics = term->sixel.cursor_right_of_graphics; break;
case 27127: term->xtsave.modify_escape_key = term->modify_escape_key; break;
case 737769: term->xtsave.ime = term_ime_is_enabled(term); break;
}
@@ -692,6 +698,7 @@ xtrestore(struct terminal *term, unsigned param)
case 1049: enable = term->xtsave.alt_screen; break;
case 1070: enable = term->xtsave.sixel_private_palette; break;
case 2004: enable = term->xtsave.bracketed_paste; break;
+ case 8452: enable = term->xtsave.sixel_cursor_right_of_graphics; break;
case 27127: enable = term->xtsave.modify_escape_key; break;
case 737769: enable = term->xtsave.ime; break;
diff --git a/doc/foot-ctlseqs.5.scd b/doc/foot-ctlseqs.5.scd
index 9b459507..8b8d2643 100644
--- a/doc/foot-ctlseqs.5.scd
+++ b/doc/foot-ctlseqs.5.scd
@@ -316,6 +316,9 @@ that corresponds to one of the following modes:
| 2004
: xterm
: Wrap pasted text with start/end delimiters (bracketed paste mode)
+| 8452
+: xterm
+: Position cursor to the right of sixels, instead of on the next line
| 737769
: foot
: Input Method Editor (IME) mode
diff --git a/sixel.c b/sixel.c
index 63ce493b..4f41348c 100644
--- a/sixel.c
+++ b/sixel.c
@@ -767,9 +767,29 @@ sixel_unhook(struct terminal *term)
{
row->cells[col].attrs.clean = 0;
}
- term_linefeed(term);
+
+ if (i < image.rows - 1 || !term->sixel.cursor_right_of_graphics)
+ term_linefeed(term);
}
- term_carriage_return(term);
+
+ /*
+ * Position cursor
+ *
+ * Private mode 8452 controls where we leave the cursor after
+ * emitting a sixel:
+ *
+ * When disabled (the default), the cursor is positioned on a
+ * new line.
+ *
+ * When enabled, the cursor is positioned to the right of the
+ * sixel.
+ */
+ term_cursor_to(
+ term,
+ term->grid->cursor.point.row,
+ (term->sixel.cursor_right_of_graphics
+ ? min(image.pos.col + image.cols, term->cols - 1)
+ : 0));
_sixel_overwrite_by_rectangle(
term, image.pos.row, image.pos.col, image.rows, image.cols);
diff --git a/terminal.h b/terminal.h
index 632f6029..898a5770 100644
--- a/terminal.h
+++ b/terminal.h
@@ -361,6 +361,7 @@ struct terminal {
uint32_t ime:1;
uint32_t sixel_private_palette:1;
+ uint32_t sixel_cursor_right_of_graphics:1;
} xtsave;
char *window_title;
@@ -538,6 +539,8 @@ struct terminal {
unsigned param; /* Currently collecting parameter, for RASTER, COLOR_SPEC and REPEAT */
unsigned param_idx; /* Parameters seen */
+ bool cursor_right_of_graphics:1; /* Private mode 8452 */
+
/* Application configurable */
unsigned palette_size; /* Number of colors in palette */
unsigned max_width; /* Maximum image width, in pixels */