From c02cc110e016b190b1a3af2792d7187f51871e80 Mon Sep 17 00:00:00 2001 From: Fabian Homborg Date: Mon, 30 Aug 2021 16:55:14 +0200 Subject: [PATCH] screen: Support tmux escape sequences Tmux has support for wrapping arbitrary escape sequences inside ``` \ePtmux;\e%s\e\\ ``` Since this ends like the screen title escape, we just reuse that. Characteristically, this is basically undocumented, but we already use it in e.g. fish_vi_cursor. --- src/screen.cpp | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/src/screen.cpp b/src/screen.cpp index 23ccd5108..43db3fda6 100644 --- a/src/screen.cpp +++ b/src/screen.cpp @@ -101,13 +101,20 @@ static bool allow_soft_wrap() { /// Does this look like the escape sequence for setting a screen name? static bool is_screen_name_escape_seq(const wchar_t *code, size_t *resulting_length) { + // Tmux escapes start with `\ePtmux;` and end also in `\e\\`, + // so we can just handle them here. + static const wchar_t *tmux_seq = L"Ptmux;"; + static const size_t tmux_seq_len = std::wcslen(tmux_seq); if (code[1] != L'k') { - return false; + if (wcsncmp(&code[1], tmux_seq, tmux_seq_len) != 0) { + return false; + } } const wchar_t *const screen_name_end_sentinel = L"\x1B\\"; const wchar_t *screen_name_end = std::wcsstr(&code[2], screen_name_end_sentinel); if (screen_name_end == nullptr) { // Consider just k to be the code. + // (note: for the tmux sequence this is broken, but since we have no idea...) *resulting_length = 2; } else { const wchar_t *escape_sequence_end =