mirror of
https://github.com/tmux/tmux.git
synced 2026-10-06 17:49:52 +00:00
Add a parser for a subset of JSON, will be used for new layout strings
(and maybe some other stuff), from Dane Jensen.
This commit is contained in:
3
Makefile
3
Makefile
@@ -1,4 +1,4 @@
|
|||||||
# $OpenBSD: Makefile,v 1.122 2026/08/01 17:04:12 miod Exp $
|
# $OpenBSD: Makefile,v 1.123 2026/09/08 08:33:10 nicm Exp $
|
||||||
|
|
||||||
PROG= tmux
|
PROG= tmux
|
||||||
SRCS= alerts.c \
|
SRCS= alerts.c \
|
||||||
@@ -89,6 +89,7 @@ SRCS= alerts.c \
|
|||||||
input-keys.c \
|
input-keys.c \
|
||||||
input.c \
|
input.c \
|
||||||
job.c \
|
job.c \
|
||||||
|
json.c \
|
||||||
key-bindings.c \
|
key-bindings.c \
|
||||||
key-string.c \
|
key-string.c \
|
||||||
layout-custom.c \
|
layout-custom.c \
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
/* $OpenBSD: cmd-display-message.c,v 1.65 2026/02/23 08:46:57 nicm Exp $ */
|
/* $OpenBSD: cmd-display-message.c,v 1.66 2026/09/08 08:33:10 nicm Exp $ */
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Copyright (c) 2009 Tiago Cunha <me@tiagocunha.org>
|
* Copyright (c) 2009 Tiago Cunha <me@tiagocunha.org>
|
||||||
@@ -39,8 +39,8 @@ const struct cmd_entry cmd_display_message_entry = {
|
|||||||
.name = "display-message",
|
.name = "display-message",
|
||||||
.alias = "display",
|
.alias = "display",
|
||||||
|
|
||||||
.args = { "aCc:d:lINpt:F:v", 0, 1, NULL },
|
.args = { "aCc:d:jlINpt:F:v", 0, 1, NULL },
|
||||||
.usage = "[-aCIlNpv] [-c target-client] [-d delay] [-F format] "
|
.usage = "[-aCIjlNpv] [-c target-client] [-d delay] [-F format] "
|
||||||
CMD_TARGET_PANE_USAGE " [message]",
|
CMD_TARGET_PANE_USAGE " [message]",
|
||||||
|
|
||||||
.target = { 't', CMD_FIND_PANE, CMD_FIND_CANFAIL },
|
.target = { 't', CMD_FIND_PANE, CMD_FIND_CANFAIL },
|
||||||
@@ -67,14 +67,15 @@ cmd_display_message_exec(struct cmd *self, struct cmdq_item *item)
|
|||||||
struct winlink *wl = target->wl;
|
struct winlink *wl = target->wl;
|
||||||
struct window_pane *wp = target->wp;
|
struct window_pane *wp = target->wp;
|
||||||
const char *template;
|
const char *template;
|
||||||
char *msg, *cause;
|
char *msg, *cause = NULL;
|
||||||
int delay = -1, flags, Nflag = args_has(args, 'N');
|
int delay = -1, flags, Nflag = args_has(args, 'N');
|
||||||
int Cflag = args_has(args, 'C');
|
int Cflag = args_has(args, 'C');
|
||||||
struct format_tree *ft;
|
struct format_tree *ft;
|
||||||
u_int count = args_count(args);
|
u_int count = args_count(args);
|
||||||
struct evbuffer *evb;
|
struct evbuffer *evb;
|
||||||
|
struct json_node *jn;
|
||||||
|
|
||||||
if (args_has(args, 'I')) {
|
if (args_has(args, 'I') && !args_has(args, 'j')) {
|
||||||
if (wp == NULL)
|
if (wp == NULL)
|
||||||
return (CMD_RETURN_NORMAL);
|
return (CMD_RETURN_NORMAL);
|
||||||
switch (window_pane_start_input(wp, item, &cause)) {
|
switch (window_pane_start_input(wp, item, &cause)) {
|
||||||
@@ -107,7 +108,9 @@ cmd_display_message_exec(struct cmd *self, struct cmdq_item *item)
|
|||||||
template = args_string(args, 0);
|
template = args_string(args, 0);
|
||||||
else
|
else
|
||||||
template = args_get(args, 'F');
|
template = args_get(args, 'F');
|
||||||
if (template == NULL)
|
if (args_has(args, 'j') && template == NULL)
|
||||||
|
template = "";
|
||||||
|
else if (template == NULL)
|
||||||
template = DISPLAY_MESSAGE_TEMPLATE;
|
template = DISPLAY_MESSAGE_TEMPLATE;
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@@ -129,7 +132,7 @@ cmd_display_message_exec(struct cmd *self, struct cmdq_item *item)
|
|||||||
ft = format_create(cmdq_get_client(item), item, FORMAT_NONE, flags);
|
ft = format_create(cmdq_get_client(item), item, FORMAT_NONE, flags);
|
||||||
format_defaults(ft, c, s, wl, wp);
|
format_defaults(ft, c, s, wl, wp);
|
||||||
|
|
||||||
if (args_has(args, 'a')) {
|
if (args_has(args, 'a') && !args_has(args, 'j')) {
|
||||||
format_each(ft, cmd_display_message_each, item);
|
format_each(ft, cmd_display_message_each, item);
|
||||||
format_free(ft);
|
format_free(ft);
|
||||||
return (CMD_RETURN_NORMAL);
|
return (CMD_RETURN_NORMAL);
|
||||||
@@ -139,6 +142,19 @@ cmd_display_message_exec(struct cmd *self, struct cmdq_item *item)
|
|||||||
msg = xstrdup(template);
|
msg = xstrdup(template);
|
||||||
else
|
else
|
||||||
msg = format_expand_time(ft, template);
|
msg = format_expand_time(ft, template);
|
||||||
|
if (args_has(args, 'j')) {
|
||||||
|
jn = json_parse(msg, &cause);
|
||||||
|
if (jn == NULL) {
|
||||||
|
cmdq_error(item, "%s", cause);
|
||||||
|
free(cause);
|
||||||
|
free(msg);
|
||||||
|
format_free(ft);
|
||||||
|
return (CMD_RETURN_ERROR);
|
||||||
|
}
|
||||||
|
free(msg);
|
||||||
|
msg = json_to_string(jn);
|
||||||
|
json_destroy_node(jn);
|
||||||
|
}
|
||||||
|
|
||||||
if (cmdq_get_client(item) == NULL)
|
if (cmdq_get_client(item) == NULL)
|
||||||
cmdq_error(item, "%s", msg);
|
cmdq_error(item, "%s", msg);
|
||||||
|
|||||||
10
tmux.1
10
tmux.1
@@ -1,4 +1,4 @@
|
|||||||
.\" $OpenBSD: tmux.1,v 1.1165 2026/09/08 07:31:59 nicm Exp $
|
.\" $OpenBSD: tmux.1,v 1.1166 2026/09/08 08:33:10 nicm Exp $
|
||||||
.\"
|
.\"
|
||||||
.\" Copyright (c) 2007 Nicholas Marriott <nicholas.marriott@gmail.com>
|
.\" Copyright (c) 2007 Nicholas Marriott <nicholas.marriott@gmail.com>
|
||||||
.\"
|
.\"
|
||||||
@@ -8277,7 +8277,7 @@ The following keys are available in menus:
|
|||||||
.El
|
.El
|
||||||
.Tg display
|
.Tg display
|
||||||
.It Xo Ic display\-message
|
.It Xo Ic display\-message
|
||||||
.Op Fl aCIlNpv
|
.Op Fl aCIjlNpv
|
||||||
.Op Fl c Ar target\-client
|
.Op Fl c Ar target\-client
|
||||||
.Op Fl d Ar delay
|
.Op Fl d Ar delay
|
||||||
.Op Fl t Ar target\-pane
|
.Op Fl t Ar target\-pane
|
||||||
@@ -8317,6 +8317,12 @@ if
|
|||||||
.Fl t
|
.Fl t
|
||||||
is given, otherwise the active pane.
|
is given, otherwise the active pane.
|
||||||
.Pp
|
.Pp
|
||||||
|
If
|
||||||
|
.Fl j
|
||||||
|
is given,
|
||||||
|
.Ar message
|
||||||
|
is parsed as JSON and printed.
|
||||||
|
.Pp
|
||||||
.Fl v
|
.Fl v
|
||||||
prints verbose logging as the format is parsed and
|
prints verbose logging as the format is parsed and
|
||||||
.Fl a
|
.Fl a
|
||||||
|
|||||||
28
tmux.h
28
tmux.h
@@ -1,4 +1,4 @@
|
|||||||
/* $OpenBSD: tmux.h,v 1.1433 2026/09/01 12:49:49 nicm Exp $ */
|
/* $OpenBSD: tmux.h,v 1.1434 2026/09/08 08:33:10 nicm Exp $ */
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Copyright (c) 2007 Nicholas Marriott <nicholas.marriott@gmail.com>
|
* Copyright (c) 2007 Nicholas Marriott <nicholas.marriott@gmail.com>
|
||||||
@@ -59,6 +59,7 @@ struct input_ctx;
|
|||||||
struct input_request;
|
struct input_request;
|
||||||
struct input_requests;
|
struct input_requests;
|
||||||
struct job;
|
struct job;
|
||||||
|
struct json_node;
|
||||||
struct menu_data;
|
struct menu_data;
|
||||||
struct mode_tree_data;
|
struct mode_tree_data;
|
||||||
struct mouse_event;
|
struct mouse_event;
|
||||||
@@ -4200,4 +4201,29 @@ struct hyperlinks *hyperlinks_copy(struct hyperlinks *);
|
|||||||
void hyperlinks_reset(struct hyperlinks *);
|
void hyperlinks_reset(struct hyperlinks *);
|
||||||
void hyperlinks_free(struct hyperlinks *);
|
void hyperlinks_free(struct hyperlinks *);
|
||||||
|
|
||||||
|
/* json.c */
|
||||||
|
struct json_node *json_parse(const char *, char **);
|
||||||
|
void json_destroy_node(struct json_node *);
|
||||||
|
char *json_to_string(struct json_node *);
|
||||||
|
struct json_node *json_find(struct json_node *, const char *);
|
||||||
|
struct json_node *json_array_first(struct json_node *);
|
||||||
|
struct json_node *json_array_next(struct json_node *);
|
||||||
|
int json_get_string(struct json_node *, const char **);
|
||||||
|
int json_get_number(struct json_node *, int64_t *);
|
||||||
|
int json_get_boolean(struct json_node *, int *);
|
||||||
|
int json_get_object(struct json_node *,
|
||||||
|
struct json_node **);
|
||||||
|
int json_get_array(struct json_node *,
|
||||||
|
struct json_node **);
|
||||||
|
int json_find_string(struct json_node *, const char *,
|
||||||
|
const char **, char **);
|
||||||
|
int json_find_number(struct json_node *, const char *,
|
||||||
|
int64_t *, char **);
|
||||||
|
int json_find_boolean(struct json_node *, const char *,
|
||||||
|
int *, char **);
|
||||||
|
int json_find_object(struct json_node *, const char *,
|
||||||
|
struct json_node **, char **);
|
||||||
|
int json_find_array(struct json_node *, const char *,
|
||||||
|
struct json_node **, char **);
|
||||||
|
|
||||||
#endif /* TMUX_H */
|
#endif /* TMUX_H */
|
||||||
|
|||||||
Reference in New Issue
Block a user