From 1a3f02702c6a8461ee401c0f3d0d66c895b69831 Mon Sep 17 00:00:00 2001 From: Hans Petter Jansson Date: Sat, 17 Jun 2023 22:35:50 +0200 Subject: [PATCH] seqs: Add seqs to enable/disable the alt screen --- chafa/chafa-term-db.c | 4 ++++ chafa/chafa-term-info.c | 2 ++ chafa/chafa-term-seq-def.h | 34 ++++++++++++++++++++++++++++++++++ 3 files changed, 40 insertions(+) diff --git a/chafa/chafa-term-db.c b/chafa/chafa-term-db.c index 0b449d62..73c3ed86 100644 --- a/chafa/chafa-term-db.c +++ b/chafa/chafa-term-db.c @@ -86,6 +86,10 @@ static const SeqStr vt220_seqs [] = { CHAFA_TERM_SEQ_SAVE_CURSOR_POS, "\033[s" }, { CHAFA_TERM_SEQ_RESTORE_CURSOR_POS, "\033[u" }, + /* These are actually xterm seqs, but we'll allow it */ + { CHAFA_TERM_SEQ_ENABLE_ALT_SCREEN, "\033[1049h" }, + { CHAFA_TERM_SEQ_DISABLE_ALT_SCREEN, "\033[1049l" }, + { CHAFA_TERM_SEQ_MAX, NULL } }; diff --git a/chafa/chafa-term-info.c b/chafa/chafa-term-info.c index a8ff7ec4..02944263 100644 --- a/chafa/chafa-term-info.c +++ b/chafa/chafa-term-info.c @@ -181,6 +181,8 @@ * @CHAFA_TERM_SEQ_RESTORE_CURSOR_POS: Move cursor to the last saved position. * @CHAFA_TERM_SEQ_ENABLE_ADVANCE_DOWN_AFTER_SIXEL: After showing a sixel image, leave cursor below the first column. * @CHAFA_TERM_SEQ_ENABLE_ADVANCE_RIGHT_AFTER_SIXEL: After showing a sixel image, leave cursor to the right of the last row. + * @CHAFA_TERM_SEQ_ENABLE_ALT_SCREEN: Switch to the alternate screen buffer. + * @CHAFA_TERM_SEQ_DISABLE_ALT_SCREEN: Switch back to the regular screen buffer. * @CHAFA_TERM_SEQ_MAX: Last control sequence plus one. * * An enumeration of the control sequences supported by #ChafaTermInfo. diff --git a/chafa/chafa-term-seq-def.h b/chafa/chafa-term-seq-def.h index 40e06540..7d1024c8 100644 --- a/chafa/chafa-term-seq-def.h +++ b/chafa/chafa-term-seq-def.h @@ -2533,6 +2533,40 @@ CHAFA_TERM_SEQ_DEF(enable_advance_down_after_sixel, ENABLE_ADVANCE_DOWN_AFTER_SI **/ CHAFA_TERM_SEQ_DEF(enable_advance_right_after_sixel, ENABLE_ADVANCE_RIGHT_AFTER_SIXEL, 0, none, char) +/** + * chafa_term_info_emit_enable_alt_screen: + * @term_info: A #ChafaTermInfo + * @dest: String destination + * + * Prints the control sequence for #CHAFA_TERM_SEQ_ENABLE_ALT_SCREEN. + * + * @dest must have enough space to hold + * #CHAFA_TERM_SEQ_LENGTH_MAX bytes, even if the emitted sequence is + * shorter. The output will not be zero-terminated. + * + * Returns: Pointer to first byte after emitted string + * + * Since: 1.14 + **/ +CHAFA_TERM_SEQ_DEF(enable_alt_screen, ENABLE_ALT_SCREEN, 0, none, char) + +/** + * chafa_term_info_emit_disable_alt_screen: + * @term_info: A #ChafaTermInfo + * @dest: String destination + * + * Prints the control sequence for #CHAFA_TERM_SEQ_DISABLE_ALT_SCREEN. + * + * @dest must have enough space to hold + * #CHAFA_TERM_SEQ_LENGTH_MAX bytes, even if the emitted sequence is + * shorter. The output will not be zero-terminated. + * + * Returns: Pointer to first byte after emitted string + * + * Since: 1.14 + **/ +CHAFA_TERM_SEQ_DEF(disable_alt_screen, DISABLE_ALT_SCREEN, 0, none, char) + #undef CHAFA_TERM_SEQ_AVAILABILITY #undef CHAFA_TERM_SEQ_ARGS