summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authortopcat001 <anindya49@hotmail.com>2023-04-29 17:32:07 -0700
committertopcat001 <anindya49@hotmail.com>2023-04-29 17:32:07 -0700
commit0d71e5853ffe797f90b815ac3af25ac0ad92ab07 (patch)
tree97b2d3cc14560a879a9b71160855e2d2b978544e
parent64368a1a63f04fb877b57e4286c9a2e1efe966c9 (diff)
parentfbe6fe7f55cfc2a32f9cee4cb50502a53d3ce8bb (diff)
Merge branch 'master' into sixel
-rw-r--r--Makefile.am1
-rw-r--r--cmd-confirm-before.c42
-rw-r--r--compat.h1
-rw-r--r--compat/systemd.c149
-rw-r--r--configure.ac32
-rw-r--r--file.c6
-rw-r--r--format.c15
-rw-r--r--input.c4
-rw-r--r--options-table.c2
-rw-r--r--proc.c11
-rw-r--r--screen-write.c6
-rw-r--r--spawn.c14
-rw-r--r--status.c2
-rw-r--r--tmux.117
-rw-r--r--tmux.c2
-rw-r--r--tmux.h34
-rw-r--r--tty-keys.c7
-rw-r--r--tty-term.c89
-rw-r--r--tty.c153
-rw-r--r--window.c1
20 files changed, 454 insertions, 134 deletions
diff --git a/Makefile.am b/Makefile.am
index 9bbd21d4..874e51a4 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -14,6 +14,7 @@ dist_EXTRA_tmux_SOURCES = compat/*.[ch]
AM_CPPFLAGS += @XOPEN_DEFINES@ \
-DTMUX_VERSION='"@VERSION@"' \
-DTMUX_CONF='"$(sysconfdir)/tmux.conf:~/.tmux.conf:$$XDG_CONFIG_HOME/tmux/tmux.conf:~/.config/tmux/tmux.conf"' \
+ -DTMUX_LOCK_CMD='"@DEFAULT_LOCK_CMD@"' \
-DTMUX_TERM='"@DEFAULT_TERM@"'
# Additional object files.
diff --git a/cmd-confirm-before.c b/cmd-confirm-before.c
index ce8c95e0..485e6e65 100644
--- a/cmd-confirm-before.c
+++ b/cmd-confirm-before.c
@@ -41,8 +41,9 @@ const struct cmd_entry cmd_confirm_before_entry = {
.name = "confirm-before",
.alias = "confirm",
- .args = { "bp:t:", 1, 1, cmd_confirm_before_args_parse },
- .usage = "[-b] [-p prompt] " CMD_TARGET_CLIENT_USAGE " command",
+ .args = { "bc:p:t:y", 1, 1, cmd_confirm_before_args_parse },
+ .usage = "[-by] [-c confirm_key] [-p prompt] " CMD_TARGET_CLIENT_USAGE
+ " command",
.flags = CMD_CLIENT_TFLAG,
.exec = cmd_confirm_before_exec
@@ -51,6 +52,8 @@ const struct cmd_entry cmd_confirm_before_entry = {
struct cmd_confirm_before_data {
struct cmdq_item *item;
struct cmd_list *cmdlist;
+ u_char confirm_key;
+ int default_yes;
};
static enum args_parse_type
@@ -68,7 +71,7 @@ cmd_confirm_before_exec(struct cmd *self, struct cmdq_item *item)
struct client *tc = cmdq_get_target_client(item);
struct cmd_find_state *target = cmdq_get_target(item);
char *new_prompt;
- const char *prompt, *cmd;
+ const char *confirm_key, *prompt, *cmd;
int wait = !args_has(args, 'b');
cdata = xcalloc(1, sizeof *cdata);
@@ -79,11 +82,26 @@ cmd_confirm_before_exec(struct cmd *self, struct cmdq_item *item)
if (wait)
cdata->item = item;
+ cdata->default_yes = args_has(args, 'y');
+ if ((confirm_key = args_get(args, 'c')) != NULL) {
+ if (confirm_key[1] == '\0' &&
+ confirm_key[0] > 31 &&
+ confirm_key[0] < 127)
+ cdata->confirm_key = confirm_key[0];
+ else {
+ cmdq_error(item, "invalid confirm key");
+ return (CMD_RETURN_ERROR);
+ }
+ }
+ else
+ cdata->confirm_key = 'y';
+
if ((prompt = args_get(args, 'p')) != NULL)
xasprintf(&new_prompt, "%s ", prompt);
else {
cmd = cmd_get_entry(cmd_list_first(cdata->cmdlist))->name;
- xasprintf(&new_prompt, "Confirm '%s'? (y/n) ", cmd);
+ xasprintf(&new_prompt, "Confirm '%s'? (%c/n) ",
+ cmd, cdata->confirm_key);
}
status_prompt_set(tc, target, new_prompt, NULL,
@@ -107,9 +125,9 @@ cmd_confirm_before_callback(struct client *c, void *data, const char *s,
if (c->flags & CLIENT_DEAD)
goto out;
- if (s == NULL || *s == '\0')
+ if (s == NULL)
goto out;
- if (tolower((u_char)s[0]) != 'y' || s[1] != '\0')
+ if (s[0] != cdata->confirm_key && (s[0] != '\0' || !cdata->default_yes))
goto out;
retcode = 0;
@@ -123,12 +141,12 @@ cmd_confirm_before_callback(struct client *c, void *data, const char *s,
}
out:
- if (item != NULL) {
- if (cmdq_get_client(item) != NULL &&
- cmdq_get_client(item)->session == NULL)
- cmdq_get_client(item)->retval = retcode;
- cmdq_continue(item);
- }
+ if (item != NULL) {
+ if (cmdq_get_client(item) != NULL &&
+ cmdq_get_client(item)->session == NULL)
+ cmdq_get_client(item)->retval = retcode;
+ cmdq_continue(item);
+ }
return (0);
}
diff --git a/compat.h b/compat.h
index aefc0d38..cabdf3ad 100644
--- a/compat.h
+++ b/compat.h
@@ -425,6 +425,7 @@ void *recallocarray(void *, size_t, size_t, size_t);
/* systemd.c */
int systemd_activated(void);
int systemd_create_socket(int, char **);
+int systemd_move_pid_to_new_cgroup(pid_t, char **);
#endif
#ifdef HAVE_UTF8PROC
diff --git a/compat/systemd.c b/compat/systemd.c
index cce42ed4..6f790a32 100644
--- a/compat/systemd.c
+++ b/compat/systemd.c
@@ -19,7 +19,10 @@
#include <sys/types.h>
#include <sys/un.h>
+#include <systemd/sd-bus.h>
#include <systemd/sd-daemon.h>
+#include <systemd/sd-login.h>
+#include <systemd/sd-id128.h>
#include <string.h>
@@ -64,3 +67,149 @@ fail:
xasprintf(cause, "systemd socket error (%s)", strerror(errno));
return (-1);
}
+
+int
+systemd_move_pid_to_new_cgroup(pid_t pid, char **cause)
+{
+ sd_bus_error error = SD_BUS_ERROR_NULL;
+ sd_bus_message *m = NULL, *reply = NULL;
+ sd_bus *bus = NULL;
+ char *name, *desc, *slice;
+ sd_id128_t uuid;
+ int r;
+ pid_t parent_pid;
+
+ /* Connect to the session bus. */
+ r = sd_bus_default_user(&bus);
+ if (r < 0) {
+ xasprintf(cause, "failed to connect to session bus: %s",
+ strerror(-r));
+ goto finish;
+ }
+
+ /* Start building the method call. */
+ r = sd_bus_message_new_method_call(bus, &m,
+ "org.freedesktop.systemd1",
+ "/org/freedesktop/systemd1",
+ "org.freedesktop.systemd1.Manager",
+ "StartTransientUnit");
+ if (r < 0) {
+ xasprintf(cause, "failed to create bus message: %s",
+ strerror(-r));
+ goto finish;
+ }
+
+ /* Generate a unique name for the new scope, to avoid collisions. */
+ r = sd_id128_randomize(&uuid);
+ if (r < 0) {
+ xasprintf(cause, "failed to generate uuid: %s", strerror(-r));
+ goto finish;
+ }
+ xasprintf(&name, "tmux-spawn-" SD_ID128_UUID_FORMAT_STR ".scope",
+ SD_ID128_FORMAT_VAL(uuid));
+ r = sd_bus_message_append(m, "s", name);
+ free(name);
+ if (r < 0) {
+ xasprintf(cause, "failed to append to bus message: %s",
+ strerror(-r));
+ goto finish;
+ }
+
+ /* Mode: fail if there's a queued unit with the same name. */
+ r = sd_bus_message_append(m, "s", "fail");
+ if (r < 0) {
+ xasprintf(cause, "failed to append to bus message: %s",
+ strerror(-r));
+ goto finish;
+ }
+
+ /* Start properties array. */
+ r = sd_bus_message_open_container(m, 'a', "(sv)");
+ if (r < 0) {
+ xasprintf(cause, "failed to start properties array: %s",
+ strerror(-r));
+ goto finish;
+ }
+
+ parent_pid = getpid();
+ xasprintf(&desc, "tmux child pane %ld launched by process %ld",
+ (long)pid, (long)parent_pid);
+ r = sd_bus_message_append(m, "(sv)", "Description", "s", desc);
+ free(desc);
+ if (r < 0) {
+ xasprintf(cause, "failed to append to properties: %s",
+ strerror(-r));
+ goto finish;
+ }
+
+ /*
+ * Inherit the slice from the parent process, or default to
+ * "app-tmux.slice" if that fails.
+ */
+ r = sd_pid_get_user_slice(parent_pid, &slice);
+ if (r < 0) {
+ slice = xstrdup("app-tmux.slice");
+ }
+ r = sd_bus_message_append(m, "(sv)", "Slice", "s", slice);
+ free(slice);
+ if (r < 0) {
+ xasprintf(cause, "failed to append to properties: %s",
+ strerror(-r));
+ goto finish;
+ }
+
+ /* PIDs to add to the scope: length - 1 array of uint32_t. */
+ r = sd_bus_message_append(m, "(sv)", "PIDs", "au", 1, pid);
+ if (r < 0) {
+ xasprintf(cause, "failed to append to properties: %s",
+ strerror(-r));
+ goto finish;
+ }
+
+ /* Clean up the scope even if it fails. */
+ r = sd_bus_message_append(m, "(sv)", "CollectMode", "s",
+ "inactive-or-failed");
+ if (r < 0) {
+ xasprintf(cause, "failed to append to properties: %s",
+ strerror(-r));
+ goto finish;
+ }
+
+ /* End properties array. */
+ r = sd_bus_message_close_container(m);
+ if (r < 0) {
+ xasprintf(cause, "failed to end properties array: %s",
+ strerror(-r));
+ goto finish;
+ }
+
+ /* aux is currently unused and should be passed an empty array. */
+ r = sd_bus_message_append(m, "a(sa(sv))", 0);
+ if (r < 0) {
+ xasprintf(cause, "failed to append to bus message: %s",
+ strerror(-r));
+ goto finish;
+ }
+
+ /* Call the method with a timeout of 1 second = 1e6 us. */
+ r = sd_bus_call(bus, m, 1000000, &error, &reply);
+ if (r < 0) {
+ if (error.message != NULL) {
+ /* We have a specific error message from sd-bus. */
+ xasprintf(cause, "StartTransientUnit call failed: %s",
+ error.message);
+ } else {
+ xasprintf(cause, "StartTransientUnit call failed: %s",
+ strerror(-r));
+ }
+ goto finish;
+ }
+
+finish:
+ sd_bus_error_free(&error);
+ sd_bus_message_unref(m);
+ sd_bus_message_unref(reply);
+ sd_bus_unref(bus);
+
+ return (r);
+}
diff --git a/configure.ac b/configure.ac
index 8e846042..1ccd0481 100644
--- a/configure.ac
+++ b/configure.ac
@@ -350,6 +350,10 @@ else
AC_MSG_ERROR("curses not found")
fi
fi
+AC_CHECK_FUNCS([ \
+ tiparm \
+ tiparm_s \
+])
# Look for utempter.
AC_ARG_ENABLE(
@@ -420,6 +424,21 @@ if test x"$enable_systemd" = xyes; then
fi
fi
AM_CONDITIONAL(HAVE_SYSTEMD, [test "x$found_systemd" = xyes])
+AC_ARG_ENABLE(
+ cgroups,
+ AS_HELP_STRING(--disable-cgroups, disable adding panes to new cgroups with systemd)
+)
+if test "x$enable_cgroups" = x; then
+ # Default to the same as $enable_systemd.
+ enable_cgroups=$enable_systemd
+fi
+if test "x$enable_cgroups" = xyes; then
+ if test "x$found_systemd" = xyes; then
+ AC_DEFINE(ENABLE_CGROUPS)
+ else
+ AC_MSG_ERROR("cgroups requires systemd to be enabled")
+ fi
+fi
# Check for b64_ntop. If we have b64_ntop, we assume b64_pton as well.
AC_MSG_CHECKING(for b64_ntop)
@@ -921,6 +940,19 @@ AM_CONDITIONAL(IS_HPUX, test "x$PLATFORM" = xhpux)
AM_CONDITIONAL(IS_HAIKU, test "x$PLATFORM" = xhaiku)
AM_CONDITIONAL(IS_UNKNOWN, test "x$PLATFORM" = xunknown)
+# Set the default lock command
+DEFAULT_LOCK_CMD="lock -np"
+AC_MSG_CHECKING(lock-command)
+if test "x$PLATFORM" = xlinux; then
+ AC_CHECK_PROG(found_vlock, vlock, yes, no)
+ if test "x$found_vlock" = xyes; then
+ DEFAULT_LOCK_CMD="vlock"
+ fi
+fi
+AC_MSG_RESULT($DEFAULT_LOCK_CMD)
+AC_SUBST(DEFAULT_LOCK_CMD)
+
+
# Save our CFLAGS/CPPFLAGS/LDFLAGS for the Makefile and restore the old user
# variables.
AC_SUBST(AM_CPPFLAGS)
diff --git a/file.c b/file.c
index 3c1096be..9bea5179 100644
--- a/file.c
+++ b/file.c
@@ -174,9 +174,9 @@ file_fire_read(struct client_file *cf)
int
file_can_print(struct client *c)
{
- if (c == NULL)
- return (0);
- if (c->session != NULL && (~c->flags & CLIENT_CONTROL))
+ if (c == NULL ||
+ (c->flags & CLIENT_ATTACHED) ||
+ (c->flags & CLIENT_CONTROL))
return (0);
return (1);
}
diff --git a/format.c b/format.c
index 547f4e1a..275d5218 100644
--- a/format.c
+++ b/format.c
@@ -1885,6 +1885,18 @@ format_cb_pane_input_off(struct format_tree *ft)
return (NULL);
}
+/* Callback for pane_unseen_changes. */
+static void *
+format_cb_pane_unseen_changes(struct format_tree *ft)
+{
+ if (ft->wp != NULL) {
+ if (ft->wp->flags & PANE_UNSEENCHANGES)
+ return (xstrdup("1"));
+ return (xstrdup("0"));
+ }
+ return (NULL);
+}
+
/* Callback for pane_last. */
static void *
format_cb_pane_last(struct format_tree *ft)
@@ -2953,6 +2965,9 @@ static const struct format_table_entry format_table[] = {
{ "pane_tty", FORMAT_TABLE_STRING,
format_cb_pane_tty
},
+ { "pane_unseen_changes", FORMAT_TABLE_STRING,
+ format_cb_pane_unseen_changes
+ },
{ "pane_width", FORMAT_TABLE_STRING,
format_cb_pane_width
},
diff --git a/input.c b/input.c
index 42862d8f..41d1a266 100644
--- a/input.c
+++ b/input.c
@@ -971,6 +971,10 @@ input_parse_buffer(struct window_pane *wp, u_char *buf, size_t len)
window_update_activity(wp->window);
wp->flags |= PANE_CHANGED;
+ /* Flag new input while in a mode. */
+ if (!TAILQ_EMPTY(&wp->modes))
+ wp->flags |= PANE_UNSEENCHANGES;
+
/* NULL wp if there is a mode set as don't want to update the tty. */
if (TAILQ_EMPTY(&wp->modes))
screen_write_start_pane(sctx, wp, &wp->base);
diff --git a/options-table.c b/options-table.c
index d4e7b204..6cb724cc 100644
--- a/options-table.c
+++ b/options-table.c
@@ -530,7 +530,7 @@ const struct options_table_entry options_table[] = {
{ .name = "lock-command",
.type = OPTIONS_TABLE_STRING,
.scope = OPTIONS_TABLE_SESSION,
- .default_str = "lock -np",
+ .default_str = TMUX_LOCK_CMD,
.text = "Shell command to run to lock a client."
},
diff --git a/proc.c b/proc.c
index 67ec214a..30eedadb 100644
--- a/proc.c
+++ b/proc.c
@@ -193,18 +193,13 @@ proc_start(const char *name)
log_debug("%s started (%ld): version %s, socket %s, protocol %d", name,
(long)getpid(), getversion(), socket_path, PROTOCOL_VERSION);
log_debug("on %s %s %s", u.sysname, u.release, u.version);
- log_debug("using libevent %s (%s)"
+ log_debug("using libevent %s %s", event_get_version(), event_get_method());
#ifdef HAVE_UTF8PROC
- "; utf8proc %s"
+ log_debug("using utf8proc %s", utf8proc_version());
#endif
#ifdef NCURSES_VERSION
- "; ncurses " NCURSES_VERSION
+ log_debug("using ncurses %s %06u", NCURSES_VERSION, NCURSES_VERSION_PATCH);
#endif
- , event_get_version(), event_get_method()
-#ifdef HAVE_UTF8PROC
- , utf8proc_version()
-#endif
- );
tp = xcalloc(1, sizeof *tp);
tp->name = xstrdup(name);
diff --git a/screen-write.c b/screen-write.c
index 0718df87..99e63ae9 100644
--- a/screen-write.c
+++ b/screen-write.c
@@ -132,6 +132,12 @@ screen_write_set_client_cb(struct tty_ctx *ttyctx, struct client *c)
{
struct window_pane *wp = ttyctx->arg;
+ if (ttyctx->allow_invisible_panes) {
+ if (session_has(c->session, wp->window))
+ return (1);
+ return (0);
+ }
+
if (c->session->curw->window != wp->window)
return (0);
if (wp->layout_cell == NULL)
diff --git a/spawn.c b/spawn.c
index e63133fe..10604028 100644
--- a/spawn.c
+++ b/spawn.c
@@ -380,8 +380,20 @@ spawn_pane(struct spawn_context *sc, char **cause)
}
/* In the parent process, everything is done now. */
- if (new_wp->pid != 0)
+ if (new_wp->pid != 0) {
+#if defined(HAVE_SYSTEMD) && defined(ENABLE_CGROUPS)
+ /*
+ * Move the child process into a new cgroup for systemd-oomd
+ * isolation.
+ */
+ if (systemd_move_pid_to_new_cgroup(new_wp->pid, cause) < 0) {
+ log_debug("%s: moving pane to new cgroup failed: %s",
+ __func__, *cause);
+ free (*cause);
+ }
+#endif
goto complete;
+ }
/*
* Child process. Change to the working directory or home if that
diff --git a/status.c b/status.c
index 08952f58..2bb42c0c 100644
--- a/status.c
+++ b/status.c
@@ -1471,8 +1471,6 @@ process_key:
return (0);
append_key:
- if (key <= 0x1f || (key >= KEYC_BASE && key < KEYC_BASE_END))
- return (0);
if (key <= 0x7f)
utf8_set(&tmp, key);
else if (KEYC_IS_UNICODE(key))
diff --git a/tmux.1 b/tmux.1
index 2009924f..92e2915f 100644
--- a/tmux.1
+++ b/tmux.1
@@ -1281,7 +1281,10 @@ behave like
.Ic attach-session
if
.Ar session-name
-already exists; in this case,
+already exists;
+if
+.Fl A
+is given,
.Fl D
behaves like
.Fl d
@@ -5260,6 +5263,7 @@ The following variables are available, where appropriate:
.It Li "pane_title" Ta "#T" Ta "Title of pane (can be set by application)"
.It Li "pane_top" Ta "" Ta "Top of pane"
.It Li "pane_tty" Ta "" Ta "Pseudo terminal of pane"
+.It Li "pane_unseen_changes" Ta "" Ta "1 if there were changes in pane while in mode"
.It Li "pane_width" Ta "" Ta "Width of pane"
.It Li "pid" Ta "" Ta "Server PID"
.It Li "rectangle_toggle" Ta "" Ta "1 if rectangle selection is activated"
@@ -5806,7 +5810,8 @@ the prompt is shown in the background and the invoking client does not exit
until it is dismissed.
.Tg confirm
.It Xo Ic confirm-before
-.Op Fl b
+.Op Fl by
+.Op Fl c Ar confirm-key
.Op Fl p Ar prompt
.Op Fl t Ar target-client
.Ar command
@@ -5827,6 +5832,14 @@ With
.Fl b ,
the prompt is shown in the background and the invoking client does not exit
until it is dismissed.
+.Fl y
+changes the default behaviour (if Enter alone is pressed) of the prompt to
+run the command.
+.Fl c
+changes the confirmation key to
+.Ar confirm-key ;
+the default is
+.Ql y .
.Tg menu
.It Xo Ic display-menu
.Op Fl O
diff --git a/tmux.c b/tmux.c
index ef78e7b4..a01ed423 100644
--- a/tmux.c
+++ b/tmux.c
@@ -391,7 +391,7 @@ main(int argc, char **argv)
cfg_quiet = 0;
break;
case 'V':
- printf("%s %s\n", getprogname(), getversion());
+ printf("tmux %s\n", getversion());
exit(0);
case 'l':
flags |= CLIENT_LOGIN;
diff --git a/tmux.h b/tmux.h
index 251d826d..bc12ab09 100644
--- a/tmux.h
+++ b/tmux.h
@@ -82,6 +82,9 @@ struct winlink;
#ifndef TMUX_TERM
#define TMUX_TERM "screen"
#endif
+#ifndef TMUX_LOCK_CMD
+#define TMUX_LOCK_CMD "lock -np"
+#endif
/* Minimum layout cell size, NOT including border lines. */
#define PANE_MINIMUM 1
@@ -159,7 +162,9 @@ struct winlink;
#define KEYC_IS_UNICODE(key) \
(((key) & KEYC_MASK_KEY) > 0x7f && \
(((key) & KEYC_MASK_KEY) < KEYC_BASE || \
- ((key) & KEYC_MASK_KEY) >= KEYC_BASE_END))
+ ((key) & KEYC_MASK_KEY) >= KEYC_BASE_END) && \
+ (((key) & KEYC_MASK_KEY) < KEYC_USER || \
+ ((key) & KEYC_MASK_KEY) >= KEYC_USER + KEYC_NUSER))
/* Multiple click timeout. */
#define KEYC_CLICK_TIMEOUT 300
@@ -1063,6 +1068,7 @@ struct window_pane {
#define PANE_STATUSDRAWN 0x400
#define PANE_EMPTY 0x800
#define PANE_STYLECHANGED 0x1000
+#define PANE_UNSEENCHANGES 0x2000
int argc;
char **argv;
@@ -2312,12 +2318,12 @@ void tty_margin_off(struct tty *);
void tty_cursor(struct tty *, u_int, u_int);
void tty_clipboard_query(struct tty *);
void tty_putcode(struct tty *, enum tty_code_code);
-void tty_putcode1(struct tty *, enum tty_code_code, int);
-void tty_putcode2(struct tty *, enum tty_code_code, int, int);
-void tty_putcode3(struct tty *, enum tty_code_code, int, int, int);
-void tty_putcode_ptr1(struct tty *, enum tty_code_code, const void *);
-void tty_putcode_ptr2(struct tty *, enum tty_code_code, const void *,
- const void *);
+void tty_putcode_i(struct tty *, enum tty_code_code, int);
+void tty_putcode_ii(struct tty *, enum tty_code_code, int, int);
+void tty_putcode_iii(struct tty *, enum tty_code_code, int, int, int);
+void tty_putcode_s(struct tty *, enum tty_code_code, const char *);
+void tty_putcode_ss(struct tty *, enum tty_code_code, const char *,
+ const char *);
void tty_puts(struct tty *, const char *);
void tty_putc(struct tty *, u_char);
void tty_putn(struct tty *, const void *, size_t, u_int);
@@ -2383,15 +2389,15 @@ int tty_term_read_list(const char *, int, char ***, u_int *,
void tty_term_free_list(char **, u_int);
int tty_term_has(struct tty_term *, enum tty_code_code);
const char *tty_term_string(struct tty_term *, enum tty_code_code);
-const char *tty_term_string1(struct tty_term *, enum tty_code_code, int);
-const char *tty_term_string2(struct tty_term *, enum tty_code_code, int,
+const char *tty_term_string_i(struct tty_term *, enum tty_code_code, int);
+const char *tty_term_string_ii(struct tty_term *, enum tty_code_code, int,
int);
-const char *tty_term_string3(struct tty_term *, enum tty_code_code, int,
+const char *tty_term_string_iii(struct tty_term *, enum tty_code_code, int,
int, int);
-const char *tty_term_ptr1(struct tty_term *, enum tty_code_code,
- const void *);
-const char *tty_term_ptr2(struct tty_term *, enum tty_code_code,
- const void *, const void *);
+const char *tty_term_string_s(struct tty_term *, enum tty_code_code,
+ const char *);
+const char *tty_term_string_ss(struct tty_term *, enum tty_code_code,
+ const char *, const char *);
int tty_term_number(struct tty_term *, enum tty_code_code);
int tty_term_flag(struct tty_term *, enum tty_code_code);
const char *tty_term_describe(struct tty_term *, enum tty_code_code);
diff --git a/tty-keys.c b/tty-keys.c
index 03e91f96..2801914f 100644
--- a/tty-keys.c
+++ b/tty-keys.c
@@ -1008,7 +1008,8 @@ tty_keys_extended_key(struct tty *tty, const char *buf, size_t len,
/*
* Handle mouse key input. Returns 0 for success, -1 for failure, 1 for partial
- * (probably a mouse sequence but need more data).
+ * (probably a mouse sequence but need more data), -2 if an invalid mouse
+ * sequence.
*/
static int
tty_keys_mouse(struct tty *tty, const char *buf, size_t len, size_t *size,
@@ -1069,7 +1070,7 @@ tty_keys_mouse(struct tty *tty, const char *buf, size_t len, size_t *size,
if (b < MOUSE_PARAM_BTN_OFF ||
x < MOUSE_PARAM_POS_OFF ||
y < MOUSE_PARAM_POS_OFF)
- return (-1);
+ return (-2);
b -= MOUSE_PARAM_BTN_OFF;
x -= MOUSE_PARAM_POS_OFF;
y -= MOUSE_PARAM_POS_OFF;
@@ -1111,7 +1112,7 @@ tty_keys_mouse(struct tty *tty, const char *buf, size_t len, size_t *size,
/* Check and return the mouse input. */
if (x < 1 || y < 1)
- return (-1);
+ return (-2);
x--;
y--;
b = sgr_b;
diff --git a/tty-term.c b/tty-term.c
index 4e9b7799..7dbcfee7 100644
--- a/tty-term.c
+++ b/tty-term.c
@@ -766,35 +766,100 @@ tty_term_string(struct tty_term *term, enum tty_code_code code)
}
const char *
-tty_term_string1(struct tty_term *term, enum tty_code_code code, int a)
+tty_term_string_i(struct tty_term *term, enum tty_code_code code, int a)
{
- return (tparm((char *) tty_term_string(term, code), a, 0, 0, 0, 0, 0, 0, 0, 0));
+ const char *x = tty_term_string(term, code), *s;
+
+#if defined(HAVE_TIPARM_S)
+ s = tiparm_s(1, 0, x, a);
+#elif defined(HAVE_TIPARM)
+ s = tiparm(x, a);
+#else
+ s = tparm((char *)x, a, 0, 0, 0, 0, 0, 0, 0, 0);
+#endif
+ if (s == NULL) {
+ log_debug("could not expand %s", tty_term_codes[code].name);
+ return ("");
+ }
+ return (s);
}
const char *
-tty_term_string2(struct tty_term *term, enum tty_code_code code, int a, int b)
+tty_term_string_ii(struct tty_term *term, enum tty_code_code code, int a, int b)
{
- return (tparm((char *) tty_term_string(term, code), a, b, 0, 0, 0, 0, 0, 0, 0));
+ const char *x = tty_term_string(term, code), *s;
+
+#if defined(HAVE_TIPARM_S)
+ s = tiparm_s(2, 0, x, a, b);
+#elif defined(HAVE_TIPARM)
+ s = tiparm(x, a, b);
+#else
+ s = tparm((char *)x, a, b, 0, 0, 0, 0, 0, 0, 0);
+#endif
+ if (s == NULL) {
+ log_debug("could not expand %s", tty_term_codes[code].name);
+ return ("");
+ }
+ return (s);
}
const char *
-tty_term_string3(struct tty_term *term, enum tty_code_code code, int a, int b,
- int c)
+tty_term_string_iii(struct tty_term *term, enum tty_code_code code, int a,
+ int b, int c)
{
- return (tparm((char *) tty_term_string(term, code), a, b, c, 0, 0, 0, 0, 0, 0));
+ const char *x = tty_term_string(term, code), *s;
+
+#if defined(HAVE_TIPARM_S)
+ s = tiparm_s(3, 0, x, a, b, c);
+#elif defined(HAVE_TIPARM)
+ s = tiparm(x, a, b, c);
+#else
+ s = tparm((char *)x, a, b, c, 0, 0, 0, 0, 0, 0);
+#endif
+ if (s == NULL) {
+ log_debug("could not expand %s", tty_term_codes[code].name);
+ return ("");
+ }
+ return (s);
}
const char *
-tty_term_ptr1(struct tty_term *term, enum tty_code_code code, const void *a)
+tty_term_string_s(struct tty_term *term, enum tty_code_code code, const char *a)
{
- return (tparm((char *) tty_term_string(term, code), (long)a, 0, 0, 0, 0, 0, 0, 0, 0));
+ const char *x = tty_term_string(term, code), *s;
+
+#if defined(HAVE_TIPARM_S)
+ s = tiparm_s(1, 1, x, a);
+#elif defined(HAVE_TIPARM)
+ s = tiparm(x, a);
+#else
+ s = tparm((char *)x, (long)a, 0, 0, 0, 0, 0, 0, 0, 0);
+#endif
+ if (s == NULL) {
+ log_debug("could not expand %s", tty_term_codes[code].name);
+ return ("");
+ }
+ return (s);
}
const char *
-tty_term_ptr2(struct tty_term *term, enum tty_code_code code, const void *a,
- const void *b)
+tty_term_string_ss(struct tty_term *term, enum tty_code_code code,
+ const char *a, const char *b)
{
- return (tparm((char *) tty_term_string(term, code), (long)a, (long)b, 0, 0, 0, 0, 0, 0, 0));
+ const char *x = tty_term_string(term, code), *s;
+
+#if defined(HAVE_TIPARM_S)
+ s = tiparm_s(2, 3, x, a, b);
+#elif defined(HAVE_TIPARM)
+ s = tiparm(x, a, b);
+#else
+ s = tparm((char *)x, (long)a, (long)b, 0, 0, 0, 0, 0, 0, 0);
+#endif
+ if (s == NULL) {
+ log_debug("could not expand %s", tty_term_codes[code].name);
+ return ("");
+ }
+ return (s);
}
int
diff --git a/tty.c b/tty.c
index 0428f4ae..4c5c43b3 100644
--- a/tty.c
+++ b/tty.c
@@ -34,8 +34,6 @@
static int tty_log_fd = -1;
-static int tty_client_ready(struct client *);
-
static void tty_set_italics(struct tty *);
static int tty_try_colour(struct tty *, int, const char *);
static void tty_force_cursor_colour(struct tty *, int);
@@ -407,7 +405,7 @@ tty_stop_tty(struct tty *tty)
if (tcsetattr(c->fd, TCSANOW, &tty->tio) == -1)
return;
- tty_raw(tty, tty_term_string2(tty->term, TTYC_CSR, 0, ws.ws_row - 1));
+ tty_raw(tty, tty_term_string_ii(tty->term, TTYC_CSR, 0, ws.ws_row - 1));
if (tty_acs_needed(tty))
tty_raw(tty, tty_term_string(tty->term, TTYC_RMACS));
tty_raw(tty, tty_term_string(tty->term, TTYC_SGR0));
@@ -417,7 +415,7 @@ tty_stop_tty(struct tty *tty)
if (tty_term_has(tty->term, TTYC_SE))
tty_raw(tty, tty_term_string(tty->term, TTYC_SE));
else if (tty_term_has(tty->term, TTYC_SS))
- tty_raw(tty, tty_term_string1(tty->term, TTYC_SS, 0));
+ tty_raw(tty, tty_term_string_i(tty->term, TTYC_SS, 0));
}
if (tty->ccolour != -1)
tty_raw(tty, tty_term_string(tty->term, TTYC_CR));
@@ -484,6 +482,8 @@ tty_update_features(struct tty *tty)
tty_puts(tty, tty_term_string(tty->term, TTYC_ENFCS));
if (tty->term->flags & TERM_VT100LIKE)
tty_puts(tty, "\033[?7727h");
+
+ tty_invalidate(tty);
}
void
@@ -514,42 +514,42 @@ tty_putcode(struct tty *tty, enum tty_code_code code)
}
void
-tty_putcode1(struct tty *tty, enum tty_code_code code, int a)
+tty_putcode_i(struct tty *tty, enum tty_code_code code, int a)
{
if (a < 0)
return;
- tty_puts(tty, tty_term_string1(tty->term, code, a));
+ tty_puts(tty, tty_term_string_i(tty->term, code, a));
}
void
-tty_putcode2(struct tty *tty, enum tty_code_code code, int a, int b)
+tty_putcode_ii(struct tty *tty, enum tty_code_code code, int a, int b)
{
if (a < 0 || b < 0)
return;
- tty_puts(tty, tty_term_string2(tty->term, code, a, b));
+ tty_puts(tty, tty_term_string_ii(tty->term, code, a, b));
}
void
-tty_putcode3(struct tty *tty, enum tty_code_code code, int a, int b, int c)
+tty_putcode_iii(struct tty *tty, enum tty_code_code code, int a, int b, int c)
{
if (a < 0 || b < 0 || c < 0)
return;
- tty_puts(tty, tty_term_string3(tty->term, code, a, b, c));
+ tty_puts(tty, tty_term_string_iii(tty->term, code, a, b, c));
}
void
-tty_putcode_ptr1(struct tty *tty, enum tty_code_code code, const void *a)
+tty_putcode_s(struct tty *tty, enum tty_code_code code, const char *a)
{
if (a != NULL)
- tty_puts(tty, tty_term_ptr1(tty->term, code, a));
+ tty_puts(tty, tty_term_string_s(tty->term, code, a));
}
void
-tty_putcode_ptr2(struct tty *tty, enum tty_code_code code, const void *a,
- const void *b)
+tty_putcode_ss(struct tty *tty, enum tty_code_code code, const char *a,
+ const char *b)
{
if (a != NULL && b != NULL)
- tty_puts(tty, tty_term_ptr2(tty->term, code, a, b));
+ tty_puts(tty, tty_term_string_ss(tty->term, code, a, b));
}
static void
@@ -611,7 +611,7 @@ tty_putc(struct tty *tty, u_char ch)
* it works on sensible terminals as well.
*/
if (tty->term->flags & TERM_NOAM)
- tty_putcode2(tty, TTYC_CUP, tty->cy, tty->cx);
+ tty_putcode_ii(tty, TTYC_CUP, tty->cy, tty->cx);
} else
tty->cx++;
}
@@ -690,7 +690,7 @@ tty_force_cursor_colour(struct tty *tty, int c)
else {
colour_split_rgb(c, &r, &g, &b);
xsnprintf(s, sizeof s, "rgb:%02hhx/%02hhx/%02hhx", r, g, b);
- tty_putcode_ptr1(tty, TTYC_CS, s);
+ tty_putcode_s(tty, TTYC_CS, s);
}
tty->ccolour = c;
}
@@ -751,7 +751,7 @@ tty_update_cursor(struct tty *tty, int mode, struct screen *s)
if (tty_term_has(tty->term, TTYC_SE))
tty_putcode(tty, TTYC_SE);
else
- tty_putcode1(tty, TTYC_SS, 0);
+ tty_putcode_i(tty, TTYC_SS, 0);
}
if (cmode & (MODE_CURSOR_BLINKING|MODE_CURSOR_VERY_VISIBLE))
tty_putcode(tty, TTYC_CVVIS);
@@ -759,27 +759,27 @@ tty_update_cursor(struct tty *tty, int mode, struct screen *s)
case SCREEN_CURSOR_BLOCK:
if (tty_term_has(tty->term, TTYC_SS)) {
if (cmode & MODE_CURSOR_BLINKING)
- tty_putcode1(tty, TTYC_SS, 1);
+ tty_putcode_i(tty, TTYC_SS, 1);
else
- tty_putcode1(tty, TTYC_SS, 2);
+ tty_putcode_i(tty, TTYC_SS, 2);
} else if (cmode & MODE_CURSOR_BLINKING)
tty_putcode(tty, TTYC_CVVIS);
break;
case SCREEN_CURSOR_UNDERLINE:
if (tty_term_has(tty->term, TTYC_SS)) {
if (cmode & MODE_CURSOR_BLINKING)
- tty_putcode1(tty, TTYC_SS, 3);
+ tty_putcode_i(tty, TTYC_SS, 3);
else
- tty_putcode1(tty, TTYC_SS, 4);
+ tty_putcode_i(tty, TTYC_SS, 4);
} else if (cmode & MODE_CURSOR_BLINKING)
tty_putcode(tty, TTYC_CVVIS);
break;
case SCREEN_CURSOR_BAR:
if (tty_term_has(tty->term, TTYC_SS)) {
if (cmode & MODE_CURSOR_BLINKING)
- tty_putcode1(tty, TTYC_SS, 5);
+ tty_putcode_i(tty, TTYC_SS, 5);
else
- tty_putcode1(tty, TTYC_SS, 6);
+ tty_putcode_i(tty, TTYC_SS, 6);
} else if (cmode & MODE_CURSOR_BLINKING)
tty_putcode(tty, TTYC_CVVIS);
break;
@@ -835,7 +835,7 @@ tty_emulate_repeat(struct tty *tty, enum tty_code_code code,
enum tty_code_code code1, u_int n)
{
if (tty_term_has(tty->term, code))
- tty_putcode1(tty, code, n);