Browse Source

tinyrl: Fix injection of char to line

Serj Kalichev 1 year ago
parent
commit
4f867726ea
2 changed files with 11 additions and 6 deletions
  1. 0 1
      tinyrl/tinyrl/keys.c
  2. 11 5
      tinyrl/tinyrl/tinyrl.c

+ 0 - 1
tinyrl/tinyrl/keys.c

@@ -22,7 +22,6 @@ bool_t tinyrl_key_default(tinyrl_t *tinyrl, unsigned char key)
 		if (tinyrl->hotkey_fn)
 		if (tinyrl->hotkey_fn)
 			tinyrl->hotkey_fn(tinyrl, key);
 			tinyrl->hotkey_fn(tinyrl, key);
 	}
 	}
-printf("key=%u, pos=%lu, len=%lu\n", (unsigned char)key, tinyrl->line.pos, tinyrl->line.len);
 
 
 	return BOOL_TRUE;
 	return BOOL_TRUE;
 }
 }

+ 11 - 5
tinyrl/tinyrl/tinyrl.c

@@ -280,6 +280,7 @@ static bool_t process_char(tinyrl_t *tinyrl, char key)
 	// Handler (that has no special meaning) will put new char to line buffer
 	// Handler (that has no special meaning) will put new char to line buffer
 	if (!tinyrl->handlers[(unsigned char)key](tinyrl, key))
 	if (!tinyrl->handlers[(unsigned char)key](tinyrl, key))
 		vt100_ding(tinyrl->term);
 		vt100_ding(tinyrl->term);
+
 //	if (tinyrl->done) // Some handler set the done flag
 //	if (tinyrl->done) // Some handler set the done flag
 //		continue; // It will break the loop
 //		continue; // It will break the loop
 
 
@@ -305,10 +306,10 @@ static bool_t process_char(tinyrl_t *tinyrl, char key)
 	// For non UTF-8 encoding the utf8_cont is always 0.
 	// For non UTF-8 encoding the utf8_cont is always 0.
 	// For UTF-8 it's 0 when one-byte symbol or we get
 	// For UTF-8 it's 0 when one-byte symbol or we get
 	// all bytes for the current multibyte character
 	// all bytes for the current multibyte character
-	if (!tinyrl->utf8_cont) {
-		//tinyrl_redisplay(tinyrl);
-		printf("%s\n", tinyrl->line.str);
-	}
+//	if (!tinyrl->utf8_cont) {
+//		//tinyrl_redisplay(tinyrl);
+//		printf("%s\n", tinyrl->line.str);
+//	}
 
 
 	return BOOL_TRUE;
 	return BOOL_TRUE;
 }
 }
@@ -325,6 +326,11 @@ int tinyrl_read(tinyrl_t *tinyrl)
 	while ((rc = vt100_getchar(tinyrl->term, &key)) > 0) {
 	while ((rc = vt100_getchar(tinyrl->term, &key)) > 0) {
 		count++;
 		count++;
 		process_char(tinyrl, key);
 		process_char(tinyrl, key);
+	if (!tinyrl->utf8_cont) {
+		//tinyrl_redisplay(tinyrl);
+		printf("%s\n", tinyrl->line.str);
+	}
+printf("key=%u, pos=%lu, len=%lu\n", key, tinyrl->line.pos, tinyrl->line.len);
 	}
 	}
 
 
 	if ((rc < 0) && (EAGAIN == errno))
 	if ((rc < 0) && (EAGAIN == errno))
@@ -421,7 +427,7 @@ bool_t tinyrl_line_insert(tinyrl_t *tinyrl, const char *text, size_t len)
 	if (tinyrl->line.pos < tinyrl->line.len) {
 	if (tinyrl->line.pos < tinyrl->line.len) {
 		memmove(tinyrl->line.str + tinyrl->line.pos + len,
 		memmove(tinyrl->line.str + tinyrl->line.pos + len,
 			tinyrl->line.str + tinyrl->line.pos,
 			tinyrl->line.str + tinyrl->line.pos,
-			len);
+			tinyrl->line.len - tinyrl->line.pos);
 	}
 	}
 
 
 	memcpy(tinyrl->line.str + tinyrl->line.pos, text, len);
 	memcpy(tinyrl->line.str + tinyrl->line.pos, text, len);