version 1.22, 2020/11/26 13:06:21 |
version 1.23, 2021/03/02 10:56:45 |
|
|
|
|
#include <sys/types.h> |
#include <sys/types.h> |
|
|
|
#include <paths.h> |
#include <stdlib.h> |
#include <stdlib.h> |
#include <string.h> |
#include <string.h> |
|
|
|
|
.name = "display-popup", |
.name = "display-popup", |
.alias = "popup", |
.alias = "popup", |
|
|
.args = { "CEKc:d:h:R:t:w:x:y:", 0, -1 }, |
.args = { "Cc:d:Eh:t:w:x:y:", 0, -1 }, |
.usage = "[-CEK] [-c target-client] [-d start-directory] [-h height] " |
.usage = "[-CE] [-c target-client] [-d start-directory] [-h height] " |
"[-R shell-command] " CMD_TARGET_PANE_USAGE " [-w width] " |
CMD_TARGET_PANE_USAGE " [-w width] " |
"[-x position] [-y position] [command line ...]", |
"[-x position] [-y position] [command]", |
|
|
.target = { 't', CMD_FIND_PANE, 0 }, |
.target = { 't', CMD_FIND_PANE, 0 }, |
|
|
|
|
{ |
{ |
struct args *args = cmd_get_args(self); |
struct args *args = cmd_get_args(self); |
struct cmd_find_state *target = cmdq_get_target(item); |
struct cmd_find_state *target = cmdq_get_target(item); |
|
struct session *s = target->s; |
struct client *tc = cmdq_get_target_client(item); |
struct client *tc = cmdq_get_target_client(item); |
struct tty *tty = &tc->tty; |
struct tty *tty = &tc->tty; |
const char *value, *cmd = NULL, **lines = NULL; |
const char *value, *shell[] = { NULL, NULL }; |
const char *shellcmd = NULL; |
const char *shellcmd = NULL; |
char *cwd, *cause; |
char *cwd, *cause, **argv = args->argv; |
int flags = 0; |
int flags = 0, argc = args->argc; |
u_int px, py, w, h, nlines = 0; |
u_int px, py, w, h; |
|
|
if (args_has(args, 'C')) { |
if (args_has(args, 'C')) { |
server_client_clear_overlay(tc); |
server_client_clear_overlay(tc); |
|
|
if (tc->overlay_draw != NULL) |
if (tc->overlay_draw != NULL) |
return (CMD_RETURN_NORMAL); |
return (CMD_RETURN_NORMAL); |
|
|
if (args->argc >= 1) |
h = tty->sy / 2; |
cmd = args->argv[0]; |
|
if (args->argc >= 2) { |
|
lines = (const char **)args->argv + 1; |
|
nlines = args->argc - 1; |
|
} |
|
|
|
if (nlines != 0) |
|
h = popup_height(nlines, lines) + 2; |
|
else |
|
h = tty->sy / 2; |
|
if (args_has(args, 'h')) { |
if (args_has(args, 'h')) { |
h = args_percentage(args, 'h', 1, tty->sy, tty->sy, &cause); |
h = args_percentage(args, 'h', 1, tty->sy, tty->sy, &cause); |
if (cause != NULL) { |
if (cause != NULL) { |
|
|
} |
} |
} |
} |
|
|
if (nlines != 0) |
w = tty->sx / 2; |
w = popup_width(item, nlines, lines, tc, target) + 2; |
|
else |
|
w = tty->sx / 2; |
|
if (args_has(args, 'w')) { |
if (args_has(args, 'w')) { |
w = args_percentage(args, 'w', 1, tty->sx, tty->sx, &cause); |
w = args_percentage(args, 'w', 1, tty->sx, tty->sx, &cause); |
if (cause != NULL) { |
if (cause != NULL) { |
|
|
if (value != NULL) |
if (value != NULL) |
cwd = format_single_from_target(item, value); |
cwd = format_single_from_target(item, value); |
else |
else |
cwd = xstrdup(server_client_get_cwd(tc, target->s)); |
cwd = xstrdup(server_client_get_cwd(tc, s)); |
|
if (argc == 0) |
|
shellcmd = options_get_string(s->options, "default-command"); |
|
else if (argc == 1) |
|
shellcmd = argv[0]; |
|
if (argc <= 1 && (shellcmd == NULL || *shellcmd == '\0')) { |
|
shellcmd = NULL; |
|
shell[0] = options_get_string(s->options, "default-shell"); |
|
if (!checkshell(shell[0])) |
|
shell[0] = _PATH_BSHELL; |
|
argc = 1; |
|
argv = (char**)shell; |
|
} |
|
|
value = args_get(args, 'R'); |
|
if (value != NULL) |
|
shellcmd = format_single_from_target(item, value); |
|
|
|
if (args_has(args, 'K')) |
|
flags |= POPUP_WRITEKEYS; |
|
if (args_has(args, 'E') > 1) |
if (args_has(args, 'E') > 1) |
flags |= POPUP_CLOSEEXITZERO; |
flags |= POPUP_CLOSEEXITZERO; |
else if (args_has(args, 'E')) |
else if (args_has(args, 'E')) |
flags |= POPUP_CLOSEEXIT; |
flags |= POPUP_CLOSEEXIT; |
if (popup_display(flags, item, px, py, w, h, nlines, lines, shellcmd, |
if (popup_display(flags, item, px, py, w, h, shellcmd, argc, argv, cwd, |
cmd, cwd, tc, target, NULL, NULL) != 0) |
tc, s, NULL, NULL) != 0) |
return (CMD_RETURN_NORMAL); |
return (CMD_RETURN_NORMAL); |
return (CMD_RETURN_WAIT); |
return (CMD_RETURN_WAIT); |
} |
} |