mirror of
				https://github.com/tmux/tmux.git
				synced 2025-11-04 01:34:18 +00:00 
			
		
		
		
	Make the prompt history global for all clients which is much more useful than per-client history.
This commit is contained in:
		@@ -70,8 +70,6 @@ server_client_create(int fd)
 | 
				
			|||||||
		fatal("gettimeofday failed");
 | 
							fatal("gettimeofday failed");
 | 
				
			||||||
	memcpy(&c->activity_time, &c->creation_time, sizeof c->activity_time);
 | 
						memcpy(&c->activity_time, &c->creation_time, sizeof c->activity_time);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	ARRAY_INIT(&c->prompt_hdata);
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
	c->stdin_event = NULL;
 | 
						c->stdin_event = NULL;
 | 
				
			||||||
	c->stdout_event = NULL;
 | 
						c->stdout_event = NULL;
 | 
				
			||||||
	c->stderr_event = NULL;
 | 
						c->stderr_event = NULL;
 | 
				
			||||||
@@ -161,9 +159,6 @@ server_client_lost(struct client *c)
 | 
				
			|||||||
		xfree(c->prompt_string);
 | 
							xfree(c->prompt_string);
 | 
				
			||||||
	if (c->prompt_buffer != NULL)
 | 
						if (c->prompt_buffer != NULL)
 | 
				
			||||||
		xfree(c->prompt_buffer);
 | 
							xfree(c->prompt_buffer);
 | 
				
			||||||
	for (i = 0; i < ARRAY_LENGTH(&c->prompt_hdata); i++)
 | 
					 | 
				
			||||||
		xfree(ARRAY_ITEM(&c->prompt_hdata, i));
 | 
					 | 
				
			||||||
	ARRAY_FREE(&c->prompt_hdata);
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
	if (c->cwd != NULL)
 | 
						if (c->cwd != NULL)
 | 
				
			||||||
		xfree(c->cwd);
 | 
							xfree(c->cwd);
 | 
				
			||||||
 
 | 
				
			|||||||
							
								
								
									
										88
									
								
								status.c
									
									
									
									
									
								
							
							
						
						
									
										88
									
								
								status.c
									
									
									
									
									
								
							@@ -41,9 +41,14 @@ void	status_replace1(struct client *,
 | 
				
			|||||||
	    struct winlink *, char **, char **, char *, size_t, int);
 | 
						    struct winlink *, char **, char **, char *, size_t, int);
 | 
				
			||||||
void	status_message_callback(int, short, void *);
 | 
					void	status_message_callback(int, short, void *);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
void	status_prompt_add_history(struct client *);
 | 
					const char *status_prompt_up_history(u_int *);
 | 
				
			||||||
 | 
					const char *status_prompt_down_history(u_int *);
 | 
				
			||||||
 | 
					void	status_prompt_add_history(const char *);
 | 
				
			||||||
char   *status_prompt_complete(const char *);
 | 
					char   *status_prompt_complete(const char *);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					/* Status prompt history. */
 | 
				
			||||||
 | 
					ARRAY_DECL(, char *) status_prompt_history = ARRAY_INITIALIZER;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
/* Retrieve options for left string. */
 | 
					/* Retrieve options for left string. */
 | 
				
			||||||
char *
 | 
					char *
 | 
				
			||||||
