summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--ChangeLog10
-rw-r--r--doc/ratpoison.texi24
-rw-r--r--src/conf.h11
-rw-r--r--src/input.c65
4 files changed, 107 insertions, 3 deletions
diff --git a/ChangeLog b/ChangeLog
index 64ddbda..70e7da5 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,15 @@
2001-12-21 shawn <sabetts@vcn.bc.ca>
+ * src/input.c (input_history): new static global
+ (input_num_history_entries): likewise
+ (get_more_input): cycle through the input history.
+
+ * src/conf.h (INPUT_PREV_HISTORY_KEY): new define
+ (INPUT_PREV_HISTORY_MODIFIER): likewise
+ (INPUT_NEXT_HISTORY_KEY): likewise
+ (INPUT_NEXT_HISTORY_MODIFIER): likewise
+ (INPUT_MAX_HISTORY): likewise
+
* src/input.c (update_input_window): Draw the cursor in the right place.
* src/actions.h (cmd_defbarpadding): new prototype
diff --git a/doc/ratpoison.texi b/doc/ratpoison.texi
index 3e0d75e..b211a05 100644
--- a/doc/ratpoison.texi
+++ b/doc/ratpoison.texi
@@ -87,8 +87,10 @@ This document explains how to use ratpoison.
* Keystrokes:: Key commands and functionality
* Commands:: ratpoison commands
* Command Line Arguments:: ratpoison command-line actions
+* Input:: Typing text into ratpoison
* Startup file:: They threatened me...with violence!
+
@end menu
@node About, Contacting, Top, Top
@@ -650,7 +652,7 @@ described in @command{defwinfmt}.
@end table
-@node Command Line Arguments, Startup file, Commands, Top
+@node Command Line Arguments, Input, Commands, Top
@chapter Command Line Arguments
ratpoison supports command line arguments to request various actions
when invoking ratpoison.
@@ -676,8 +678,26 @@ window otherwise launch it.
@end table
+@node Input, Startup file, Command Line Arguments, Top
+@chapter Input
+At various times ratpoison will prompt you for input. Currently only
+very basic text editing commands exist.
+
+@table @key
+@item Backspace
+Deletes one letter preceding the cursor.
+
+@item C-p
+Cycle backwards through the history.
+
+@item C-n
+Cycle forwards through the history.
+@end table
+
+All input is stored in the same history list. By default ratpoison has
+a history length of 50 entries.
-@node Startup file, , Command Line Arguments, Top
+@node Startup file, , Input, Top
@chapter Startup file
Now you've probably read the web page, and you've no doubt dug up some
diff --git a/src/conf.h b/src/conf.h
index 47e2289..10821a1 100644
--- a/src/conf.h
+++ b/src/conf.h
@@ -32,6 +32,17 @@
#define INPUT_ABORT_KEY XK_g
#define INPUT_ABORT_MODIFIER ControlMask
+/* This is the previous history entry key when typing input. */
+#define INPUT_PREV_HISTORY_KEY XK_p
+#define INPUT_PREV_HISTORY_MODIFIER ControlMask
+
+/* This is the next history entry key when typing input. */
+#define INPUT_NEXT_HISTORY_KEY XK_n
+#define INPUT_NEXT_HISTORY_MODIFIER ControlMask
+
+/* Number of history items to store. */
+#define INPUT_MAX_HISTORY 50
+
/* Treat windows with maxsize hints as if they were a transient window
(don't hide the windows underneath, and center them) */
#define MAXSIZE_WINDOWS_ARE_TRANSIENTS
diff --git a/src/input.c b/src/input.c
index 27d7583..bd264c1 100644
--- a/src/input.c
+++ b/src/input.c
@@ -28,6 +28,10 @@
#include "ratpoison.h"
+/* Variables to keep track of input history. */
+static char *input_history[INPUT_MAX_HISTORY];
+static int input_num_history_entries = 0;
+
/* Convert an X11 modifier mask to the rp modifier mask equivalent, as
best it can (the X server may not have a hyper key defined, for
instance). */
@@ -322,8 +326,9 @@ get_more_input (char *prompt, char *preinput)
int revert;
Window fwin;
char *str;
+ int history_index = input_num_history_entries;
- /* Allocate some memory to start with */
+ /* Allocate some memory to start with. */
str = (char *) xmalloc ( allocated_len );
/* load in the preinput */
@@ -354,6 +359,46 @@ get_more_input (char *prompt, char *preinput)
if (cur_len > 0) cur_len--;
update_input_window(s, prompt, str, cur_len);
}
+ else if (ch == INPUT_PREV_HISTORY_KEY
+ && modifier == INPUT_PREV_HISTORY_MODIFIER)
+ {
+ /* Cycle through the history. */
+ if (input_num_history_entries > 0)
+ {
+ history_index--;
+ if (history_index < 0)
+ {
+ history_index = input_num_history_entries - 1;
+ }
+
+ free (str);
+ str = xstrdup (input_history[history_index]);
+ allocated_len = strlen (str) + 1;
+ cur_len = allocated_len - 1;
+
+ update_input_window (s, prompt, str, cur_len);
+ }
+ }
+ else if (ch == INPUT_NEXT_HISTORY_KEY
+ && modifier == INPUT_NEXT_HISTORY_MODIFIER)
+ {
+ /* Cycle through the history. */
+ if (input_num_history_entries > 0)
+ {
+ history_index++;
+ if (history_index >= input_num_history_entries)
+ {
+ history_index = 0;
+ }
+
+ free (str);
+ str = xstrdup (input_history[history_index]);
+ allocated_len = strlen (str) + 1;
+ cur_len = allocated_len - 1;
+
+ update_input_window (s, prompt, str, cur_len);
+ }
+ }
else if (ch == INPUT_ABORT_KEY && modifier == INPUT_ABORT_MODIFIER)
{
/* User aborted. */
@@ -381,6 +426,24 @@ get_more_input (char *prompt, char *preinput)
}
str[cur_len] = 0;
+
+ /* Push the history entries down. */
+ if (input_num_history_entries >= INPUT_MAX_HISTORY)
+ {
+ int i;
+ free (input_history[0]);
+ for (i=0; i<INPUT_MAX_HISTORY-1; i++)
+ {
+ input_history[i] = input_history[i+1];
+ }
+
+ input_num_history_entries--;
+ }
+
+ /* Store the string in the history. */
+ input_history[input_num_history_entries] = xstrdup (str);
+ input_num_history_entries++;
+
XSetInputFocus (dpy, fwin, RevertToPointerRoot, CurrentTime);
XUnmapWindow (dpy, s->input_window);
return str;