mirror of
				https://github.com/tmux/tmux.git
				synced 2025-11-04 09:26:05 +00:00 
			
		
		
		
	Prompt history.
This commit is contained in:
		
							
								
								
									
										6
									
								
								CHANGES
									
									
									
									
									
								
							
							
						
						
									
										6
									
								
								CHANGES
									
									
									
									
									
								
							@@ -1,6 +1,8 @@
 | 
				
			|||||||
06 January 2009
 | 
					06 January 2009
 | 
				
			||||||
 | 
					
 | 
				
			||||||
* Use a splay tree for key bindings.
 | 
					* Per-client prompt history of up to 100 items.
 | 
				
			||||||
 | 
					* Use a splay tree for key bindings instead of an array. As a side-effect this
 | 
				
			||||||
 | 
					  sorts them when listed.
 | 
				
			||||||
 | 
					
 | 
				
			||||||
22 December 2008
 | 
					22 December 2008
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@@ -796,7 +798,7 @@
 | 
				
			|||||||
  (including mutt, emacs). No status bar yet and no key remapping or other
 | 
					  (including mutt, emacs). No status bar yet and no key remapping or other
 | 
				
			||||||
  customisation.
 | 
					  customisation.
 | 
				
			||||||
 | 
					
 | 
				
			||||||
$Id: CHANGES,v 1.177 2009-01-06 14:10:32 nicm Exp $
 | 
					$Id: CHANGES,v 1.178 2009-01-06 15:37:15 nicm Exp $
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 LocalWords:  showw utf UTF fulvio ciriaco joshe OSC APC gettime abc DEF OA clr
 | 
					 LocalWords:  showw utf UTF fulvio ciriaco joshe OSC APC gettime abc DEF OA clr
 | 
				
			||||||
 LocalWords:  rivo nurges lscm Erdely eol smysession mysession ek dstname RB
 | 
					 LocalWords:  rivo nurges lscm Erdely eol smysession mysession ek dstname RB
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -1,4 +1,4 @@
 | 
				
			|||||||
/* $Id: server-fn.c,v 1.50 2008-08-28 17:45:27 nicm Exp $ */
 | 
					/* $Id: server-fn.c,v 1.51 2009-01-06 15:37:15 nicm Exp $ */
 | 
				
			||||||
 | 
					
 | 
				
			||||||
/*
 | 
					/*
 | 
				
			||||||
 * Copyright (c) 2007 Nicholas Marriott <nicm@users.sourceforge.net>
 | 
					 * Copyright (c) 2007 Nicholas Marriott <nicm@users.sourceforge.net>
 | 
				
			||||||
@@ -68,6 +68,8 @@ server_set_client_prompt(
 | 
				
			|||||||
	c->prompt_callback = fn;
 | 
						c->prompt_callback = fn;
 | 
				
			||||||
	c->prompt_data = data;
 | 
						c->prompt_data = data;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						c->prompt_hindex = 0;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	c->tty.flags |= (TTY_NOCURSOR|TTY_FREEZE);
 | 
						c->tty.flags |= (TTY_NOCURSOR|TTY_FREEZE);
 | 
				
			||||||
	c->flags |= CLIENT_STATUS;
 | 
						c->flags |= CLIENT_STATUS;
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
@@ -82,6 +84,7 @@ server_clear_client_prompt(struct client *c)
 | 
				
			|||||||
	c->prompt_string = NULL;
 | 
						c->prompt_string = NULL;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	xfree(c->prompt_buffer);
 | 
						xfree(c->prompt_buffer);
 | 
				
			||||||
 | 
						c->prompt_buffer = NULL;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	c->tty.flags &= ~(TTY_NOCURSOR|TTY_FREEZE);
 | 
						c->tty.flags &= ~(TTY_NOCURSOR|TTY_FREEZE);
 | 
				
			||||||
	c->flags |= CLIENT_REDRAW;
 | 
						c->flags |= CLIENT_REDRAW;
 | 
				
			||||||
 
 | 
				
			|||||||
							
								
								
									
										18
									
								
								server.c
									
									
									
									
									
								
							
							
						
						
									
										18
									
								
								server.c
									
									
									
									
									
								
							@@ -1,4 +1,4 @@
 | 
				
			|||||||
/* $Id: server.c,v 1.87 2008-12-13 18:06:08 nicm Exp $ */
 | 
					/* $Id: server.c,v 1.88 2009-01-06 15:37:15 nicm Exp $ */
 | 
				
			||||||
 | 
					
 | 
				
			||||||
