mirror of
https://github.com/tmux/tmux.git
synced 2025-01-05 23:38:48 +00:00
Add some additional format helper functions.
This commit is contained in:
parent
e62db55713
commit
c30e765c7b
52
format.c
52
format.c
@ -2472,25 +2472,59 @@ format_single(struct cmdq_item *item, const char *fmt, struct client *c,
|
||||
struct format_tree *ft;
|
||||
char *expanded;
|
||||
|
||||
if (item != NULL)
|
||||
ft = format_create(cmdq_get_client(item), item, FORMAT_NONE, 0);
|
||||
else
|
||||
ft = format_create(NULL, item, FORMAT_NONE, 0);
|
||||
format_defaults(ft, c, s, wl, wp);
|
||||
|
||||
ft = format_create_defaults(item, c, s, wl, wp);
|
||||
expanded = format_expand(ft, fmt);
|
||||
format_free(ft);
|
||||
return (expanded);
|
||||
}
|
||||
|
||||
/* Expand a single string using state. */
|
||||
char *
|
||||
format_single_from_state(struct cmdq_item *item, const char *fmt,
|
||||
struct client *c, struct cmd_find_state *fs)
|
||||
{
|
||||
return (format_single(item, fmt, c, fs->s, fs->wl, fs->wp));
|
||||
}
|
||||
|
||||
/* Expand a single string using target. */
|
||||
char *
|
||||
format_single_from_target(struct cmdq_item *item, const char *fmt)
|
||||
{
|
||||
struct cmd_find_state *target = cmdq_get_target(item);
|
||||
struct client *tc = cmdq_get_target_client(item);
|
||||
struct client *tc = cmdq_get_target_client(item);
|
||||
|
||||
return (format_single(item, fmt, tc, target->s, target->wl, target->wp));
|
||||
return (format_single_from_state(item, fmt, tc, cmdq_get_target(item)));
|
||||
}
|
||||
|
||||
/* Create and add defaults. */
|
||||
struct format_tree *
|
||||
format_create_defaults(struct cmdq_item *item, struct client *c,
|
||||
struct session *s, struct winlink *wl, struct window_pane *wp)
|
||||
{
|
||||
struct format_tree *ft;
|
||||
|
||||
if (item != NULL)
|
||||
ft = format_create(cmdq_get_client(item), item, FORMAT_NONE, 0);
|
||||
else
|
||||
ft = format_create(NULL, item, FORMAT_NONE, 0);
|
||||
format_defaults(ft, c, s, wl, wp);
|
||||
return (ft);
|
||||
}
|
||||
|
||||
/* Create and add defaults using state. */
|
||||
struct format_tree *
|
||||
format_create_from_state(struct cmdq_item *item, struct client *c,
|
||||
struct cmd_find_state *fs)
|
||||
{
|
||||
return (format_create_defaults(item, c, fs->s, fs->wl, fs->wp));
|
||||
}
|
||||
|
||||
/* Create and add defaults using target. */
|
||||
struct format_tree *
|
||||
format_create_from_target(struct cmdq_item *item)
|
||||
{
|
||||
struct client *tc = cmdq_get_target_client(item);
|
||||
|
||||
return (format_create_from_state(item, tc, cmdq_get_target(item)));
|
||||
}
|
||||
|
||||
/* Set defaults for any of arguments that are not NULL. */
|
||||
|
4
menu.c
4
menu.c
@ -73,7 +73,7 @@ menu_add_item(struct menu *menu, const struct menu_item *item,
|
||||
return;
|
||||
|
||||
if (fs != NULL)
|
||||
s = format_single(qitem, item->name, c, fs->s, fs->wl, fs->wp);
|
||||
s = format_single_from_state(qitem, item->name, c, fs);
|
||||
else
|
||||
s = format_single(qitem, item->name, c, NULL, NULL, NULL);
|
||||
if (*s == '\0') { /* no item if empty after format expanded */
|
||||
@ -91,7 +91,7 @@ menu_add_item(struct menu *menu, const struct menu_item *item,
|
||||
cmd = item->command;
|
||||
if (cmd != NULL) {
|
||||
if (fs != NULL)
|
||||
s = format_single(qitem, cmd, c, fs->s, fs->wl, fs->wp);
|
||||
s = format_single_from_state(qitem, cmd, c, fs);
|
||||
else
|
||||
s = format_single(qitem, cmd, c, NULL, NULL, NULL);
|
||||
} else
|
||||
|
7
tmux.h
7
tmux.h
@ -1827,7 +1827,14 @@ char *format_expand(struct format_tree *, const char *);
|
||||
char *format_single(struct cmdq_item *, const char *,
|
||||
struct client *, struct session *, struct winlink *,
|
||||
struct window_pane *);
|
||||
char *format_single_from_state(struct cmdq_item *, const char *,
|
||||
struct client *, struct cmd_find_state *);
|
||||
char *format_single_from_target(struct cmdq_item *, const char *);
|
||||
struct format_tree *format_create_defaults(struct cmdq_item *, struct client *,
|
||||
struct session *, struct winlink *, struct window_pane *);
|
||||
struct format_tree *format_create_from_state(struct cmdq_item *,
|
||||
struct client *, struct cmd_find_state *);
|
||||
struct format_tree *format_create_from_target(struct cmdq_item *);
|
||||
void format_defaults(struct format_tree *, struct client *,
|
||||
struct session *, struct winlink *, struct window_pane *);
|
||||
void format_defaults_window(struct format_tree *, struct window *);
|
||||
|
Loading…
Reference in New Issue
Block a user