Browse Source

Patch by Michal Turek

git-svn-id: https://klish.googlecode.com/svn/trunk@463 0eaa4687-2ee9-07dd-09d9-bcdd2d2dd5fb
Serj Kalichev 13 years ago
parent
commit
620288a711
5 changed files with 61 additions and 16 deletions
  1. 4 1
      clish/shell/shell_tinyrl.c
  2. 19 0
      tinyrl/tinyrl.c
  3. 10 0
      tinyrl/tinyrl.h
  4. 11 8
      tinyrl/vt100.h
  5. 17 7
      tinyrl/vt100/vt100.c

+ 4 - 1
clish/shell/shell_tinyrl.c

@@ -146,7 +146,10 @@ static bool_t clish_shell_tinyrl_key_space(tinyrl_t * this, int key)
 	const clish_command_t *cmd = NULL;
 	clish_pargv_t *pargv = NULL;
 
-	if (BOOL_TRUE == tinyrl_is_quoting(this)) {
+	if(BOOL_TRUE == tinyrl_is_empty(this)) {
+		/* ignore space at the begining of the line, don't display commands */
+		return BOOL_TRUE;
+	} else if (BOOL_TRUE == tinyrl_is_quoting(this)) {
 		/* if we are in the middle of a quote then simply enter a space */
 		result = BOOL_TRUE;
 	} else {

+ 19 - 0
tinyrl/tinyrl.c

@@ -349,6 +349,19 @@ static bool_t tinyrl_key_escape(tinyrl_t * this, int key)
 	case tinyrl_vt100_CURSOR_RIGHT:
 		result = tinyrl_key_right(this, key);
 		break;
+	case tinyrl_vt100_HOME:
+		result = tinyrl_key_start_of_line(this,key);
+		break;
+	case tinyrl_vt100_END:
+		result = tinyrl_key_end_of_line(this,key);
+		break;
+	case tinyrl_vt100_DELETE:
+		result = tinyrl_key_delete(this,key);
+		break;
+
+	case tinyrl_vt100_INSERT:
+	case tinyrl_vt100_PGDOWN:
+	case tinyrl_vt100_PGUP:
 	case tinyrl_vt100_UNKNOWN:
 		break;
 	}
@@ -1346,6 +1359,12 @@ bool_t tinyrl_is_quoting(const tinyrl_t * this)
 	return result;
 }
 
+/*-------------------------------------------------------- */
+bool_t tinyrl_is_empty(const tinyrl_t *this)
+{
+	return (this->point == 0) ? BOOL_TRUE : BOOL_FALSE;
+}
+
 /*--------------------------------------------------------- */
 void tinyrl_limit_line_length(tinyrl_t * this, unsigned length)
 {

+ 10 - 0
tinyrl/tinyrl.h

@@ -199,6 +199,16 @@ extern bool_t tinyrl_is_quoting(
          * The instance on which to operate
          */
 				       const tinyrl_t * instance);
+/**
+ * Indicate whether the current insertion is empty or not
+ */
+extern bool_t
+	tinyrl_is_empty(
+		/**
+		 * The instance on which to operate
+		 */
+		const tinyrl_t *instance
+	);
 /**
  * Limit maximum line length
  */

+ 11 - 8
tinyrl/vt100.h

@@ -67,14 +67,17 @@ _BEGIN_C_DECL typedef struct _tinyrl_vt100 tinyrl_vt100_t;
  * This enumeration is used to identify the types of escape code 
  */
 typedef enum {
-	tinyrl_vt100_UNKNOWN,  /**< Undefined escape sequence */
-	tinyrl_vt100_CURSOR_UP,/**< Move the cursor up        */
-	tinyrl_vt100_CURSOR_DOWN,
-			       /**< Move the cursor down      */
-	tinyrl_vt100_CURSOR_LEFT,
-			       /**< Move the cursor left      */
-	tinyrl_vt100_CURSOR_RIGHT
-			       /**< Move the cursor right     */
+	tinyrl_vt100_UNKNOWN, /**< Undefined escape sequence */
+	tinyrl_vt100_CURSOR_UP, /**< Move the cursor up */
+	tinyrl_vt100_CURSOR_DOWN, /**< Move the cursor down */
+	tinyrl_vt100_CURSOR_LEFT, /**< Move the cursor left */
+	tinyrl_vt100_CURSOR_RIGHT, /**< Move the cursor right */
+	tinyrl_vt100_HOME, /**< Move the cursor to the beginning of the line */
+	tinyrl_vt100_END, /**< Move the cursor to the end of the line */
+	tinyrl_vt100_INSERT, /**< No action at the moment */
+	tinyrl_vt100_DELETE, /**< Delete character on the right */
+	tinyrl_vt100_PGUP, /**< No action at the moment */
+	tinyrl_vt100_PGDOWN /**< No action at the moment */
 } tinyrl_vt100_escape_t;
 
 extern tinyrl_vt100_t *tinyrl_vt100_new(FILE * instream, FILE * outstream);

+ 17 - 7
tinyrl/vt100/vt100.c

@@ -2,20 +2,27 @@
 #include <stdlib.h>
 # include <unistd.h>
 # include <fcntl.h>
+#include <string.h>
 
 #include "private.h"
 
 typedef struct {
-	const char terminator;
+	const char* sequence;
 	tinyrl_vt100_escape_t code;
 } vt100_decode_t;
 
 /* This table maps the vt100 escape codes to an enumeration */
 static vt100_decode_t cmds[] = {
-	{'A', tinyrl_vt100_CURSOR_UP},
-	{'B', tinyrl_vt100_CURSOR_DOWN},
-	{'C', tinyrl_vt100_CURSOR_RIGHT},
-	{'D', tinyrl_vt100_CURSOR_LEFT},
+	{"[A", tinyrl_vt100_CURSOR_UP},
+	{"[B", tinyrl_vt100_CURSOR_DOWN},
+	{"[C", tinyrl_vt100_CURSOR_RIGHT},
+	{"[D", tinyrl_vt100_CURSOR_LEFT},
+	{"[H", tinyrl_vt100_HOME},
+	{"[F", tinyrl_vt100_END},
+	{"[2~", tinyrl_vt100_INSERT},
+	{"[3~", tinyrl_vt100_DELETE},
+	{"[5~", tinyrl_vt100_PGUP},
+	{"[6~", tinyrl_vt100_PGDOWN},
 };
 
 /*--------------------------------------------------------- */
@@ -66,16 +73,19 @@ tinyrl_vt100_escape_t tinyrl_vt100_escape_decode(const tinyrl_vt100_t * this)
 			break;
 		}
 	}
-	/* terminate the string (for debug purposes) */
+	/* terminate the string */
 	*p = '\0';
 
 	/* restore the blocking status */
 	_tinyrl_vt100_setInputBlocking(this);
 
 	if (tinyrl_vt100_UNKNOWN != result) {
+		p = sequence;
+		result = tinyrl_vt100_UNKNOWN;
+
 		/* now decode the sequence */
 		for (i = 0; i < sizeof(cmds) / sizeof(vt100_decode_t); i++) {
-			if (cmds[i].terminator == c) {
+			if (strcmp(cmds[i].sequence, p) == 0) {
 				/* found the code in the lookup table */
 				result = cmds[i].code;
 				break;