Skip to content

Commit 12a720d

Browse files
committed
svn update
1 parent fb52d25 commit 12a720d

12 files changed

+187
-25
lines changed

TODO

+1
Original file line numberDiff line numberDiff line change
@@ -145,6 +145,7 @@
145145
- flag to switch-client to switch all clients
146146
- history of layouts and undo/redo flags to selectl
147147
- way to tag a layout as a number/name
148+
- optimize pane redraws, [email protected]
148149
* We need a tmux terminfo entry to document the extensions we are using in
149150
upstream terminfo. Must NOT change (only add or remove) anything from
150151
TERM=screen so we can fallback!

client.c

+6-5
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
*/
1818

1919
#include <sys/types.h>
20+
#include <sys/file.h>
2021
#include <sys/socket.h>
2122
#include <sys/stat.h>
2223
#include <sys/un.h>
@@ -252,11 +253,6 @@ client_send_identify(int flags)
252253
strlcpy(data.term, term, sizeof data.term) >= sizeof data.term)
253254
*data.term = '\0';
254255

255-
if ((fd = dup(STDIN_FILENO)) == -1)
256-
fatal("dup failed");
257-
imsg_compose(&client_ibuf,
258-
MSG_IDENTIFY, PROTOCOL_VERSION, -1, fd, &data, sizeof data);
259-
260256
if ((fd = dup(STDOUT_FILENO)) == -1)
261257
fatal("dup failed");
262258
imsg_compose(&client_ibuf,
@@ -266,6 +262,11 @@ client_send_identify(int flags)
266262
fatal("dup failed");
267263
imsg_compose(&client_ibuf,
268264
MSG_STDERR, PROTOCOL_VERSION, -1, fd, NULL, 0);
265+
266+
if ((fd = dup(STDIN_FILENO)) == -1)
267+
fatal("dup failed");
268+
imsg_compose(&client_ibuf,
269+
MSG_IDENTIFY, PROTOCOL_VERSION, -1, fd, &data, sizeof data);
269270
}
270271

271272
/* Forward entire environment to server. */

cmd-find-window.c

+46-6
Original file line numberDiff line numberDiff line change
@@ -29,13 +29,25 @@
2929

3030
int cmd_find_window_exec(struct cmd *, struct cmd_ctx *);
3131

32+
u_int cmd_find_window_match_flags(struct args *);
3233
void cmd_find_window_callback(void *, int);
3334
void cmd_find_window_free(void *);
3435

