1
0
mirror of https://github.com/tmate-io/tmate-ssh-server.git synced 2020-11-18 19:53:51 -08:00

Add -q flags to shut up errors to capture-pane and show-options, from George

Nachman.
This commit is contained in:
Nicholas Marriott 2013-03-04 09:00:24 +00:00
parent 208881a735
commit 1cb1fb5bd4
3 changed files with 70 additions and 53 deletions

View File

@ -31,8 +31,8 @@ enum cmd_retval cmd_capture_pane_exec(struct cmd *, struct cmd_q *);
const struct cmd_entry cmd_capture_pane_entry = { const struct cmd_entry cmd_capture_pane_entry = {
"capture-pane", "capturep", "capture-pane", "capturep",
"ab:CeE:JpS:t:", 0, 0, "ab:CeE:JpqS:t:", 0, 0,
"[-aCeJp] [-b buffer-index] [-E end-line] [-S start-line]" "[-aCeJpq] [-b buffer-index] [-E end-line] [-S start-line]"
CMD_TARGET_PANE_USAGE, CMD_TARGET_PANE_USAGE,
0, 0,
NULL, NULL,
@ -62,7 +62,7 @@ cmd_capture_pane_exec(struct cmd *self, struct cmd_q *cmdq)
s = NULL; s = NULL;
gd = wp->saved_grid; gd = wp->saved_grid;
sx = screen_size_x(&wp->base); sx = screen_size_x(&wp->base);
if (gd == NULL) { if (gd == NULL && !args_has(args, 'q')) {
cmdq_error(cmdq, "no alternate screen"); cmdq_error(cmdq, "no alternate screen");
return (CMD_RETURN_ERROR); return (CMD_RETURN_ERROR);
} }
@ -75,54 +75,57 @@ cmd_capture_pane_exec(struct cmd *self, struct cmd_q *cmdq)
buf = NULL; buf = NULL;
len = 0; len = 0;
n = args_strtonum(args, 'S', INT_MIN, SHRT_MAX, &cause); if (gd != NULL) {
if (cause != NULL) { n = args_strtonum(args, 'S', INT_MIN, SHRT_MAX, &cause);
top = gd->hsize; if (cause != NULL) {
free(cause); top = gd->hsize;
} else if (n < 0 && (u_int) -n > gd->hsize) free(cause);
top = 0; } else if (n < 0 && (u_int) -n > gd->hsize)
else top = 0;
top = gd->hsize + n; else
if (top > gd->hsize + gd->sy - 1) top = gd->hsize + n;
top = gd->hsize + gd->sy - 1; if (top > gd->hsize + gd->sy - 1)
top = gd->hsize + gd->sy - 1;
n = args_strtonum(args, 'E', INT_MIN, SHRT_MAX, &cause); n = args_strtonum(args, 'E', INT_MIN, SHRT_MAX, &cause);
if (cause != NULL) { if (cause != NULL) {
bottom = gd->hsize + gd->sy - 1; bottom = gd->hsize + gd->sy - 1;
free(cause); free(cause);
} else if (n < 0 && (u_int) -n > gd->hsize) } else if (n < 0 && (u_int) -n > gd->hsize)
bottom = 0; bottom = 0;
else else
bottom = gd->hsize + n; bottom = gd->hsize + n;
if (bottom > gd->hsize + gd->sy - 1) if (bottom > gd->hsize + gd->sy - 1)
bottom = gd->hsize + gd->sy - 1; bottom = gd->hsize + gd->sy - 1;
if (bottom < top) { if (bottom < top) {
tmp = bottom; tmp = bottom;
bottom = top; bottom = top;
top = tmp; top = tmp;
} }
with_codes = args_has(args, 'e'); with_codes = args_has(args, 'e');
escape_c0 = args_has(args, 'C'); escape_c0 = args_has(args, 'C');
join_lines = args_has(args, 'J'); join_lines = args_has(args, 'J');
gc = NULL; gc = NULL;
for (i = top; i <= bottom; i++) { for (i = top; i <= bottom; i++) {
line = grid_string_cells(gd, 0, i, sx, &gc, with_codes, line = grid_string_cells(gd, 0, i, sx, &gc, with_codes,
escape_c0); escape_c0);
linelen = strlen(line); linelen = strlen(line);
buf = xrealloc(buf, 1, len + linelen + 1); buf = xrealloc(buf, 1, len + linelen + 1);
memcpy(buf + len, line, linelen); memcpy(buf + len, line, linelen);
len += linelen; len += linelen;
gl = grid_peek_line(gd, i); gl = grid_peek_line(gd, i);
if (!join_lines || !(gl->flags & GRID_LINE_WRAPPED)) if (!join_lines || !(gl->flags & GRID_LINE_WRAPPED))
buf[len++] = '\n'; buf[len++] = '\n';
free(line); free(line);
} }
} else
buf = xstrdup("");
if (args_has(args, 'p')) { if (args_has(args, 'p')) {
c = cmdq->client; c = cmdq->client;

View File

@ -30,14 +30,14 @@
enum cmd_retval cmd_show_options_exec(struct cmd *, struct cmd_q *); enum cmd_retval cmd_show_options_exec(struct cmd *, struct cmd_q *);
enum cmd_retval cmd_show_options_one(struct cmd *, struct cmd_q *, enum cmd_retval cmd_show_options_one(struct cmd *, struct cmd_q *,
struct options *); struct options *, int);
enum cmd_retval cmd_show_options_all(struct cmd *, struct cmd_q *, enum cmd_retval cmd_show_options_all(struct cmd *, struct cmd_q *,
const struct options_table_entry *, struct options *); const struct options_table_entry *, struct options *);
const struct cmd_entry cmd_show_options_entry = { const struct cmd_entry cmd_show_options_entry = {
"show-options", "show", "show-options", "show",
"gst:vw", 0, 1, "gqst:vw", 0, 1,
"[-gsvw] [-t target-session|target-window] [option]", "[-gqsvw] [-t target-session|target-window] [option]",
0, 0,
NULL, NULL,
NULL, NULL,
@ -62,6 +62,7 @@ cmd_show_options_exec(struct cmd *self, struct cmd_q *cmdq)
struct winlink *wl; struct winlink *wl;
const struct options_table_entry *table; const struct options_table_entry *table;
struct options *oo; struct options *oo;
int quiet;
if (args_has(self->args, 's')) { if (args_has(self->args, 's')) {
oo = &global_options; oo = &global_options;
@ -89,15 +90,16 @@ cmd_show_options_exec(struct cmd *self, struct cmd_q *cmdq)
} }
} }
if (args->argc != 0) quiet = args_has(self->args, 'q');
return (cmd_show_options_one(self, cmdq, oo)); if (args->argc == 0)
else
return (cmd_show_options_all(self, cmdq, table, oo)); return (cmd_show_options_all(self, cmdq, table, oo));
else
return (cmd_show_options_one(self, cmdq, oo, quiet));
} }
enum cmd_retval enum cmd_retval
cmd_show_options_one(struct cmd *self, struct cmd_q *cmdq, cmd_show_options_one(struct cmd *self, struct cmd_q *cmdq,
struct options *oo) struct options *oo, int quiet)
{ {
struct args *args = self->args; struct args *args = self->args;
const struct options_table_entry *table, *oe; const struct options_table_entry *table, *oe;
@ -106,6 +108,8 @@ cmd_show_options_one(struct cmd *self, struct cmd_q *cmdq,
if (*args->argv[0] == '@') { if (*args->argv[0] == '@') {
if ((o = options_find1(oo, args->argv[0])) == NULL) { if ((o = options_find1(oo, args->argv[0])) == NULL) {
if (quiet)
return (CMD_RETURN_NORMAL);
cmdq_error(cmdq, "unknown option: %s", args->argv[0]); cmdq_error(cmdq, "unknown option: %s", args->argv[0]);
return (CMD_RETURN_ERROR); return (CMD_RETURN_ERROR);
} }
@ -122,6 +126,8 @@ cmd_show_options_one(struct cmd *self, struct cmd_q *cmdq,
return (CMD_RETURN_ERROR); return (CMD_RETURN_ERROR);
} }
if (oe == NULL) { if (oe == NULL) {
if (quiet)
return (CMD_RETURN_NORMAL);
cmdq_error(cmdq, "unknown option: %s", args->argv[0]); cmdq_error(cmdq, "unknown option: %s", args->argv[0]);
return (CMD_RETURN_ERROR); return (CMD_RETURN_ERROR);
} }

12
tmux.1
View File

@ -1066,7 +1066,7 @@ By default, it uses the format
but a different format may be specified with but a different format may be specified with
.Fl F . .Fl F .
.It Xo Ic capture-pane .It Xo Ic capture-pane
.Op Fl aep .Op Fl aepq
.Op Fl b Ar buffer-index .Op Fl b Ar buffer-index
.Op Fl E Ar end-line .Op Fl E Ar end-line
.Op Fl S Ar start-line .Op Fl S Ar start-line
@ -1082,6 +1082,9 @@ or a new buffer if omitted.
If If
.Fl a .Fl a
is given, the alternate screen is used, and the history is not accessible. is given, the alternate screen is used, and the history is not accessible.
If no alternate screen exists, an error will be returned unless
.Fl q
is given.
If If
.Fl e .Fl e
is given, the output includes escape sequences for text and background is given, the output includes escape sequences for text and background
@ -2952,7 +2955,7 @@ If this option is set, searches will wrap around the end of the pane contents.
The default is on. The default is on.
.El .El
.It Xo Ic show-options .It Xo Ic show-options
.Op Fl gsvw .Op Fl gqsvw
.Op Fl t Ar target-session | Ar target-window .Op Fl t Ar target-session | Ar target-window
.Op Ar option .Op Ar option
.Xc .Xc
@ -2970,6 +2973,11 @@ Global session or window options are listed if
is used. is used.
.Fl v .Fl v
shows only the option value, not the name. shows only the option value, not the name.
If
.Fl q
is set, no error will be returned if
.Ar option
is unset.
.It Xo Ic show-window-options .It Xo Ic show-window-options
.Op Fl gv .Op Fl gv
.Op Fl t Ar target-window .Op Fl t Ar target-window