status_redraw_get_left(struct client *c,
 | 
					status_redraw_get_left(struct client *c,
 | 
				
			||||||
@@ -972,29 +977,20 @@ status_prompt_key(struct client *c, int key)
 | 
				
			|||||||
		}
 | 
							}
 | 
				
			||||||
		break;
 | 
							break;
 | 
				
			||||||
	case MODEKEYEDIT_HISTORYUP:
 | 
						case MODEKEYEDIT_HISTORYUP:
 | 
				
			||||||
		if (ARRAY_LENGTH(&c->prompt_hdata) == 0)
 | 
							s = status_prompt_up_history(&c->prompt_hindex);
 | 
				
			||||||
 | 
							if (s == NULL)
 | 
				
			||||||
			break;
 | 
								break;
 | 
				
			||||||
	       	xfree(c->prompt_buffer);
 | 
						       	xfree(c->prompt_buffer);
 | 
				
			||||||
 | 
							c->prompt_buffer = xstrdup(s);
 | 
				
			||||||
		c->prompt_buffer = xstrdup(ARRAY_ITEM(&c->prompt_hdata,
 | 
					 | 
				
			||||||
		    ARRAY_LENGTH(&c->prompt_hdata) - 1 - c->prompt_hindex));
 | 
					 | 
				
			||||||
		if (c->prompt_hindex != ARRAY_LENGTH(&c->prompt_hdata) - 1)
 | 
					 | 
				
			||||||
			c->prompt_hindex++;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
		c->prompt_index = strlen(c->prompt_buffer);
 | 
							c->prompt_index = strlen(c->prompt_buffer);
 | 
				
			||||||
		c->flags |= CLIENT_STATUS;
 | 
							c->flags |= CLIENT_STATUS;
 | 
				
			||||||
		break;
 | 
							break;
 | 
				
			||||||
	case MODEKEYEDIT_HISTORYDOWN:
 | 
						case MODEKEYEDIT_HISTORYDOWN:
 | 
				
			||||||
 | 
							s = status_prompt_down_history(&c->prompt_hindex);
 | 
				
			||||||
 | 
							if (s == NULL)
 | 
				
			||||||
 | 
								break;
 | 
				
			||||||
		xfree(c->prompt_buffer);
 | 
							xfree(c->prompt_buffer);
 | 
				
			||||||
 | 
							c->prompt_buffer = xstrdup(s);
 | 
				
			||||||
		if (c->prompt_hindex != 0) {
 | 
					 | 
				
			||||||
			c->prompt_hindex--;
 | 
					 | 
				
			||||||
			c->prompt_buffer = xstrdup(ARRAY_ITEM(
 | 
					 | 
				
			||||||
			    &c->prompt_hdata, ARRAY_LENGTH(
 | 
					 | 
				
			||||||
			    &c->prompt_hdata) - 1 - c->prompt_hindex));
 | 
					 | 
				
			||||||
		} else
 | 
					 | 
				
			||||||
			c->prompt_buffer = xstrdup("");
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
		c->prompt_index = strlen(c->prompt_buffer);
 | 
							c->prompt_index = strlen(c->prompt_buffer);
 | 
				
			||||||
		c->flags |= CLIENT_STATUS;
 | 
							c->flags |= CLIENT_STATUS;
 | 
				
			||||||
		break;
 | 
							break;
 | 
				
			||||||
@@ -1036,7 +1032,7 @@ status_prompt_key(struct client *c, int key)
 | 
				
			|||||||
		break;
 | 
							break;
 | 
				
			||||||
	case MODEKEYEDIT_ENTER:
 | 
						case MODEKEYEDIT_ENTER:
 | 
				
			||||||
		if (*c->prompt_buffer != '\0')
 | 
							if (*c->prompt_buffer != '\0')
 | 
				
			||||||
			status_prompt_add_history(c);
 | 
								status_prompt_add_history(c->prompt_buffer);
 | 
				
			||||||
		if (c->prompt_callbackfn(c->prompt_data, c->prompt_buffer) == 0)
 | 
							if (c->prompt_callbackfn(c->prompt_data, c->prompt_buffer) == 0)
 | 
				
			||||||
			status_prompt_clear(c);
 | 
								status_prompt_clear(c);
 | 
				
			||||||
		break;
 | 
							break;
 | 
				
			||||||
@@ -1072,20 +1068,56 @@ status_prompt_key(struct client *c, int key)
 | 
				
			|||||||
	}
 | 
						}
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
/* Add line to the history. */
 | 
					/* Get previous line from the history. */
 | 
				
			||||||
void
 | 
					const char *
 | 
				
			||||||