/*
 | 
					/*
 | 
				
			||||||
 * Copyright (c) 2007 Nicholas Marriott <nicm@users.sourceforge.net>
 | 
					 * Copyright (c) 2007 Nicholas Marriott <nicm@users.sourceforge.net>
 | 
				
			||||||
@@ -507,6 +507,8 @@ server_accept_client(int srv_fd)
 | 
				
			|||||||
	c->in = buffer_create(BUFSIZ);
 | 
						c->in = buffer_create(BUFSIZ);
 | 
				
			||||||
	c->out = buffer_create(BUFSIZ);
 | 
						c->out = buffer_create(BUFSIZ);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						ARRAY_INIT(&c->prompt_hdata);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	c->tty.fd = -1;
 | 
						c->tty.fd = -1;
 | 
				
			||||||
	c->title = NULL;
 | 
						c->title = NULL;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@@ -569,6 +571,20 @@ server_lost_client(struct client *c)
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
	tty_free(&c->tty);
 | 
						tty_free(&c->tty);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						if (c->title != NULL)
 | 
				
			||||||
 | 
							xfree(c->title);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						if (c->message_string != NULL)
 | 
				
			||||||
 | 
							xfree(c->message_string);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						if (c->prompt_string != NULL)
 | 
				
			||||||
 | 
							xfree(c->prompt_string);
 | 
				
			||||||
 | 
						if (c->prompt_buffer != NULL)
 | 
				
			||||||
 | 
							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);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	close(c->fd);
 | 
						close(c->fd);
 | 
				
			||||||
	buffer_destroy(c->in);
 | 
						buffer_destroy(c->in);
 | 
				
			||||||
	buffer_destroy(c->out);
 | 
						buffer_destroy(c->out);
 | 
				
			||||||
 
 | 
				
			|||||||
							
								
								
									
										49
									
								
								status.c
									
									
									
									
									
								
							
							
						
						
									
										49
									
								
								status.c
									
									
									
									
									
								
							@@ -1,4 +1,4 @@
 | 
				
			|||||||
/* $Id: status.c,v 1.52 2008-12-08 16:19:51 nicm Exp $ */
 | 
					/* $Id: status.c,v 1.53 2009-01-06 15:37:15 nicm Exp $ */
 | 
				
			||||||
 | 
					
 | 
				
			||||||
/*
 | 
					/*
 | 
				
			||||||
 * Copyright (c) 2007 Nicholas Marriott <nicm@users.sourceforge.net>
 | 
					 * Copyright (c) 2007 Nicholas Marriott <nicm@users.sourceforge.net>
 | 
				
			||||||
@@ -32,6 +32,8 @@ char   *status_replace(struct session *, char *, time_t);
 | 
				
			|||||||
size_t	status_width(struct winlink *);
 | 
					size_t	status_width(struct winlink *);
 | 
				
			||||||
char   *status_print(struct session *, struct winlink *, struct grid_cell *);
 | 
					char   *status_print(struct session *, struct winlink *, struct grid_cell *);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					void	status_prompt_add_history(struct client *);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
/* Draw status for client on the last lines of given context. */
 | 
					/* Draw status for client on the last lines of given context. */
 | 
				
			||||||
void
 | 
					void
 | 
				
			||||||
status_redraw(struct client *c)
 | 
					status_redraw(struct client *c)
 | 
				
			||||||
