mirror of
				https://github.com/tmux/tmux.git
				synced 2025-10-26 12:27:15 +00:00 
			
		
		
		
	Add format variables for the default formats for the various modes
(tree_mode_format and so on) and add a -a flag to display-message to list variables with values.
This commit is contained in:
		| @@ -39,8 +39,8 @@ const struct cmd_entry cmd_display_message_entry = { | |||||||
| 	.name = "display-message", | 	.name = "display-message", | ||||||
| 	.alias = "display", | 	.alias = "display", | ||||||
|  |  | ||||||
| 	.args = { "c:pt:F:v", 0, 1 }, | 	.args = { "ac:pt:F:v", 0, 1 }, | ||||||
| 	.usage = "[-pv] [-c target-client] [-F format] " | 	.usage = "[-apv] [-c target-client] [-F format] " | ||||||
| 		 CMD_TARGET_PANE_USAGE " [message]", | 		 CMD_TARGET_PANE_USAGE " [message]", | ||||||
|  |  | ||||||
| 	.target = { 't', CMD_FIND_PANE, 0 }, | 	.target = { 't', CMD_FIND_PANE, 0 }, | ||||||
| @@ -49,6 +49,14 @@ const struct cmd_entry cmd_display_message_entry = { | |||||||
| 	.exec = cmd_display_message_exec | 	.exec = cmd_display_message_exec | ||||||
| }; | }; | ||||||
|  |  | ||||||
|  | static void | ||||||
|  | cmd_display_message_each(const char *key, const char *value, void *arg) | ||||||
|  | { | ||||||
|  | 	struct cmdq_item	*item = arg; | ||||||
|  |  | ||||||
|  | 	cmdq_print(item, "%s=%s", key, value); | ||||||
|  | } | ||||||
|  |  | ||||||
| static enum cmd_retval | static enum cmd_retval | ||||||
| cmd_display_message_exec(struct cmd *self, struct cmdq_item *item) | cmd_display_message_exec(struct cmd *self, struct cmdq_item *item) | ||||||
| { | { | ||||||
| @@ -91,6 +99,12 @@ cmd_display_message_exec(struct cmd *self, struct cmdq_item *item) | |||||||
| 	ft = format_create(item->client, item, FORMAT_NONE, flags); | 	ft = format_create(item->client, item, FORMAT_NONE, flags); | ||||||
| 	format_defaults(ft, target_c, s, wl, wp); | 	format_defaults(ft, target_c, s, wl, wp); | ||||||
|  |  | ||||||
|  | 	if (args_has(args, 'a')) { | ||||||
|  | 		if (item != NULL) | ||||||
|  | 			format_each(ft, cmd_display_message_each, item); | ||||||
|  | 		return (CMD_RETURN_NORMAL); | ||||||
|  | 	} | ||||||
|  |  | ||||||
| 	msg = format_expand_time(ft, template); | 	msg = format_expand_time(ft, template); | ||||||
| 	if (args_has(self->args, 'p')) | 	if (args_has(self->args, 'p')) | ||||||
| 		cmdq_print(item, "%s", msg); | 		cmdq_print(item, "%s", msg); | ||||||
|   | |||||||
							
								
								
									
										36
									
								
								format.c
									
									
									
									
									
								
							
							
						
						
									
										36
									
								
								format.c
									
									
									
									
									
								
							| @@ -701,7 +701,9 @@ format_merge(struct format_tree *ft, struct format_tree *from) | |||||||
| struct format_tree * | struct format_tree * | ||||||
| format_create(struct client *c, struct cmdq_item *item, int tag, int flags) | format_create(struct client *c, struct cmdq_item *item, int tag, int flags) | ||||||
| { | { | ||||||
| 	struct format_tree	*ft; | 	struct format_tree		 *ft; | ||||||
|  | 	const struct window_mode	**wm; | ||||||
|  | 	char				  tmp[64]; | ||||||
|  |  | ||||||
| 	if (!event_initialized(&format_job_event)) { | 	if (!event_initialized(&format_job_event)) { | ||||||
| 		evtimer_set(&format_job_event, format_job_timer, NULL); | 		evtimer_set(&format_job_event, format_job_timer, NULL); | ||||||
| @@ -727,6 +729,14 @@ format_create(struct client *c, struct cmdq_item *item, int tag, int flags) | |||||||
| 	format_add(ft, "socket_path", "%s", socket_path); | 	format_add(ft, "socket_path", "%s", socket_path); | ||||||
| 	format_add_tv(ft, "start_time", &start_time); | 	format_add_tv(ft, "start_time", &start_time); | ||||||
|  |  | ||||||
|  | 	for (wm = all_window_modes; *wm != NULL; wm++) { | ||||||
|  | 		if ((*wm)->default_format != NULL) { | ||||||
|  | 			xsnprintf(tmp, sizeof tmp, "%s_format", (*wm)->name); | ||||||
|  | 			tmp[strcspn(tmp, "-")] = '_'; | ||||||
|  | 			format_add(ft, tmp, "%s", (*wm)->default_format); | ||||||
|  | 		} | ||||||
|  | 	} | ||||||
|  |  | ||||||
| 	if (item != NULL) { | 	if (item != NULL) { | ||||||
| 		if (item->cmd != NULL) | 		if (item->cmd != NULL) | ||||||
| 			format_add(ft, "command", "%s", item->cmd->entry->name); | 			format_add(ft, "command", "%s", item->cmd->entry->name); | ||||||
| @@ -755,6 +765,30 @@ format_free(struct format_tree *ft) | |||||||
| 	free(ft); | 	free(ft); | ||||||
| } | } | ||||||
|  |  | ||||||
|  | /* Walk each format. */ | ||||||
|  | void | ||||||
|  | format_each(struct format_tree *ft, void (*cb)(const char *, const char *, | ||||||
|  |     void *), void *arg) | ||||||
|  | { | ||||||
|  | 	struct format_entry	*fe; | ||||||
|  | 	static char		 s[64]; | ||||||
|  |  | ||||||
|  | 	RB_FOREACH(fe, format_entry_tree, &ft->tree) { | ||||||
|  | 		if (fe->t != 0) { | ||||||
|  | 			xsnprintf(s, sizeof s, "%lld", (long long)fe->t); | ||||||
|  | 			cb(fe->key, fe->value, s); | ||||||
|  | 		} else { | ||||||
|  | 			if (fe->value == NULL && fe->cb != NULL) { | ||||||
|  | 				fe->cb(ft, fe); | ||||||
|  | 				if (fe->value == NULL) | ||||||
|  | 					fe->value = xstrdup(""); | ||||||
|  | 			} | ||||||
|  | 			cb(fe->key, fe->value, arg); | ||||||
|  | 		} | ||||||
|  | 	} | ||||||
|  | } | ||||||
|  |  | ||||||
|  |  | ||||||
| /* Add a key-value pair. */ | /* Add a key-value pair. */ | ||||||
| void | void | ||||||
| format_add(struct format_tree *ft, const char *key, const char *fmt, ...) | format_add(struct format_tree *ft, const char *key, const char *fmt, ...) | ||||||
|   | |||||||
							
								
								
									
										9
									
								
								tmux.1
									
									
									
									
									
								
							
							
						
						
									
										9
									
								
								tmux.1
									
									
									
									
									
								
							| @@ -4177,7 +4177,7 @@ option. | |||||||
| This command works only from inside | This command works only from inside | ||||||
| .Nm . | .Nm . | ||||||
| .It Xo Ic display-message | .It Xo Ic display-message | ||||||
| .Op Fl pv | .Op Fl apv | ||||||
| .Op Fl c Ar target-client | .Op Fl c Ar target-client | ||||||
| .Op Fl t Ar target-pane | .Op Fl t Ar target-pane | ||||||
| .Op Ar message | .Op Ar message | ||||||
| @@ -4200,9 +4200,10 @@ if | |||||||
| is given, otherwise the active pane for the session attached to | is given, otherwise the active pane for the session attached to | ||||||
| .Ar target-client . | .Ar target-client . | ||||||
| .Pp | .Pp | ||||||
| With | .Fl v | ||||||
| .Fl v , | prints verbose logging as the format is parsed and | ||||||
| verbose logging is printed as the format is parsed. | .Fl a | ||||||
|  | lists the format variables and their values. | ||||||
| .El | .El | ||||||
| .Sh BUFFERS | .Sh BUFFERS | ||||||
| .Nm | .Nm | ||||||
|   | |||||||
							
								
								
									
										4
									
								
								tmux.h
									
									
									
									
									
								
							
							
						
						
									
										4
									
								
								tmux.h
									
									
									
									
									
								
							| @@ -704,6 +704,7 @@ struct screen_write_ctx { | |||||||
| struct window_mode_entry; | struct window_mode_entry; | ||||||
| struct window_mode { | struct window_mode { | ||||||
| 	const char	*name; | 	const char	*name; | ||||||
|  | 	const char	*default_format; | ||||||
|  |  | ||||||
| 	struct screen	*(*init)(struct window_mode_entry *, | 	struct screen	*(*init)(struct window_mode_entry *, | ||||||
| 			     struct cmd_find_state *, struct args *); | 			     struct cmd_find_state *, struct args *); | ||||||
| @@ -1587,6 +1588,8 @@ struct format_tree *format_create(struct client *, struct cmdq_item *, int, | |||||||
| void		 format_free(struct format_tree *); | void		 format_free(struct format_tree *); | ||||||
| void printflike(3, 4) format_add(struct format_tree *, const char *, | void printflike(3, 4) format_add(struct format_tree *, const char *, | ||||||
| 		     const char *, ...); | 		     const char *, ...); | ||||||
|  | void		 format_each(struct format_tree *, void (*)(const char *, | ||||||
|  | 		     const char *, void *), void *); | ||||||
| char		*format_expand_time(struct format_tree *, const char *); | char		*format_expand_time(struct format_tree *, const char *); | ||||||
| char		*format_expand(struct format_tree *, const char *); | char		*format_expand(struct format_tree *, const char *); | ||||||
| char		*format_single(struct cmdq_item *, const char *, | char		*format_single(struct cmdq_item *, const char *, | ||||||
| @@ -2156,6 +2159,7 @@ void	 screen_select_cell(struct screen *, struct grid_cell *, | |||||||
| /* window.c */ | /* window.c */ | ||||||
| extern struct windows windows; | extern struct windows windows; | ||||||
| extern struct window_pane_tree all_window_panes; | extern struct window_pane_tree all_window_panes; | ||||||
|  | extern const struct window_mode *all_window_modes[]; | ||||||
| int		 window_cmp(struct window *, struct window *); | int		 window_cmp(struct window *, struct window *); | ||||||
| RB_PROTOTYPE(windows, window, entry, window_cmp); | RB_PROTOTYPE(windows, window, entry, window_cmp); | ||||||
| int		 winlink_cmp(struct winlink *, struct winlink *); | int		 winlink_cmp(struct winlink *, struct winlink *); | ||||||
|   | |||||||
| @@ -41,6 +41,7 @@ static void		 window_buffer_key(struct window_mode_entry *, | |||||||
|  |  | ||||||
| const struct window_mode window_buffer_mode = { | const struct window_mode window_buffer_mode = { | ||||||
| 	.name = "buffer-mode", | 	.name = "buffer-mode", | ||||||
|  | 	.default_format = WINDOW_BUFFER_DEFAULT_FORMAT, | ||||||
|  |  | ||||||
| 	.init = window_buffer_init, | 	.init = window_buffer_init, | ||||||
| 	.free = window_buffer_free, | 	.free = window_buffer_free, | ||||||
|   | |||||||
| @@ -42,6 +42,7 @@ static void		 window_client_key(struct window_mode_entry *, | |||||||
|  |  | ||||||
| const struct window_mode window_client_mode = { | const struct window_mode window_client_mode = { | ||||||
| 	.name = "client-mode", | 	.name = "client-mode", | ||||||
|  | 	.default_format = WINDOW_CLIENT_DEFAULT_FORMAT, | ||||||
|  |  | ||||||
| 	.init = window_client_init, | 	.init = window_client_init, | ||||||
| 	.free = window_client_free, | 	.free = window_client_free, | ||||||
|   | |||||||
| @@ -55,6 +55,7 @@ static void		 window_tree_key(struct window_mode_entry *, | |||||||
|  |  | ||||||
| const struct window_mode window_tree_mode = { | const struct window_mode window_tree_mode = { | ||||||
| 	.name = "tree-mode", | 	.name = "tree-mode", | ||||||
|  | 	.default_format = WINDOW_TREE_DEFAULT_FORMAT, | ||||||
|  |  | ||||||
| 	.init = window_tree_init, | 	.init = window_tree_init, | ||||||
| 	.free = window_tree_free, | 	.free = window_tree_free, | ||||||
|   | |||||||
							
								
								
									
										11
									
								
								window.c
									
									
									
									
									
								
							
							
						
						
									
										11
									
								
								window.c
									
									
									
									
									
								
							| @@ -62,6 +62,17 @@ static u_int	next_window_pane_id; | |||||||
| static u_int	next_window_id; | static u_int	next_window_id; | ||||||
| static u_int	next_active_point; | static u_int	next_active_point; | ||||||
|  |  | ||||||
|  | /* List of window modes. */ | ||||||
|  | const struct window_mode *all_window_modes[] = { | ||||||
|  | 	&window_buffer_mode, | ||||||
|  | 	&window_client_mode, | ||||||
|  | 	&window_clock_mode, | ||||||
|  | 	&window_copy_mode, | ||||||
|  | 	&window_tree_mode, | ||||||
|  | 	&window_view_mode, | ||||||
|  | 	NULL | ||||||
|  | }; | ||||||
|  |  | ||||||
| static void	window_destroy(struct window *); | static void	window_destroy(struct window *); | ||||||
|  |  | ||||||
| static struct window_pane *window_pane_create(struct window *, u_int, u_int, | static struct window_pane *window_pane_create(struct window *, u_int, u_int, | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user
	 nicm
					nicm