status_prompt_add_history(struct client *c)
 | 
					status_prompt_up_history(u_int *idx)
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
	if (ARRAY_LENGTH(&c->prompt_hdata) > 0 &&
 | 
						u_int size;
 | 
				
			||||||
	    strcmp(ARRAY_LAST(&c->prompt_hdata), c->prompt_buffer) == 0)
 | 
					 | 
				
			||||||
		return;
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
	if (ARRAY_LENGTH(&c->prompt_hdata) == PROMPT_HISTORY) {
 | 
						/*
 | 
				
			||||||
		xfree(ARRAY_FIRST(&c->prompt_hdata));
 | 
						 * History runs from 0 to size - 1.
 | 
				
			||||||
		ARRAY_REMOVE(&c->prompt_hdata, 0);
 | 
						 *
 | 
				
			||||||
 | 
						 * Index is from 0 to size. Zero is empty.
 | 
				
			||||||
 | 
						 */
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						size = ARRAY_LENGTH(&status_prompt_history);
 | 
				
			||||||
 | 
						if (size == 0 || *idx == size)
 | 
				
			||||||
 | 
							return (NULL);
 | 
				
			||||||
 | 
						(*idx)++;
 | 
				
			||||||
 | 
						return (ARRAY_ITEM(&status_prompt_history, size - *idx));
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	ARRAY_ADD(&c->prompt_hdata, xstrdup(c->prompt_buffer));
 | 
					/* Get next line from the history. */
 | 
				
			||||||
 | 
					const char *
 | 
				
			||||||
 | 
					status_prompt_down_history(u_int *idx)
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
 | 
						u_int size;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						size = ARRAY_LENGTH(&status_prompt_history);
 | 
				
			||||||
 | 
						if (size == 0 || *idx == 0)
 | 
				
			||||||
 | 
							return ("");
 | 
				
			||||||
 | 
						(*idx)--;
 | 
				
			||||||
 | 
						if (*idx == 0)
 | 
				
			||||||
 | 
							return ("");
 | 
				
			||||||
 | 
						return (ARRAY_ITEM(&status_prompt_history, size - *idx));
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					/* Add line to the history. */
 | 
				
			||||||
 | 
					void
 | 
				
			||||||
 | 
					status_prompt_add_history(const char *line)
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
 | 
						u_int size;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						size = ARRAY_LENGTH(&status_prompt_history);
 | 
				
			||||||
 | 
						if (size > 0 && strcmp(ARRAY_LAST(&status_prompt_history), line) == 0)
 | 
				
			||||||
 | 
							return;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						if (size == PROMPT_HISTORY) {
 | 
				
			||||||
 | 
							xfree(ARRAY_FIRST(&status_prompt_history));
 | 
				
			||||||
 | 
							ARRAY_REMOVE(&status_prompt_history, 0);
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						ARRAY_ADD(&status_prompt_history, xstrdup(line));
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
/* Complete word. */
 | 
					/* Complete word. */
 | 
				
			||||||
 
 | 
				
			|||||||
							
								
								
									
										4
									
								
								tmux.h
									
									
									
									
									
								
							
							
						
						
									
										4
									
								
								tmux.h
									
									
									
									
									
								
							@@ -1147,13 +1147,11 @@ struct client {
 | 
				
			|||||||
	int		 (*prompt_callbackfn)(void *, const char *);
 | 
						int		 (*prompt_callbackfn)(void *, const char *);
 | 
				
			||||||
	void		 (*prompt_freefn)(void *);
 | 
						void		 (*prompt_freefn)(void *);
 | 
				
			||||||
	void		*prompt_data;
 | 
						void		*prompt_data;
 | 
				
			||||||
 | 
						u_int            prompt_hindex;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
#define PROMPT_SINGLE 0x1
 | 
					#define PROMPT_SINGLE 0x1
 | 
				
			||||||
	int		 prompt_flags;
 | 
						int		 prompt_flags;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	u_int		 prompt_hindex;
 | 
					 | 
				
			||||||
	ARRAY_DECL(, char *) prompt_hdata;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
	struct mode_key_data prompt_mdata;
 | 
						struct mode_key_data prompt_mdata;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	struct session	*session;
 | 
						struct session	*session;
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user