Kaynağa Gözat

Change interactive commands behaviour

Serj Kalichev 7 ay önce
ebeveyn
işleme
b9587e08c6

+ 8 - 3
klish/ksession/kexec.c

@@ -314,7 +314,11 @@ static bool_t kexec_prepare(kexec_t *exec)
 	// never get terminal
 	if (exec->type == KCONTEXT_TYPE_ACTION) {
 		isatty_stdin = ksession_isatty_stdin(exec->session);
-		isatty_stdout = ksession_isatty_stdout(exec->session);
+		// Only if last command in pipeline is interactive then stdout
+		// can be pts. Because client adds its own pager to pipeline in
+		// a case of non-interactive commands
+		if (kexec_interactive(exec))
+			isatty_stdout = ksession_isatty_stdout(exec->session);
 		isatty_stderr = ksession_isatty_stderr(exec->session);
 	}
 	if (isatty_stdin || isatty_stdout || isatty_stderr) {
@@ -787,8 +791,9 @@ bool_t kexec_interactive(const kexec_t *exec)
 	if (!exec)
 		return BOOL_FALSE;
 
-	// Only the ACTION of first context can be interactive
-	node = faux_list_head(exec->contexts);
+	// Only the interactivity of last context is important. Because
+	// its output can be used as input for client's pager
+	node = faux_list_tail(exec->contexts);
 	if (!node)
 		return BOOL_FALSE;
 	context = (kcontext_t *)faux_list_data(node);

+ 2 - 16
klish/ksession/ksession_parse.c

@@ -494,14 +494,6 @@ static bool_t ksession_check_line(const kpargv_t *pargv, faux_error_t *error,
 			return BOOL_FALSE;
 		}
 
-		// Interactive command can't have filters
-		if (kentry_interactive(cmd) && is_piped) {
-			faux_error_sprintf(error, "The interactive command \"%s\" "
-				"can't have filters",
-				kentry_name(cmd));
-			return BOOL_FALSE;
-		}
-
 	// Components after pipe "|"
 	} else {
 
@@ -521,16 +513,10 @@ static bool_t ksession_check_line(const kpargv_t *pargv, faux_error_t *error,
 			return BOOL_FALSE;
 		}
 
-		// Only the first component can have 'interactive=true' attribute
-		if (kentry_interactive(cmd)) {
-			faux_error_sprintf(error, "The filter \"%s\" "
-				"can't be interactive",
-				kentry_name(cmd));
-			return BOOL_FALSE;
-		}
-
 	}
 
+	is_piped = is_piped; // Happy compiler
+
 	return BOOL_TRUE;
 }
 

+ 0 - 2
klish/ktp/ktpd_session.c

@@ -945,8 +945,6 @@ static bool_t ktpd_session_process_stdin(ktpd_session_t *ktpd, faux_msg_t *msg)
 
 	if (!ktpd->exec)
 		return BOOL_FALSE;
-	if (!kexec_interactive(ktpd->exec))
-		return BOOL_FALSE;
 	fd = kexec_stdin(ktpd->exec);
 	if (fd < 0)
 		return BOOL_FALSE;