Browse Source

klish: Press enter with empty line

Serj Kalichev 2 months ago
parent
commit
ec4fc7c96c
1 changed files with 8 additions and 5 deletions
  1. 8 5
      bin/klish/interactive.c

+ 8 - 5
bin/klish/interactive.c

@@ -5,6 +5,7 @@
 #include <fcntl.h>
 
 #include <faux/faux.h>
+#include <faux/str.h>
 #include <faux/eloop.h>
 #include <klish/ktp.h>
 #include <klish/ktp_session.h>
@@ -111,16 +112,18 @@ static bool_t tinyrl_key_enter(tinyrl_t *tinyrl, unsigned char key)
 {
 	const char *line = NULL;
 	ctx_t *ctx = (ctx_t *)tinyrl_udata(tinyrl);
+	faux_error_t *error = faux_error_new();
 
 	tinyrl_multi_crlf(tinyrl);
+	tinyrl_reset_line_state(tinyrl);
 
 	line = tinyrl_line(tinyrl);
-	if (line) {
-		faux_error_t *error = faux_error_new();
-		ktp_session_cmd(ctx->ktp, line, error, BOOL_FALSE);
-	}
+	// Don't do anything on empty line
+	if (faux_str_is_empty(line))
+		return BOOL_TRUE;
+
+	ktp_session_cmd(ctx->ktp, line, error, BOOL_FALSE);
 
-	tinyrl_reset_line_state(tinyrl);
 	tinyrl_reset_line(tinyrl);
 	tinyrl_set_busy(tinyrl, BOOL_TRUE);