36+
/* Flags for determining matching behavior. */
37+
#define CMD_FIND_WINDOW_BY_TITLE 0x1
38+
#define CMD_FIND_WINDOW_BY_CONTENT 0x2
39+
#define CMD_FIND_WINDOW_BY_NAME 0x4
40+
41+
#define CMD_FIND_WINDOW_ALL \
42+
(CMD_FIND_WINDOW_BY_TITLE | \
43+
CMD_FIND_WINDOW_BY_CONTENT | \
44+
CMD_FIND_WINDOW_BY_NAME)
45+
46+
3547
const struct cmd_entry cmd_find_window_entry = {
3648
"find-window", "findw",
37-
"t:", 1, 1,
38-
CMD_TARGET_WINDOW_USAGE " match-string",
49+
"CNt:T", 1, 4,
50+
"[-CNT] " CMD_TARGET_WINDOW_USAGE " match-string",
3951
0,
4052
NULL,
4153
NULL,
@@ -46,6 +58,26 @@ struct cmd_find_window_data {
4658
struct session *session;
4759
};
4860

61+
u_int
62+
cmd_find_window_match_flags(struct args *args)
63+
{
64+
u_int match_flags = 0;
65+
66+
/* Turn on flags based on the options. */
67+
if (args_has(args, 'T'))
68+
match_flags |= CMD_FIND_WINDOW_BY_TITLE;
69+
if (args_has(args, 'C'))
70+
match_flags |= CMD_FIND_WINDOW_BY_CONTENT;
71+
if (args_has(args, 'N'))
72+
match_flags |= CMD_FIND_WINDOW_BY_NAME;
73+
74+
/* If none of the flags were set, default to matching anything. */
75+
if (match_flags == 0)
76+
match_flags = CMD_FIND_WINDOW_ALL;
77+
78+
return match_flags;
79+
}
80+
4981
int
5082
cmd_find_window_exec(struct cmd *self, struct cmd_ctx *ctx)
5183
{
@@ -58,7 +90,7 @@ cmd_find_window_exec(struct cmd *self, struct cmd_ctx *ctx)
5890
ARRAY_DECL(, u_int) list_idx;
5991
ARRAY_DECL(, char *) list_ctx;
6092
char *str, *sres, *sctx, *searchstr;
61-
u_int i, line;
93+
u_int i, line, match_flags;
6294

6395
if (ctx->curclient == NULL) {
6496
ctx->error(ctx, "must be run interactively");
@@ -69,6 +101,7 @@ cmd_find_window_exec(struct cmd *self, struct cmd_ctx *ctx)
69101
if ((wl = cmd_find_window(ctx, args_get(args, 't'), NULL)) == NULL)
70102
return (-1);
71103

104+
match_flags = cmd_find_window_match_flags(args);
72105
str = args->argv[0];
73106

74107
ARRAY_INIT(&list_idx);
@@ -80,12 +113,19 @@ cmd_find_window_exec(struct cmd *self, struct cmd_ctx *ctx)
80113
TAILQ_FOREACH(wp, &wm->window->panes, entry) {
81114
i++;
82115

83-
if (fnmatch(searchstr, wm->window->name, 0) == 0)
116+
if ((match_flags & CMD_FIND_WINDOW_BY_NAME) &&
117+
fnmatch(searchstr, wm->window->name, 0) == 0)
84118
sctx = xstrdup("");
85119
else {
86-
sres = window_pane_search(wp, str, &line);
120+
sres = NULL;
121+
if (match_flags & CMD_FIND_WINDOW_BY_CONTENT) {
122+
sres = window_pane_search(
123+
wp, str, &line);
124+
}
125+
87126
if (sres == NULL &&
88-
fnmatch(searchstr, wp->base.title, 0) != 0)
127+
(!(match_flags & CMD_FIND_WINDOW_BY_TITLE) ||
128+
fnmatch(searchstr, wp->base.title, 0) != 0))
89129
continue;
90130

91131
if (sres == NULL) {

cmd-save-buffer.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ int cmd_save_buffer_exec(struct cmd *, struct cmd_ctx *);
3333
const struct cmd_entry cmd_save_buffer_entry = {
3434
"save-buffer", "saveb",
3535
"ab:", 1, 1,
36-
"[-a] " CMD_BUFFER_USAGE,
36+
"[-a] " CMD_BUFFER_USAGE " path",
3737
0,
3838
NULL,
3939
NULL,

cmd-show-environment.c

+15-2
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,8 @@ int cmd_show_environment_exec(struct cmd *, struct cmd_ctx *);
3131

3232
const struct cmd_entry cmd_show_environment_entry = {
3333
"show-environment", "showenv",
34-
"gt:", 0, 0,
35-
"[-g] " CMD_TARGET_SESSION_USAGE,
34+
"gt:", 0, 1,
35+
"[-g] " CMD_TARGET_SESSION_USAGE " [name]",
3636
0,
3737
NULL,
3838
NULL,
@@ -55,6 +55,19 @@ cmd_show_environment_exec(struct cmd *self, struct cmd_ctx *ctx)
5555
env = &s->environ;
5656
}
5757

58+
if (args->argc != 0) {
59+
envent = environ_find(env, args->argv[0]);
60+
if (envent == NULL) {
61+
ctx->error(ctx, "unknown variable: %s", args->argv[0]);
62+
return (-1);
63+
}
64+
if (envent->value != NULL)
65+
ctx->print(ctx, "%s=%s", envent->name, envent->value);
66+
else
67+
ctx->print(ctx, "-%s", envent->name);
68+
return (0);
69+
}
70+
5871
RB_FOREACH(envent, environ, env) {
5972
if (envent->value != NULL)
6073
ctx->print(ctx, "%s=%s", envent->name, envent->value);

input.c

+13-3
Original file line numberDiff line numberDiff line change
@@ -908,6 +908,7 @@ input_c0_dispatch(struct input_ctx *ictx)
908908
struct screen_write_ctx *sctx = &ictx->ctx;
909909
struct window_pane *wp = ictx->wp;
910910
struct screen *s = sctx->s;
911+
u_int trigger;
911912

912913
log_debug("%s: '%c", __func__, ictx->ch);
913914

@@ -919,7 +920,7 @@ input_c0_dispatch(struct input_ctx *ictx)
919920
break;
920921
case '\010': /* BS */
921922
screen_write_backspace(sctx);
922-
break;
923+
goto count_c0;
923924
case '\011': /* HT */
924925
/* Don't tab beyond the end of the line. */
925926
if (s->cx >= screen_size_x(s) - 1)
@@ -936,10 +937,10 @@ input_c0_dispatch(struct input_ctx *ictx)
936937
case '\013': /* VT */
937938
case '\014': /* FF */
938939
screen_write_linefeed(sctx, 0);
939-
break;
940+
goto count_c0;
940941
case '\015': /* CR */
941942
screen_write_carriagereturn(sctx);
942-
break;
943+
goto count_c0;
943944
case '\016': /* SO */
944945
ictx->cell.attr |= GRID_ATTR_CHARSET;
945946
break;
@@ -951,6 +952,15 @@ input_c0_dispatch(struct input_ctx *ictx)
951952
break;
952953
}
953954

955+
return (0);
956+
957+
count_c0:
958+
trigger = options_get_number(&wp->window->options, "c0-change-trigger");
959+
if (++wp->changes == trigger) {
960+
wp->flags |= PANE_DROP;
961+
window_pane_timer_start(wp);
962+
}
963+
954964
return (0);
955965
}
956966

options-table.c

+15
Original file line numberDiff line numberDiff line change
@@ -464,6 +464,21 @@ const struct options_table_entry window_options_table[] = {
464464
.default_num = 1
465465
},
466466

467+
468+
{ .name = "c0-change-trigger",
469+
.type = OPTIONS_TABLE_NUMBER,
470+
.default_num = 250,
471+
.minimum = 0,
472+
.maximum = USHRT_MAX
473+
},
474+
475+
{ .name = "c0-change-interval",
476+
.type = OPTIONS_TABLE_NUMBER,
477+
.default_num = 100,
478+
.minimum = 1,
479+
.maximum = USHRT_MAX
480+
},
481+
467482
{ .name = "clock-mode-colour",
468483
.type = OPTIONS_TABLE_COLOUR,
469484
.default_num = 4

tmux.1

+34-2
Original file line numberDiff line numberDiff line change
@@ -1103,6 +1103,7 @@ to
11031103
.Ql 9
11041104
keys.
11051105
.It Xo Ic find-window
1106+
.Op Fl CNT
11061107
.Op Fl t Ar target-window
11071108
.Ar match-string
11081109
.Xc
@@ -1112,8 +1113,17 @@ Search for the
11121113
pattern
11131114
.Ar match-string
11141115
in window names, titles, and visible content (but not history).
1115-
If only one window is matched, it'll be automatically selected, otherwise a
1116-
choice list is shown.
1116+
The flags control matching behavior:
1117+
.Fl C
1118+
matches only visible window contents,
1119+
.Fl N
1120+
matches only the window name and
1121+
.Fl T
1122+
matches only the window title.
1123+
The default is
1124+
.Fl CNT .
1125+
If only one window is matched, it'll be automatically selected,
1126+
otherwise a choice list is shown.
11171127
This command only works from inside
11181128
.Nm .
11191129
.It Xo Ic join-pane
@@ -2467,6 +2477,24 @@ It may be switched off globally with:
24672477
set-window-option -g automatic-rename off
24682478
.Ed
24692479
.Pp
2480+
.It Ic c0-change-interval Ar interval
2481+
.It Ic c0-change-trigger Ar trigger
2482+
These two options configure a simple form of rate limiting for a pane.
2483+
If
2484+
.Nm
2485+
sees more than
2486+
.Ar trigger
2487+
C0 sequences that modify the screen (for example, carriage returns, linefeeds
2488+
or backspaces) in one millisecond, it will stop updating the pane immediately and
2489+
instead redraw it entirely every
2490+
.Ar interval
2491+
milliseconds.
2492+
This helps to prevent fast output (such as
2493+
.Xr yes 1
2494+
overwhelming the terminal).
2495+
The default is a trigger of 250 and an interval of 100.
2496+
A trigger of zero disables the rate limiting.
2497+
.Pp
24702498
.It Ic clock-mode-colour Ar colour
24712499
Set clock colour.
24722500
.Pp
@@ -2884,12 +2912,16 @@ new process.
28842912
.It Xo Ic show-environment
28852913
.Op Fl g
28862914
.Op Fl t Ar target-session
2915+
.Op Ar variable
28872916
.Xc
28882917
.D1 (alias: Ic showenv )
28892918
Display the environment for
28902919
.Ar target-session
28912920
or the global environment with
28922921
.Fl g .
2922+
If
2923+
.Ar variable
2924+
is omitted, all variables are shown.
28932925
Variables removed from the environment are prefixed with
28942926
.Ql - .
28952927
.El

tmux.h

+6-1
Original file line numberDiff line numberDiff line change
@@ -807,6 +807,7 @@ struct window_pane {
807807

808808
int flags;
809809
#define PANE_REDRAW 0x1
810+
#define PANE_DROP 0x2
810811

811812
char *cmd;
812813
char *shell;
@@ -815,6 +816,10 @@ struct window_pane {
815816
pid_t pid;
816817
char tty[TTY_NAME_MAX];
817818

819+
u_int changes;
820+
struct event changes_timer;
821+
u_int changes_redraw;
822+
818823
int fd;
819824
struct bufferevent *event;
820825

@@ -1959,6 +1964,7 @@ void window_destroy_panes(struct window *);
19591964
struct window_pane *window_pane_find_by_id(u_int);
19601965
struct window_pane *window_pane_create(struct window *, u_int, u_int, u_int);
19611966
void window_pane_destroy(struct window_pane *);
1967+
void window_pane_timer_start(struct window_pane *);
19621968
int window_pane_spawn(struct window_pane *, const char *,
19631969
const char *, const char *, struct environ *,
19641970
struct termios *, char **);
@@ -1977,7 +1983,6 @@ int window_pane_visible(struct window_pane *);
19771983
char *window_pane_search(
19781984
struct window_pane *, const char *, u_int *);
19791985
char *window_printable_flags(struct session *, struct winlink *);
1980-
19811986
struct window_pane *window_pane_find_up(struct window_pane *);
19821987
struct window_pane *window_pane_find_down(struct window_pane *);
19831988
struct window_pane *window_pane_find_left(struct window_pane *);

tty-keys.c

+8-4
Original file line numberDiff line numberDiff line change
@@ -686,9 +686,9 @@ tty_keys_device(struct tty *tty, const char *buf, size_t len, size_t *size)
686686
char tmp[64], *endptr;
687687

688688
/*
689-
* Secondary device attributes are \033[>a;b;c. We only request
690-
* attributes on xterm, so we only care about the middle values which
691-
* is the xterm version.
689+
* Primary device attributes are \033[?a;b and secondary are
690+
* \033[>a;b;c. We only request attributes on xterm, so we only care
691+
* about the middle values which is the xterm version.
692692
*/
693693

694694
*size = 0;
@@ -702,7 +702,7 @@ tty_keys_device(struct tty *tty, const char *buf, size_t len, size_t *size)
702702
return (-1);
703703
if (len == 2)
704704
return (1);
705-
if (buf[2] != '>')
705+
if (buf[2] != '>' && buf[2] != '?')
706706
return (-1);
707707
if (len == 3)
708708
return (1);
@@ -718,6 +718,10 @@ tty_keys_device(struct tty *tty, const char *buf, size_t len, size_t *size)
718718
tmp[i] = '\0';
719719
*size = 4 + i;
720720

721+
/* Only secondary is of interest. */
722+
if (buf[2] != '>')
723+
return (0);
724+
721725
/* Convert version numbers. */
722726
a = strtoul(tmp, &endptr, 10);
723727
if (*endptr == ';') {

tty.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -661,7 +661,7 @@ tty_write(
661661

662662
if (wp->window->flags & WINDOW_REDRAW || wp->flags & PANE_REDRAW)
663663
return;
664-
if (!window_pane_visible(wp))
664+
if (!window_pane_visible(wp) || wp->flags & PANE_DROP)
665665
return;
666666

667667
for (i = 0; i < ARRAY_LENGTH(&clients); i++) {

0 commit comments

Comments
 (0)