mirror of
https://github.com/UzixLS/picocom.git
synced 2025-07-19 07:21:18 +03:00
Added commandline option --quiet
Suppress picocom from printing initial greetings banners and other messages not explicitly requested by the user. Command responses and errors or warnings are still printed.
This commit is contained in:
20
fdio.c
20
fdio.c
@ -67,6 +67,26 @@ fd_printf (int fd, const char *format, ...)
|
||||
return writen_ni(fd, buf, len);
|
||||
}
|
||||
|
||||
|
||||
|
||||
int
|
||||
fd_pinfof(int quiet, const char *format, ...)
|
||||
{
|
||||
char buf[256];
|
||||
va_list args;
|
||||
int len;
|
||||
|
||||
if ( quiet ) {
|
||||
return 0;
|
||||
}
|
||||
va_start(args, format);
|
||||
len = vsnprintf(buf, sizeof(buf), format, args);
|
||||
buf[sizeof(buf) - 1] = '\0';
|
||||
va_end(args);
|
||||
|
||||
return writen_ni(STDOUT_FILENO, buf, len);
|
||||
}
|
||||
|
||||
/**********************************************************************/
|
||||
|
||||
#ifndef LINENOISE
|
||||
|
2
fdio.h
2
fdio.h
@ -28,6 +28,8 @@ ssize_t writen_ni(int fd, const void *buff, size_t n);
|
||||
|
||||
int fd_printf (int fd, const char *format, ...);
|
||||
|
||||
int fd_pinfof (int quiet, const char *format, ...);
|
||||
|
||||
#ifndef LINENOISE
|
||||
|
||||
int fd_readline (int fdi, int fdo, char *b, int bsz);
|
||||
|
@ -323,6 +323,13 @@ Picocom accepts the following command-line options.
|
||||
when it becomes idle. When exiting with **--exit-after**, picocom
|
||||
observes the **--noreset** setting as usual. (Default: not set).
|
||||
|
||||
**--quiet** | **-q**
|
||||
|
||||
: Forces picocom to be quiet. Suppresses the output of the initial
|
||||
status and options information, as well as any other information or
|
||||
messages not explicitly requested by the user. Responses to user
|
||||
commands and any error or warning messages are still printed.
|
||||
|
||||
**--help** | **-h**
|
||||
|
||||
: Print a short help message describing the command-line
|
||||
|
26
picocom.c
26
picocom.c
@ -195,6 +195,7 @@ struct {
|
||||
int exit_after;
|
||||
int lower_rts;
|
||||
int lower_dtr;
|
||||
int quiet;
|
||||
} opts = {
|
||||
.port = NULL,
|
||||
.baud = 9600,
|
||||
@ -218,7 +219,8 @@ struct {
|
||||
.initstring = NULL,
|
||||
.exit_after = -1,
|
||||
.lower_rts = 0,
|
||||
.lower_dtr = 0
|
||||
.lower_dtr = 0,
|
||||
.quiet = 0
|
||||
};
|
||||
|
||||
int sig_exit = 0;
|
||||
@ -1390,6 +1392,7 @@ parse_args(int argc, char *argv[])
|
||||
{"exit-after", required_argument, 0, 'x'},
|
||||
{"lower-rts", no_argument, 0, 'R'},
|
||||
{"lower-dtr", no_argument, 0, 'D'},
|
||||
{"quiet", no_argument, 0, 'q'},
|
||||
{"help", no_argument, 0, 'h'},
|
||||
{0, 0, 0, 0}
|
||||
};
|
||||
@ -1404,7 +1407,7 @@ parse_args(int argc, char *argv[])
|
||||
/* no default error messages printed. */
|
||||
opterr = 0;
|
||||
|
||||
c = getopt_long(argc, argv, "hirlcv:s:r:e:f:b:y:d:p:g:t:x:",
|
||||
c = getopt_long(argc, argv, "hirlcqv:s:r:e:f:b:y:d:p:g:t:x:",
|
||||
longOptions, &optionIndex);
|
||||
|
||||
if (c < 0)
|
||||
@ -1562,6 +1565,9 @@ parse_args(int argc, char *argv[])
|
||||
break;
|
||||
}
|
||||
break;
|
||||
case 'q':
|
||||
opts.quiet = 1;
|
||||
break;
|
||||
case 'h':
|
||||
show_usage(argv[0]);
|
||||
exit(EXIT_SUCCESS);
|
||||
@ -1596,6 +1602,9 @@ parse_args(int argc, char *argv[])
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
|
||||
if ( opts.quiet )
|
||||
return;
|
||||
|
||||
#ifndef NO_HELP
|
||||
printf("picocom v%s\n", VERSION_STR);
|
||||
printf("\n");
|
||||
@ -1723,10 +1732,11 @@ main(int argc, char *argv[])
|
||||
#endif
|
||||
|
||||
#ifndef NO_HELP
|
||||
fd_printf(STO, "Type [C-%c] [C-%c] to see available commands\r\n\r\n",
|
||||
fd_pinfof(opts.quiet,
|
||||
"Type [C-%c] [C-%c] to see available commands\r\n\r\n",
|
||||
KEYC(opts.escape), KEYC(KEY_HELP));
|
||||
#endif
|
||||
fd_printf(STO, "Terminal ready\r\n");
|
||||
fd_pinfof(opts.quiet, "Terminal ready\r\n");
|
||||
|
||||
/* Prime output buffer with initstring */
|
||||
tty_q.len = 0;
|
||||
@ -1760,16 +1770,16 @@ main(int argc, char *argv[])
|
||||
cleanup_history();
|
||||
#endif
|
||||
|
||||
fd_printf(STO, "\r\n");
|
||||
fd_pinfof(opts.quiet, "\r\n");
|
||||
if ( opts.noreset ) {
|
||||
fd_printf(STO, "Skipping tty reset...\r\n");
|
||||
fd_pinfof(opts.quiet, "Skipping tty reset...\r\n");
|
||||
term_erase(tty_fd);
|
||||
}
|
||||
|
||||
if ( sig_exit )
|
||||
fd_printf(STO, "Picocom was killed\r\n");
|
||||
fd_pinfof(opts.quiet, "Picocom was killed\r\n");
|
||||
else
|
||||
fd_printf(STO, "Thanks for using picocom\r\n");
|
||||
fd_pinfof(opts.quiet, "Thanks for using picocom\r\n");
|
||||
/* wait a bit for output to drain */
|
||||
sleep(1);
|
||||
|
||||
|
Reference in New Issue
Block a user