Anonymous avatar Anonymous committed c7d33f0

add Home, End, Delete, tried fancier MIN/MAX macros to make sure nothing is evaluated twice, but it's not worth getting rid of the -pedantic flag, so i'll just try to be safe and not use MIN/MAX with a function call or increment/decrement

Comments (0)

Files changed (2)

 
 .SH DESCRIPTION
 .B srw
-srw is used to provide a simple line editing interface to a program. The output
-of the program does not interupt the input to srw, and the input to srw is not
-echoed.
+is used to provide a simple line editing interface to a program. The output of the program does not interupt the input to srw, and the input to srw is not echoed.
+
 .SH SYNOPSIS
 .B srw
 .RB [ \-p
 .IR prompt ]
-.RB [ \-v ]
 .IR cmd
 .RI [ args... ]
+.P
+.B srw
+.RB [ \-v ]
 .SH OPTIONS
 .TP
 .IR " cmd"
 the command to wrap, this and it's arguments must come last
 .TP
 .IR " args..."
-the arguments passed to command
+the arguments passed to cmd
 .TP
 .BI \-p " prompt"
-lets you override the default prompt (>)
+override the default prompt (>)
 .TP
 .BI \-v
-prints version information and exits
+print version information and exit
 
 .SH USAGE
+srw supports the usual arrow keys, Home, End, Delete, as well as the following shortcuts
 .TP
-So far the left and right arrow keys and a few shortcuts work. Specifically ^A ^B ^E ^F ^K ^U ^W. Home, End, Delete, etc. do not work yet.
-.SH AUTHORS
+.I C-a
+move cursor to beginning of line
+.TP
+.I C-b
+move cursor back one character
+.TP
+.I C-e
+move cursor to end of the line
+.TP
+.I C-f
+move cursor forward one character
+.TP
+.I C-k
+delete from cursor to end of line
+.TP
+.I C-u
+delete entire line
+.TP
+.I C-w
+delete from cursor to beginning of word
+.SH AUTHOR
 Copyright \(co 2010 by Evan Gates <evan.gates (at) gmail (dot) com>
 #define STDOUT 1
 #define STDERR 2
 
-#define MAX(a, b)   (((a) > (b)) ? (a) : (b))
-#define MIN(a, b)   (((a) < (b)) ? (a) : (b))
+/*
+ * I like these because they make sure you never evaluate something twice in the macro,
+ * think function call or increment, but they aren't part of C99 so I have to get rid
+ * of the -pedantic when I compile, but I like what that catches for me. Until I find
+ * a better way to use these, I'll just have to be safe with the unsafe versions.
+ *#define MIN(x,y) ({ typeof(x) _x = (x); typeof(y) _y = (y); (_x < _y) ? _x : _y; })
+ *#define MAX(x,y) ({ typeof(x) _x = (x); typeof(y) _y = (y); (_x > _y) ? _x : _y; })
+ */
+
+#define MIN(x,y) ((x) < (y) ? (x) : (y))
+#define MAX(x,y) ((x) > (y) ? (x) : (y))
 
 #define BELL        CTRL('g')
 #define BACKSPACE   CTRL('h')
 #define cursor_fwd(n) printf("\033[%dC", MAX(1, (n)))
 #define cursor_bak(n) printf("\033[%dD", MAX(1, (n)))
 
-char  csi[] = {ESC, '[', 0};
 char  buf[4096], usrbuf[4096];
 char  scrl_prompt_left[]  = "<";
 char  scrl_prompt_right[] = ">";
 			if (escape) {
 				switch (c) {
 					case '[' : continue;
-					case 'C' : cur = MIN(cur + 1, len); break;
-					case 'D' : cur = MAX(cur - 1, 0  ); break;
+					case '3' : // Delete
+					   if (cur != len)
+						   shift_buf(usrbuf, cur + 1, len--, -1);
+					   escape++;
+					   break;
+					case '7' : cur = 0;   escape++;     break; // Home
+					case '8' : cur = len; escape++;     break; // End
+					case 'C' : cur = MIN(cur + 1, len); break; // Left  Arrow
+					case 'D' : cur = MAX(cur - 1, 0  ); break; // Right Arrow
 				}
-				escape = 0;
+				escape--;
 			} else {
 				switch (c) {
 					case ESC :
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.