Browse Source

tinyrl: Busy flag

Serj Kalichev 1 year ago
parent
commit
4bb836e543
4 changed files with 39 additions and 3 deletions
  1. 8 2
      bin/klish/interactive.c
  2. 2 0
      tinyrl/tinyrl.h
  3. 1 0
      tinyrl/tinyrl/private.h
  4. 28 1
      tinyrl/tinyrl/tinyrl.c

+ 8 - 2
bin/klish/interactive.c

@@ -45,6 +45,7 @@ int klish_interactive_shell(ktp_session_t *ktp)
 	tinyrl_set_prompt(tinyrl, "$ ");
 	tinyrl_set_udata(tinyrl, &ctx);
 	tinyrl_bind_key(tinyrl, KEY_CR, tinyrl_key_enter);
+	tinyrl_redisplay(tinyrl);
 
 	ctx.ktp = ktp;
 	ctx.tinyrl = tinyrl;
@@ -68,13 +69,17 @@ int klish_interactive_shell(ktp_session_t *ktp)
 
 bool_t cmd_ack_cb(ktp_session_t *ktp, const faux_msg_t *msg, void *udata)
 {
+	ctx_t *ctx = (ctx_t *)udata;
+
+//	ktp_session_set_done(ktp, BOOL_TRUE);
+	tinyrl_redisplay(ctx->tinyrl);
+
+
 	// Happy compiler
 	ktp = ktp;
 	msg = msg;
 	udata = udata;
 
-//	ktp_session_set_done(ktp, BOOL_TRUE);
-
 	return BOOL_TRUE;
 }
 
@@ -106,6 +111,7 @@ static bool_t tinyrl_key_enter(tinyrl_t *tinyrl, unsigned char key)
 
 	tinyrl_reset_line_state(tinyrl);
 	tinyrl_reset_line(tinyrl);
+	tinyrl_set_busy(tinyrl, BOOL_TRUE);
 
 	return BOOL_TRUE;
 }

+ 2 - 0
tinyrl/tinyrl.h

@@ -77,6 +77,8 @@ void tinyrl_set_ostream(tinyrl_t *tinyrl, FILE *ostream);
 FILE *tinyrl_ostream(const tinyrl_t *tinyrl);
 void tinyrl_set_utf8(tinyrl_t *tinyrl, bool_t utf8);
 bool_t tinyrl_utf8(const tinyrl_t *tinyrl);
+bool_t tinyrl_busy(const tinyrl_t *tinyrl);
+void tinyrl_set_busy(tinyrl_t *tinyrl, bool_t busy);
 void tinyrl_set_prompt(tinyrl_t *tinyrl, const char *prompt);
 const char *tinyrl_prompt(const tinyrl_t *tinyrl);
 const char *tinyrl_line(const tinyrl_t *tinyrl);

+ 1 - 0
tinyrl/tinyrl/private.h

@@ -64,6 +64,7 @@ struct tinyrl_s {
 	size_t prompt_len; // strlen()
 	size_t prompt_chars; // Symbol positions
 	void *udata; // Arbitrary user data
+	bool_t busy; // Long executed commands set this flag. tinyrl_read() drops it
 
 	// Input processing vars. Input is processed char by char so
 	// the current state of processing is necessary.

+ 28 - 1
tinyrl/tinyrl/tinyrl.c

@@ -75,6 +75,7 @@ tinyrl_t *tinyrl_new(FILE *istream, FILE *ostream,
 	tinyrl->echo_char = '\0';
 	tinyrl->echo_enabled = BOOL_TRUE;
 	tinyrl->utf8 = BOOL_TRUE;
+	tinyrl->busy = BOOL_FALSE;
 
 	// VT100 terminal
 	tinyrl->term = vt100_new(istream, ostream);
@@ -224,6 +225,26 @@ void tinyrl_set_utf8(tinyrl_t *tinyrl, bool_t utf8)
 }
 
 
+bool_t tinyrl_busy(const tinyrl_t *tinyrl)
+{
+	assert(tinyrl);
+	if (!tinyrl)
+		return BOOL_FALSE;
+
+	return tinyrl->busy;
+}
+
+
+void tinyrl_set_busy(tinyrl_t *tinyrl, bool_t busy)
+{
+	assert(tinyrl);
+	if (!tinyrl)
+		return;
+
+	tinyrl->busy = busy;
+}
+
+
 const char *tinyrl_prompt(const tinyrl_t *tinyrl)
 {
 	assert(tinyrl);
@@ -373,10 +394,16 @@ int tinyrl_read(tinyrl_t *tinyrl)
 
 	assert(tinyrl);
 
+	// Some commands can't be processed immediately by handlers and need some
+	// network exchange for example. In this case we will not execute
+	// redisplay() after char processing because command is not really
+	// finished. Drop busy flag here because engine ready to get new input.
+	tinyrl_set_busy(tinyrl, BOOL_FALSE);
+
 	while ((rc = vt100_getchar(tinyrl->term, &key)) > 0) {
 		count++;
 		process_char(tinyrl, key);
-		if (!tinyrl->utf8_cont) {
+		if (!tinyrl->utf8_cont && !tinyrl_busy(tinyrl)) {
 			tinyrl_redisplay(tinyrl);
 	//		printf("%s\n", tinyrl->line.str);
 		}