Update of /cvsroot/tmux/tmux
In directory sfp-cvsdas-2.v30.ch3.sourceforge.com:/tmp/cvs-serv16284
Modified Files:
server-client.c status.c tmux.h
Log Message:
Make the prompt history global for all clients which is much more useful
than per-client history.
Index: server-client.c
===================================================================
RCS file: /cvsroot/tmux/tmux/server-client.c,v
retrieving revision 1.45
retrieving revision 1.46
diff -u -d -r1.45 -r1.46
--- server-client.c 24 Oct 2010 01:51:34 -0000 1.45
+++ server-client.c 11 Dec 2010 16:15:02 -0000 1.46
@@ -69,8 +69,6 @@
fatal("gettimeofday failed");
memcpy(&c->activity_time, &c->creation_time, sizeof c->activity_time);
- ARRAY_INIT(&c->prompt_hdata);
-
c->stdin_event = NULL;
c->stdout_event = NULL;
c->stderr_event = NULL;
@@ -160,9 +158,6 @@
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);
if (c->cwd != NULL)
xfree(c->cwd);
Index: tmux.h
===================================================================
RCS file: /cvsroot/tmux/tmux/tmux.h,v
retrieving revision 1.585
retrieving revision 1.586
diff -u -d -r1.585 -r1.586
--- tmux.h 6 Dec 2010 22:52:21 -0000 1.585
+++ tmux.h 11 Dec 2010 16:15:02 -0000 1.586
@@ -1145,13 +1145,11 @@
int (*prompt_callbackfn)(void *, const char *);
void (*prompt_freefn)(void *);
void *prompt_data;
+ u_int prompt_hindex;
#define PROMPT_SINGLE 0x1
int prompt_flags;
- u_int prompt_hindex;
- ARRAY_DECL(, char *) prompt_hdata;
-
struct mode_key_data prompt_mdata;
struct session *session;
Index: status.c
===================================================================
RCS file: /cvsroot/tmux/tmux/status.c,v
retrieving revision 1.150
retrieving revision 1.151
diff -u -d -r1.150 -r1.151
--- status.c 6 Dec 2010 22:52:21 -0000 1.150
+++ status.c 11 Dec 2010 16:15:02 -0000 1.151
@@ -41,9 +41,14 @@
struct winlink *, char **, char **, char *, size_t, int);
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 *);
+/* Status prompt history. */
+ARRAY_DECL(, char *) status_prompt_history = ARRAY_INITIALIZER;
+
/* Retrieve options for left string. */
char *
status_redraw_get_left(struct client *c,
@@ -860,6 +865,7 @@
{
struct paste_buffer *pb;
char *s, *first, *last, word[64], swapc;
+ const char *histstr;
u_char ch;
size_t size, n, off, idx;
@@ -972,29 +978,20 @@
}
break;
case MODEKEYEDIT_HISTORYUP:
- if (ARRAY_LENGTH(&c->prompt_hdata) == 0)
+ histstr = status_prompt_up_history(&c->prompt_hindex);
+ if (histstr == NULL)
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_buffer = xstrdup(histstr);
c->prompt_index = strlen(c->prompt_buffer);
c->flags |= CLIENT_STATUS;
break;
case MODEKEYEDIT_HISTORYDOWN:
+ histstr = status_prompt_down_history(&c->prompt_hindex);
+ if (histstr == NULL)
+ break;
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_buffer = xstrdup(histstr);
c->prompt_index = strlen(c->prompt_buffer);
c->flags |= CLIENT_STATUS;
break;
@@ -1036,7 +1033,7 @@
break;
case MODEKEYEDIT_ENTER:
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)
status_prompt_clear(c);
break;
@@ -1072,20 +1069,56 @@
}
}
+/* Get previous line from the history. */
+const char *
+status_prompt_up_history(u_int *idx)
+{
+ u_int size;
+
+ /*
+ * History runs from 0 to size - 1.
+ *
+ * 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));
+}
+
+/* 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(struct client *c)
+status_prompt_add_history(const char *line)
{
- if (ARRAY_LENGTH(&c->prompt_hdata) > 0 &&
- strcmp(ARRAY_LAST(&c->prompt_hdata), c->prompt_buffer) == 0)
+ u_int size;
+
+ size = ARRAY_LENGTH(&status_prompt_history);
+ if (size > 0 && strcmp(ARRAY_LAST(&status_prompt_history), line) == 0)
return;
- if (ARRAY_LENGTH(&c->prompt_hdata) == PROMPT_HISTORY) {
- xfree(ARRAY_FIRST(&c->prompt_hdata));
- ARRAY_REMOVE(&c->prompt_hdata, 0);
+ if (size == PROMPT_HISTORY) {
+ xfree(ARRAY_FIRST(&status_prompt_history));
+ ARRAY_REMOVE(&status_prompt_history, 0);
}
- ARRAY_ADD(&c->prompt_hdata, xstrdup(c->prompt_buffer));
+ ARRAY_ADD(&status_prompt_history, xstrdup(line));
}
/* Complete word. */
------------------------------------------------------------------------------
Oracle to DB2 Conversion Guide: Learn learn about native support for PL/SQL,
new data types, scalar functions, improved concurrency, built-in packages,
OCI, SQL*Plus, data movement tools, best practices and more.
http://p.sf.net/sfu/oracle-sfdev2dev
_______________________________________________
tmux-cvs mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/tmux-cvs