linux-gpio.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [RFC PATCH] gpioset: only print prompt when stdout is tty
@ 2023-05-23 13:54 Esben Haabendal
  2023-05-23 15:36 ` Kent Gibson
  0 siblings, 1 reply; 8+ messages in thread
From: Esben Haabendal @ 2023-05-23 13:54 UTC (permalink / raw)
  To: linux-gpio

When gpioset interactive mode is used as intended, as a human controlled
interface, stdout should be a tty.

By leaving out the prompt when stdout is not a tty, gpioset interactive mode can
be used as a really simple deamon for controlling GPIOs by connecting it to a
FIFO.

Signed-off-by: Esben Haabendal <esben@geanix.com>
---
 tools/gpioset.c | 10 +++-------
 1 file changed, 3 insertions(+), 7 deletions(-)

diff --git a/tools/gpioset.c b/tools/gpioset.c
index 9dc5aeb8b286..a1ca211febd7 100644
--- a/tools/gpioset.c
+++ b/tools/gpioset.c
@@ -742,13 +742,12 @@ static void interact(struct gpiod_line_request **requests,
 {
 	int num_words, num_lines, max_words, period_us, i;
 	char *line, **words, *line_buf;
-	bool done, stdout_is_tty;
+	bool done;
 
 	stifle_history(20);
 	rl_attempted_completion_function = tab_completion;
 	rl_basic_word_break_characters = " =\"";
 	completion_context = resolver;
-	stdout_is_tty = isatty(1);
 
 	max_words = resolver->num_lines + 1;
 	words = calloc(max_words, sizeof(*words));
@@ -757,12 +756,9 @@ static void interact(struct gpiod_line_request **requests,
 
 	for (done = false; !done;) {
 		/*
-		 * manually print the prompt, as libedit doesn't if stdout
-		 * is not a tty.  And fflush to ensure the prompt and any
-		 * output buffered from the previous command is sent.
+		 * fflush to ensure the prompt and any output buffered from the
+		 * previous command is sent.
 		 */
-		if (!stdout_is_tty)
-			printf(PROMPT);
 		fflush(stdout);
 
 		line = readline(PROMPT);
-- 
2.40.1


^ permalink raw reply related	[flat|nested] 8+ messages in thread

end of thread, other threads:[~2023-05-24  8:50 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2023-05-23 13:54 [RFC PATCH] gpioset: only print prompt when stdout is tty Esben Haabendal
2023-05-23 15:36 ` Kent Gibson
2023-05-24  6:30   ` esben
2023-05-24  7:32     ` Kent Gibson
2023-05-24  7:53       ` esben
2023-05-24  8:12         ` Kent Gibson
2023-05-24  8:35           ` esben
2023-05-24  8:50             ` Kent Gibson

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).