2020-04-20 13:25:36 +00:00
|
|
|
/* $OpenBSD$ */
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Copyright (c) 2020 Nicholas Marriott <nicholas.marriott@gmail.com>
|
|
|
|
*
|
|
|
|
* Permission to use, copy, modify, and distribute this software for any
|
|
|
|
* purpose with or without fee is hereby granted, provided that the above
|
|
|
|
* copyright notice and this permission notice appear in all copies.
|
|
|
|
*
|
|
|
|
* THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
|
|
|
|
* WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
|
|
|
|
* MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
|
|
|
|
* ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
|
|
|
|
* WHATSOEVER RESULTING FROM LOSS OF MIND, USE, DATA OR PROFITS, WHETHER
|
|
|
|
* IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING
|
|
|
|
* OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <sys/types.h>
|
|
|
|
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <string.h>
|
|
|
|
|
2022-07-19 06:48:48 +00:00
|
|
|
#if defined(HAVE_CURSES_H)
|
|
|
|
#include <curses.h>
|
|
|
|
#elif defined(HAVE_NCURSES_H)
|
|
|
|
#include <ncurses.h>
|
|
|
|
#endif
|
|
|
|
|
2020-04-20 13:25:36 +00:00
|
|
|
#include "tmux.h"
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Still hardcoded:
|
|
|
|
* - default colours (under AX or op capabilities);
|
|
|
|
* - AIX colours (under colors >= 16);
|
2020-05-16 14:46:14 +00:00
|
|
|
* - alternate escape (if terminal is VT100-like).
|
2020-04-20 13:25:36 +00:00
|
|
|
*
|
|
|
|
* Also:
|
2020-05-16 14:22:51 +00:00
|
|
|
* - DECFRA uses a flag instead of capabilities;
|
2020-04-20 13:25:36 +00:00
|
|
|
* - UTF-8 is a separate flag on the client; needed for unattached clients.
|
|
|
|
*/
|
|
|
|
|
|
|
|
/* A named terminal feature. */
|
|
|
|
struct tty_feature {
|
2022-08-15 08:41:13 +00:00
|
|
|
const char *name;
|
|
|
|
const char *const *capabilities;
|
|
|
|
int flags;
|
2020-04-20 13:25:36 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
/* Terminal has xterm(1) title setting. */
|
2022-08-15 08:41:13 +00:00
|
|
|
static const char *const tty_feature_title_capabilities[] = {
|
2020-04-20 13:25:36 +00:00
|
|
|
"tsl=\\E]0;", /* should be using TS really */
|
|
|
|
"fsl=\\a",
|
|
|
|
NULL
|
|
|
|
};
|
2020-05-16 14:46:14 +00:00
|
|
|
static const struct tty_feature tty_feature_title = {
|
2020-04-20 13:25:36 +00:00
|
|
|
"title",
|
|
|
|
tty_feature_title_capabilities,
|
|
|
|
0
|
|
|
|
};
|
|
|
|
|
2022-03-24 09:05:57 +00:00
|
|
|
/* Terminal has OSC 7 working directory. */
|
2022-08-15 08:41:13 +00:00
|
|
|
static const char *const tty_feature_osc7_capabilities[] = {
|
2022-03-24 09:05:57 +00:00
|
|
|
"Swd=\\E]7;",
|
|
|
|
"fsl=\\a",
|
|
|
|
NULL
|
|
|
|
};
|
|
|
|
static const struct tty_feature tty_feature_osc7 = {
|
|
|
|
"osc7",
|
|
|
|
tty_feature_osc7_capabilities,
|
|
|
|
0
|
|
|
|
};
|
|
|
|
|
2021-06-10 07:59:08 +00:00
|
|
|
/* Terminal has mouse support. */
|
2022-08-15 08:41:13 +00:00
|
|
|
static const char *const tty_feature_mouse_capabilities[] = {
|
2021-06-10 07:59:08 +00:00
|
|
|
"kmous=\\E[M",
|
|
|
|
NULL
|
|
|
|
};
|
|
|
|
static const struct tty_feature tty_feature_mouse = {
|
|
|
|
"mouse",
|
|
|
|
tty_feature_mouse_capabilities,
|
|
|
|
0
|
|
|
|
};
|
|
|
|
|
2020-04-20 13:25:36 +00:00
|
|
|
/* Terminal can set the clipboard with OSC 52. */
|
2022-08-15 08:41:13 +00:00
|
|
|
static const char *const tty_feature_clipboard_capabilities[] = {
|
2020-04-20 13:25:36 +00:00
|
|
|
"Ms=\\E]52;%p1%s;%p2%s\\a",
|
|
|
|
NULL
|
|
|
|
};
|
2020-05-16 14:46:14 +00:00
|
|
|
static const struct tty_feature tty_feature_clipboard = {
|
2020-04-20 13:25:36 +00:00
|
|
|
"clipboard",
|
|
|
|
tty_feature_clipboard_capabilities,
|
|
|
|
0
|
|
|
|
};
|
|
|
|
|
2022-06-30 09:55:53 +00:00
|
|
|
/* Terminal supports OSC 8 hyperlinks. */
|
|
|
|
static const char *tty_feature_hyperlinks_capabilities[] = {
|
2022-06-30 15:46:26 +00:00
|
|
|
#if defined (__OpenBSD__) || (defined(NCURSES_VERSION_MAJOR) && \
|
|
|
|
(NCURSES_VERSION_MAJOR > 5 || \
|
|
|
|
(NCURSES_VERSION_MAJOR == 5 && NCURSES_VERSION_MINOR > 8)))
|
2022-06-30 09:55:53 +00:00
|
|
|
"*:Hls=\\E]8;%?%p1%l%tid=%p1%s%;;%p2%s\\E\\\\",
|
2022-06-30 15:46:26 +00:00
|
|
|
#endif
|
2022-06-30 09:55:53 +00:00
|
|
|
NULL
|
|
|
|
};
|
|
|
|
static const struct tty_feature tty_feature_hyperlinks = {
|
|
|
|
"hyperlinks",
|
|
|
|
tty_feature_hyperlinks_capabilities,
|
|
|
|
0
|
|
|
|
};
|
|
|
|
|
2020-04-20 13:25:36 +00:00
|
|
|
/*
|
|
|
|
* Terminal supports RGB colour. This replaces setab and setaf also since
|
|
|
|
* terminals with RGB have versions that do not allow setting colours from the
|
|
|
|
* 256 palette.
|
|
|
|
*/
|
2022-08-15 08:41:13 +00:00
|
|
|
static const char *const tty_feature_rgb_capabilities[] = {
|
2020-04-21 10:37:11 +00:00
|
|
|
"AX",
|
2020-04-20 13:25:36 +00:00
|
|
|
"setrgbf=\\E[38;2;%p1%d;%p2%d;%p3%dm",
|
|
|
|
"setrgbb=\\E[48;2;%p1%d;%p2%d;%p3%dm",
|
|
|
|
"setab=\\E[%?%p1%{8}%<%t4%p1%d%e%p1%{16}%<%t10%p1%{8}%-%d%e48;5;%p1%d%;m",
|
|
|
|
"setaf=\\E[%?%p1%{8}%<%t3%p1%d%e%p1%{16}%<%t9%p1%{8}%-%d%e38;5;%p1%d%;m",
|
|
|
|
NULL
|
|
|
|
};
|
2020-05-16 14:46:14 +00:00
|
|
|
static const struct tty_feature tty_feature_rgb = {
|
2020-04-20 13:25:36 +00:00
|
|
|
"RGB",
|
|
|
|
tty_feature_rgb_capabilities,
|
2020-05-16 14:22:51 +00:00
|
|
|
TERM_256COLOURS|TERM_RGBCOLOURS
|
2020-04-20 13:25:36 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
/* Terminal supports 256 colours. */
|
2022-08-15 08:41:13 +00:00
|
|
|
static const char *const tty_feature_256_capabilities[] = {
|
2020-04-21 10:37:11 +00:00
|
|
|
"AX",
|
2020-04-20 13:25:36 +00:00
|
|
|
"setab=\\E[%?%p1%{8}%<%t4%p1%d%e%p1%{16}%<%t10%p1%{8}%-%d%e48;5;%p1%d%;m",
|
|
|
|
"setaf=\\E[%?%p1%{8}%<%t3%p1%d%e%p1%{16}%<%t9%p1%{8}%-%d%e38;5;%p1%d%;m",
|
|
|
|
NULL
|
|
|
|
};
|
2020-05-16 14:46:14 +00:00
|
|
|
static const struct tty_feature tty_feature_256 = {
|
2020-04-20 13:25:36 +00:00
|
|
|
"256",
|
|
|
|
tty_feature_256_capabilities,
|
|
|
|
TERM_256COLOURS
|
|
|
|
};
|
|
|
|
|
|
|
|
/* Terminal supports overline. */
|
2022-08-15 08:41:13 +00:00
|
|
|
static const char *const tty_feature_overline_capabilities[] = {
|
2020-04-20 13:25:36 +00:00
|
|
|
"Smol=\\E[53m",
|
|
|
|
NULL
|
|
|
|
};
|
2020-05-16 14:46:14 +00:00
|
|
|
static const struct tty_feature tty_feature_overline = {
|
2020-04-20 13:25:36 +00:00
|
|
|
"overline",
|
|
|
|
tty_feature_overline_capabilities,
|
|
|
|
0
|
|
|
|
};
|
|
|
|
|
|
|
|
/* Terminal supports underscore styles. */
|
2022-08-15 08:41:13 +00:00
|
|
|
static const char *const tty_feature_usstyle_capabilities[] = {
|
2020-07-18 02:53:47 +00:00
|
|
|
"Smulx=\\E[4::%p1%dm",
|
|
|
|
"Setulc=\\E[58::2::%p1%{65536}%/%d::%p1%{256}%/%{255}%&%d::%p1%{255}%&%d%;m",
|
2023-09-02 09:17:23 +00:00
|
|
|
"Setulc1=\\E[58::5::%p1%dm",
|
2020-10-05 09:53:01 +00:00
|
|
|
"ol=\\E[59m",
|
2020-04-20 13:25:36 +00:00
|
|
|
NULL
|
|
|
|
};
|
2020-05-16 14:46:14 +00:00
|
|
|
static const struct tty_feature tty_feature_usstyle = {
|
2020-04-20 13:25:36 +00:00
|
|
|
"usstyle",
|
|
|
|
tty_feature_usstyle_capabilities,
|
|
|
|
0
|
|
|
|
};
|
|
|
|
|
2020-05-16 14:46:14 +00:00
|
|
|
/* Terminal supports bracketed paste. */
|
2022-08-15 08:41:13 +00:00
|
|
|
static const char *const tty_feature_bpaste_capabilities[] = {
|
2020-05-16 14:46:14 +00:00
|
|
|
"Enbp=\\E[?2004h",
|
|
|
|
"Dsbp=\\E[?2004l",
|
|
|
|
NULL
|
|
|
|
};
|
|
|
|
static const struct tty_feature tty_feature_bpaste = {
|
|
|
|
"bpaste",
|
|
|
|
tty_feature_bpaste_capabilities,
|
|
|
|
0
|
|
|
|
};
|
|
|
|
|
|
|
|
/* Terminal supports focus reporting. */
|
2022-08-15 08:41:13 +00:00
|
|
|
static const char *const tty_feature_focus_capabilities[] = {
|
2020-05-16 14:46:14 +00:00
|
|
|
"Enfcs=\\E[?1004h",
|
|
|
|
"Dsfcs=\\E[?1004l",
|
|
|
|
NULL
|
|
|
|
};
|
|
|
|
static const struct tty_feature tty_feature_focus = {
|
|
|
|
"focus",
|
|
|
|
tty_feature_focus_capabilities,
|
|
|
|
0
|
|
|
|
};
|
|
|
|
|
2020-04-20 13:25:36 +00:00
|
|
|
/* Terminal supports cursor styles. */
|
2022-08-15 08:41:13 +00:00
|
|
|
static const char *const tty_feature_cstyle_capabilities[] = {
|
2020-04-20 13:25:36 +00:00
|
|
|
"Ss=\\E[%p1%d q",
|
|
|
|
"Se=\\E[2 q",
|
|
|
|
NULL
|
|
|
|
};
|
2020-05-16 14:46:14 +00:00
|
|
|
static const struct tty_feature tty_feature_cstyle = {
|
2020-04-20 13:25:36 +00:00
|
|
|
"cstyle",
|
|
|
|
tty_feature_cstyle_capabilities,
|
|
|
|
0
|
|
|
|
};
|
|
|
|
|
|
|
|
/* Terminal supports cursor colours. */
|
2022-08-15 08:41:13 +00:00
|
|
|
static const char *const tty_feature_ccolour_capabilities[] = {
|
2020-04-20 13:25:36 +00:00
|
|
|
"Cs=\\E]12;%p1%s\\a",
|
|
|
|
"Cr=\\E]112\\a",
|
|
|
|
NULL
|
|
|
|
};
|
2020-05-16 14:46:14 +00:00
|
|
|
static const struct tty_feature tty_feature_ccolour = {
|
2020-04-20 13:25:36 +00:00
|
|
|
"ccolour",
|
|
|
|
tty_feature_ccolour_capabilities,
|
|
|
|
0
|
|
|
|
};
|
|
|
|
|
2020-05-16 14:46:14 +00:00
|
|
|
/* Terminal supports strikethrough. */
|
2022-08-15 08:41:13 +00:00
|
|
|
static const char *const tty_feature_strikethrough_capabilities[] = {
|
2020-05-16 14:46:14 +00:00
|
|
|
"smxx=\\E[9m",
|
|
|
|
NULL
|
|
|
|
};
|
|
|
|
static const struct tty_feature tty_feature_strikethrough = {
|
|
|
|
"strikethrough",
|
|
|
|
tty_feature_strikethrough_capabilities,
|
|
|
|
0
|
|
|
|
};
|
|
|
|
|
2020-04-20 13:25:36 +00:00
|
|
|
/* Terminal supports synchronized updates. */
|
2022-08-15 08:41:13 +00:00
|
|
|
static const char *const tty_feature_sync_capabilities[] = {
|
2023-11-14 15:38:33 +00:00
|
|
|
"Sync=\\E[?2026%?%p1%{1}%-%tl%eh%;",
|
2020-04-20 13:25:36 +00:00
|
|
|
NULL
|
|
|
|
};
|
2020-05-16 14:46:14 +00:00
|
|
|
static const struct tty_feature tty_feature_sync = {
|
2020-04-20 13:25:36 +00:00
|
|
|
"sync",
|
|
|
|
tty_feature_sync_capabilities,
|
|
|
|
0
|
|
|
|
};
|
|
|
|
|
2020-05-16 16:44:54 +00:00
|
|
|
/* Terminal supports extended keys. */
|
2022-08-15 08:41:13 +00:00
|
|
|
static const char *const tty_feature_extkeys_capabilities[] = {
|
2020-05-16 16:44:54 +00:00
|
|
|
"Eneks=\\E[>4;1m",
|
|
|
|
"Dseks=\\E[>4m",
|
|
|
|
NULL
|
|
|
|
};
|
|
|
|
static const struct tty_feature tty_feature_extkeys = {
|
|
|
|
"extkeys",
|
|
|
|
tty_feature_extkeys_capabilities,
|
|
|
|
0
|
|
|
|
};
|
|
|
|
|
2020-04-20 13:25:36 +00:00
|
|
|
/* Terminal supports DECSLRM margins. */
|
2022-08-15 08:41:13 +00:00
|
|
|
static const char *const tty_feature_margins_capabilities[] = {
|
2020-05-16 14:22:51 +00:00
|
|
|
"Enmg=\\E[?69h",
|
|
|
|
"Dsmg=\\E[?69l",
|
|
|
|
"Clmg=\\E[s",
|
|
|
|
"Cmg=\\E[%i%p1%d;%p2%ds",
|
|
|
|
NULL
|
|
|
|
};
|
2020-05-16 14:46:14 +00:00
|
|
|
static const struct tty_feature tty_feature_margins = {
|
2020-04-20 13:25:36 +00:00
|
|
|
"margins",
|
2020-05-16 14:22:51 +00:00
|
|
|
tty_feature_margins_capabilities,
|
2020-04-20 13:25:36 +00:00
|
|
|
TERM_DECSLRM
|
|
|
|
};
|
|
|
|
|
|
|
|
/* Terminal supports DECFRA rectangle fill. */
|
2022-08-15 08:41:13 +00:00
|
|
|
static const char *const tty_feature_rectfill_capabilities[] = {
|
2021-06-10 07:28:45 +00:00
|
|
|
"Rect",
|
|
|
|
NULL
|
|
|
|
};
|
2020-05-16 14:46:14 +00:00
|
|
|
static const struct tty_feature tty_feature_rectfill = {
|
2020-04-20 13:25:36 +00:00
|
|
|
"rectfill",
|
2021-06-10 07:28:45 +00:00
|
|
|
tty_feature_rectfill_capabilities,
|
2020-04-20 13:25:36 +00:00
|
|
|
TERM_DECFRA
|
|
|
|
};
|
|
|
|
|
2022-06-14 07:29:00 +00:00
|
|
|
/* Use builtin function keys only. */
|
2022-08-15 08:41:13 +00:00
|
|
|
static const char *const tty_feature_ignorefkeys_capabilities[] = {
|
2022-06-14 07:29:00 +00:00
|
|
|
"kf0@",
|
|
|
|
"kf1@",
|
|
|
|
"kf2@",
|
|
|
|
"kf3@",
|
|
|
|
"kf4@",
|
|
|
|
"kf5@",
|
|
|
|
"kf6@",
|
|
|
|
"kf7@",
|
|
|
|
"kf8@",
|
|
|
|
"kf9@",
|
|
|
|
"kf10@",
|
|
|
|
"kf11@",
|
|
|
|
"kf12@",
|
|
|
|
"kf13@",
|
|
|
|
"kf14@",
|
|
|
|
"kf15@",
|
|
|
|
"kf16@",
|
|
|
|
"kf17@",
|
|
|
|
"kf18@",
|
|
|
|
"kf19@",
|
|
|
|
"kf20@",
|
|
|
|
"kf21@",
|
|
|
|
"kf22@",
|
|
|
|
"kf23@",
|
|
|
|
"kf24@",
|
|
|
|
"kf25@",
|
|
|
|
"kf26@",
|
|
|
|
"kf27@",
|
|
|
|
"kf28@",
|
|
|
|
"kf29@",
|
|
|
|
"kf30@",
|
|
|
|
"kf31@",
|
|
|
|
"kf32@",
|
|
|
|
"kf33@",
|
|
|
|
"kf34@",
|
|
|
|
"kf35@",
|
|
|
|
"kf36@",
|
|
|
|
"kf37@",
|
|
|
|
"kf38@",
|
|
|
|
"kf39@",
|
|
|
|
"kf40@",
|
|
|
|
"kf41@",
|
|
|
|
"kf42@",
|
|
|
|
"kf43@",
|
|
|
|
"kf44@",
|
|
|
|
"kf45@",
|
|
|
|
"kf46@",
|
|
|
|
"kf47@",
|
|
|
|
"kf48@",
|
|
|
|
"kf49@",
|
|
|
|
"kf50@",
|
|
|
|
"kf51@",
|
|
|
|
"kf52@",
|
|
|
|
"kf53@",
|
|
|
|
"kf54@",
|
|
|
|
"kf55@",
|
|
|
|
"kf56@",
|
|
|
|
"kf57@",
|
|
|
|
"kf58@",
|
|
|
|
"kf59@",
|
|
|
|
"kf60@",
|
|
|
|
"kf61@",
|
|
|
|
"kf62@",
|
|
|
|
"kf63@",
|
|
|
|
NULL
|
|
|
|
};
|
|
|
|
static const struct tty_feature tty_feature_ignorefkeys = {
|
|
|
|
"ignorefkeys",
|
|
|
|
tty_feature_ignorefkeys_capabilities,
|
|
|
|
0
|
|
|
|
};
|
|
|
|
|
2022-11-11 08:37:55 +00:00
|
|
|
/* Terminal has sixel capability. */
|
|
|
|
static const char *const tty_feature_sixel_capabilities[] = {
|
|
|
|
"Sxl",
|
|
|
|
NULL
|
|
|
|
};
|
|
|
|
static const struct tty_feature tty_feature_sixel = {
|
|
|
|
"sixel",
|
|
|
|
tty_feature_sixel_capabilities,
|
2022-11-11 08:44:11 +00:00
|
|
|
TERM_SIXEL
|
2022-11-11 08:37:55 +00:00
|
|
|
};
|
|
|
|
|
2020-04-20 13:25:36 +00:00
|
|
|
/* Available terminal features. */
|
2022-08-15 08:41:13 +00:00
|
|
|
static const struct tty_feature *const tty_features[] = {
|
2020-04-20 13:25:36 +00:00
|
|
|
&tty_feature_256,
|
2020-05-16 14:46:14 +00:00
|
|
|
&tty_feature_bpaste,
|
2020-04-20 13:25:36 +00:00
|
|
|
&tty_feature_ccolour,
|
2020-05-16 14:46:14 +00:00
|
|
|
&tty_feature_clipboard,
|
2022-06-30 09:55:53 +00:00
|
|
|
&tty_feature_hyperlinks,
|
2020-04-20 13:25:36 +00:00
|
|
|
&tty_feature_cstyle,
|
2020-05-16 16:44:54 +00:00
|
|
|
&tty_feature_extkeys,
|
2020-05-16 14:46:14 +00:00
|
|
|
&tty_feature_focus,
|
2022-06-14 07:29:00 +00:00
|
|
|
&tty_feature_ignorefkeys,
|
2020-04-20 13:25:36 +00:00
|
|
|
&tty_feature_margins,
|
2021-06-10 07:59:08 +00:00
|
|
|
&tty_feature_mouse,
|
2022-03-24 09:05:57 +00:00
|
|
|
&tty_feature_osc7,
|
2020-04-20 13:25:36 +00:00
|
|
|
&tty_feature_overline,
|
|
|
|
&tty_feature_rectfill,
|
|
|
|
&tty_feature_rgb,
|
2022-11-11 08:37:55 +00:00
|
|
|
&tty_feature_sixel,
|
2020-05-16 14:46:14 +00:00
|
|
|
&tty_feature_strikethrough,
|
2020-04-20 13:25:36 +00:00
|
|
|
&tty_feature_sync,
|
|
|
|
&tty_feature_title,
|
|
|
|
&tty_feature_usstyle
|
|
|
|
};
|
|
|
|
|
|
|
|
void
|
|
|
|
tty_add_features(int *feat, const char *s, const char *separators)
|
|
|
|
{
|
|
|
|
const struct tty_feature *tf;
|
|
|
|
char *next, *loop, *copy;
|
|
|
|
u_int i;
|
|
|
|
|
2020-05-16 14:46:14 +00:00
|
|
|
log_debug("adding terminal features %s", s);
|
2020-05-16 14:22:51 +00:00
|
|
|
|
2020-04-20 13:25:36 +00:00
|
|
|
loop = copy = xstrdup(s);
|
|
|
|
while ((next = strsep(&loop, separators)) != NULL) {
|
|
|
|
for (i = 0; i < nitems(tty_features); i++) {
|
|
|
|
tf = tty_features[i];
|
|
|
|
if (strcasecmp(tf->name, next) == 0)
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
if (i == nitems(tty_features)) {
|
|
|
|
log_debug("unknown terminal feature: %s", next);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
if (~(*feat) & (1 << i)) {
|
|
|
|
log_debug("adding terminal feature: %s", tf->name);
|
|
|
|
(*feat) |= (1 << i);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
free(copy);
|
|
|
|
}
|
|
|
|
|
|
|
|
const char *
|
|
|
|
tty_get_features(int feat)
|
|
|
|
{
|
|
|
|
const struct tty_feature *tf;
|
|
|
|
static char s[512];
|
|
|
|
u_int i;
|
|
|
|
|
|
|
|
*s = '\0';
|
|
|
|
for (i = 0; i < nitems(tty_features); i++) {
|
|
|
|
if (~feat & (1 << i))
|
|
|
|
continue;
|
|
|
|
tf = tty_features[i];
|
|
|
|
|
|
|
|
strlcat(s, tf->name, sizeof s);
|
|
|
|
strlcat(s, ",", sizeof s);
|
|
|
|
}
|
|
|
|
if (*s != '\0')
|
|
|
|
s[strlen(s) - 1] = '\0';
|
|
|
|
return (s);
|
|
|
|
}
|
|
|
|
|
2020-04-20 15:37:32 +00:00
|
|
|
int
|
2020-04-20 13:25:36 +00:00
|
|
|
tty_apply_features(struct tty_term *term, int feat)
|
|
|
|
{
|
2022-08-15 08:41:13 +00:00
|
|
|
const struct tty_feature *tf;
|
|
|
|
const char *const *capability;
|
|
|
|
u_int i;
|
2020-04-20 13:25:36 +00:00
|
|
|
|
|
|
|
if (feat == 0)
|
2020-04-20 15:37:32 +00:00
|
|
|
return (0);
|
2020-04-20 13:25:36 +00:00
|
|
|
log_debug("applying terminal features: %s", tty_get_features(feat));
|
|
|
|
|
|
|
|
for (i = 0; i < nitems(tty_features); i++) {
|
|
|
|
if ((term->features & (1 << i)) || (~feat & (1 << i)))
|
|
|
|
continue;
|
|
|
|
tf = tty_features[i];
|
|
|
|
|
|
|
|
log_debug("applying terminal feature: %s", tf->name);
|
|
|
|
if (tf->capabilities != NULL) {
|
|
|
|
capability = tf->capabilities;
|
|
|
|
while (*capability != NULL) {
|
|
|
|
log_debug("adding capability: %s", *capability);
|
|
|
|
tty_term_apply(term, *capability, 1);
|
|
|
|
capability++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
term->flags |= tf->flags;
|
|
|
|
}
|
2020-04-20 15:37:32 +00:00
|
|
|
if ((term->features | feat) == term->features)
|
|
|
|
return (0);
|
2020-04-20 13:25:36 +00:00
|
|
|
term->features |= feat;
|
2020-04-20 15:37:32 +00:00
|
|
|
return (1);
|
2020-04-20 13:25:36 +00:00
|
|
|
}
|
2020-05-16 14:46:14 +00:00
|
|
|
|
|
|
|
void
|
|
|
|
tty_default_features(int *feat, const char *name, u_int version)
|
|
|
|
{
|
2022-08-15 08:41:13 +00:00
|
|
|
static const struct {
|
2020-05-16 14:46:14 +00:00
|
|
|
const char *name;
|
|
|
|
u_int version;
|
|
|
|
const char *features;
|
|
|
|
} table[] = {
|
2020-06-04 10:36:28 +00:00
|
|
|
#define TTY_FEATURES_BASE_MODERN_XTERM \
|
2021-06-10 07:59:08 +00:00
|
|
|
"256,RGB,bpaste,clipboard,mouse,strikethrough,title"
|
2020-05-16 14:46:14 +00:00
|
|
|
{ .name = "mintty",
|
2020-06-04 10:36:28 +00:00
|
|
|
.features = TTY_FEATURES_BASE_MODERN_XTERM
|
2020-10-05 09:53:01 +00:00
|
|
|
",ccolour,cstyle,extkeys,margins,overline,usstyle"
|
2020-05-16 14:46:14 +00:00
|
|
|
},
|
|
|
|
{ .name = "tmux",
|
2020-06-04 10:36:28 +00:00
|
|
|
.features = TTY_FEATURES_BASE_MODERN_XTERM
|
2022-06-30 09:55:53 +00:00
|
|
|
",ccolour,cstyle,focus,overline,usstyle,hyperlinks"
|
2020-05-16 14:46:14 +00:00
|
|
|
},
|
|
|
|
{ .name = "rxvt-unicode",
|
2022-06-14 07:29:00 +00:00
|
|
|
.features = "256,bpaste,ccolour,cstyle,mouse,title,ignorefkeys"
|
2020-05-16 14:46:14 +00:00
|
|
|
},
|
|
|
|
{ .name = "iTerm2",
|
2020-06-04 10:36:28 +00:00
|
|
|
.features = TTY_FEATURES_BASE_MODERN_XTERM
|
2022-06-30 09:55:53 +00:00
|
|
|
",cstyle,extkeys,margins,usstyle,sync,osc7,hyperlinks"
|
2020-05-16 14:46:14 +00:00
|
|
|
},
|
|
|
|
{ .name = "XTerm",
|
2021-06-10 07:28:45 +00:00
|
|
|
/*
|
|
|
|
* xterm also supports DECSLRM and DECFRA, but they can be
|
|
|
|
* disabled so not set it here - they will be added if
|
|
|
|
* secondary DA shows VT420.
|
|
|
|
*/
|
2020-06-04 10:36:28 +00:00
|
|
|
.features = TTY_FEATURES_BASE_MODERN_XTERM
|
2021-06-10 07:28:45 +00:00
|
|
|
",ccolour,cstyle,extkeys,focus"
|
2020-05-16 14:46:14 +00:00
|
|
|
}
|
|
|
|
};
|
|
|
|
u_int i;
|
|
|
|
|
|
|
|
for (i = 0; i < nitems(table); i++) {
|
|
|
|
if (strcmp(table[i].name, name) != 0)
|
|
|
|
continue;
|
|
|
|
if (version != 0 && version < table[i].version)
|
|
|
|
continue;
|
|
|
|
tty_add_features(feat, table[i].features, ",");
|
|
|
|
}
|
|
|
|
}
|