Browse Source

Fix multiline crlf.

Serj Kalichev 12 years ago
parent
commit
844dec9e7b
3 changed files with 19 additions and 5 deletions
  1. 3 3
      clish/shell/shell_tinyrl.c
  2. 15 2
      tinyrl/tinyrl.c
  3. 1 0
      tinyrl/tinyrl.h

+ 3 - 3
clish/shell/shell_tinyrl.c

@@ -231,7 +231,7 @@ static bool_t clish_shell_tinyrl_key_enter(tinyrl_t *this, int key)
 
 	/* nothing to pass simply move down the screen */
 	if (!*line) {
-		tinyrl_crlf(this);
+		tinyrl_multi_crlf(this);
 		tinyrl_done(this);
 		return BOOL_TRUE;
 	}
@@ -261,7 +261,7 @@ static bool_t clish_shell_tinyrl_key_enter(tinyrl_t *this, int key)
 			/* failed to get a unique match... */
 			if (!tinyrl__get_isatty(this)) {
 				/* batch mode */
-				tinyrl_crlf(this);
+				tinyrl_multi_crlf(this);
 				errmsg = "Unknown command";
 			}
 			break;
@@ -269,7 +269,7 @@ static bool_t clish_shell_tinyrl_key_enter(tinyrl_t *this, int key)
 	}
 	if (cmd) {
 		clish_pargv_status_t arg_status;
-		tinyrl_crlf(this);
+		tinyrl_multi_crlf(this);
 		/* we've got a command so check the syntax */
 		arg_status = clish_shell_parse(context->shell,
 			line, &context->cmd, &context->pargv);

+ 15 - 2
tinyrl/tinyrl.c

@@ -41,7 +41,7 @@ static void utf8_point_right(tinyrl_t * this)
 }
 
 /*-------------------------------------------------------- */
-static unsigned utf8_nsyms(tinyrl_t * this, const char *str, unsigned num)
+static unsigned utf8_nsyms(const tinyrl_t * this, const char *str, unsigned num)
 {
 	unsigned nsym = 0;
 	unsigned i;
@@ -562,7 +562,7 @@ static void tinyrl_internal_print(const tinyrl_t * this, const char *text)
 }
 
 /*----------------------------------------------------------------------- */
-static void tinyrl_internal_position(tinyrl_t *this, int prompt_len,
+static void tinyrl_internal_position(const tinyrl_t *this, int prompt_len,
 	int line_len, unsigned int width)
 {
 	int rows, cols;
@@ -579,6 +579,19 @@ static void tinyrl_internal_position(tinyrl_t *this, int prompt_len,
 		tinyrl_vt100_cursor_down(this->term, -rows);
 }
 
+/*-------------------------------------------------------- */
+/* Jump to first free line after current multiline input   */
+void tinyrl_multi_crlf(const tinyrl_t * this)
+{
+	unsigned int line_size = strlen(this->last_buffer);
+	unsigned int line_len = utf8_nsyms(this, this->last_buffer, line_size);
+	unsigned int count = utf8_nsyms(this, this->last_buffer, this->last_point);
+
+	tinyrl_internal_position(this, this->prompt_len + line_len,
+		- (line_len - count), this->last_width);
+	tinyrl_crlf(this);
+}
+
 /*----------------------------------------------------------------------- */
 void tinyrl_redisplay(tinyrl_t * this)
 {

+ 1 - 0
tinyrl/tinyrl.h

@@ -120,6 +120,7 @@ extern char **tinyrl_completion(tinyrl_t *instance,
 	const char *line, unsigned start, unsigned end,
 	tinyrl_compentry_func_t *generator);
 extern void tinyrl_crlf(const tinyrl_t * instance);
+extern void tinyrl_multi_crlf(const tinyrl_t * instance);
 extern void tinyrl_ding(const tinyrl_t * instance);
 
 extern void tinyrl_reset_line_state(tinyrl_t * instance);