@@ -530,8 +532,37 @@ status_prompt_key(struct client *c, int key)
 | 
				
			|||||||
			c->flags |= CLIENT_STATUS;
 | 
								c->flags |= CLIENT_STATUS;
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
		break;
 | 
							break;
 | 
				
			||||||
 | 
						case KEYC_UP:
 | 
				
			||||||
 | 
							if (ARRAY_LENGTH(&c->prompt_hdata) == 0)
 | 
				
			||||||
 | 
								break;
 | 
				
			||||||
 | 
						       	xfree(c->prompt_buffer);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
							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->flags |= CLIENT_STATUS;
 | 
				
			||||||
 | 
							break;
 | 
				
			||||||
 | 
						case KEYC_DOWN:
 | 
				
			||||||
 | 
							xfree(c->prompt_buffer);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
							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->flags |= CLIENT_STATUS;
 | 
				
			||||||
 | 
							break;
 | 
				
			||||||
 	case '\r':	/* enter */
 | 
					 	case '\r':	/* enter */
 | 
				
			||||||
		if (*c->prompt_buffer != '\0') {
 | 
							if (*c->prompt_buffer != '\0') {
 | 
				
			||||||
 | 
								status_prompt_add_history(c);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
			c->prompt_callback(c->prompt_data, c->prompt_buffer);
 | 
								c->prompt_callback(c->prompt_data, c->prompt_buffer);
 | 
				
			||||||
			server_clear_client_prompt(c);
 | 
								server_clear_client_prompt(c);
 | 
				
			||||||
			break;
 | 
								break;
 | 
				
			||||||
@@ -560,3 +591,19 @@ status_prompt_key(struct client *c, int key)
 | 
				
			|||||||
		break;
 | 
							break;
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					/* Add line to the history. */
 | 
				
			||||||
 | 
					void
 | 
				
			||||||
 | 
					status_prompt_add_history(struct client *c)
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
 | 
						if (ARRAY_LENGTH(&c->prompt_hdata) > 0 &&
 | 
				
			||||||
 | 
						    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));
 | 
				
			||||||
 | 
							ARRAY_REMOVE(&c->prompt_hdata, 0);
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						ARRAY_ADD(&c->prompt_hdata, xstrdup(c->prompt_buffer));
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 
 | 
				
			|||||||
							
								
								
									
										7
									
								
								tmux.h
									
									
									
									
									
								
							
							
						
						
									
										7
									
								
								tmux.h
									
									
									
									
									
								
							@@ -1,4 +1,4 @@
 | 
				
			|||||||
/* $Id: tmux.h,v 1.205 2009-01-06 14:10:32 nicm Exp $ */
 | 
					/* $Id: tmux.h,v 1.206 2009-01-06 15:37:15 nicm Exp $ */
 | 
				
			||||||
 | 
					
 | 
				
			||||||
/*
 | 
					/*
 | 
				
			||||||
 * Copyright (c) 2007 Nicholas Marriott <nicm@users.sourceforge.net>
 | 
					 * Copyright (c) 2007 Nicholas Marriott <nicm@users.sourceforge.net>
 | 
				
			||||||
@@ -119,6 +119,9 @@ extern const char    *__progname;
 | 
				
			|||||||
/* Default configuration file. */
 | 
					/* Default configuration file. */
 | 
				
			||||||
#define DEFAULT_CFG ".tmux.conf"
 | 
					#define DEFAULT_CFG ".tmux.conf"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					/* Default prompt history length. */
 | 
				
			||||||
 | 
					#define PROMPT_HISTORY 100
 | 
				
			||||||
 | 
					
 | 
				
			||||||
/* Fatal errors. */
 | 
					/* Fatal errors. */
 | 
				
			||||||
#define fatal(msg) log_fatal("%s: %s", __func__, msg);
 | 
					#define fatal(msg) log_fatal("%s: %s", __func__, msg);
 | 
				
			||||||
#define fatalx(msg) log_fatalx("%s: %s", __func__, msg);
 | 
					#define fatalx(msg) log_fatalx("%s: %s", __func__, msg);
 | 
				
			||||||
@@ -745,6 +748,8 @@ struct client {
 | 
				
			|||||||
	size_t		 prompt_index;
 | 
						size_t		 prompt_index;
 | 
				
			||||||
	void		 (*prompt_callback)(void *, char *);
 | 
						void		 (*prompt_callback)(void *, char *);
 | 
				
			||||||
	void		*prompt_data;
 | 
						void		*prompt_data;
 | 
				
			||||||
 | 
						u_int		 prompt_hindex;
 | 
				
			||||||
 | 
						ARRAY_DECL(, char *) prompt_hdata;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	struct session	*session;
 | 
						struct session	*session;
 | 
				
			||||||
};
 | 
					};
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user