mirror of
https://gitlab.nic.cz/labs/bird.git
synced 2024-12-23 02:01:55 +00:00
BIRD Client: Don't print excessive lines in non-interactive mode
Do not print out excessive lines with BIRD version and CLI prompt in non-interactive mode. Share birdcl input_read() code for birdc non-interactive mode.
This commit is contained in:
parent
c0b101a1de
commit
f603be4643
@ -140,6 +140,12 @@ input_help(int arg, int key UNUSED)
|
||||
void
|
||||
input_init(void)
|
||||
{
|
||||
prompt_active = 0;
|
||||
|
||||
if (interactive)
|
||||
{
|
||||
prompt_active = 1;
|
||||
|
||||
retrieve_symbols();
|
||||
printf("BIRD Client " BIRD_VERSION " ready.\n");
|
||||
|
||||
@ -147,13 +153,12 @@ input_init(void)
|
||||
rl_add_defun("bird-complete", input_complete, '\t');
|
||||
rl_add_defun("bird-help", input_help, '?');
|
||||
rl_callback_handler_install("bird> ", input_got_line);
|
||||
}
|
||||
|
||||
// rl_get_screen_size();
|
||||
term_lns = LINES;
|
||||
term_cls = COLS;
|
||||
|
||||
prompt_active = 1;
|
||||
|
||||
// readline library does strange things when stdin is nonblocking.
|
||||
// if (fcntl(0, F_SETFL, O_NONBLOCK) < 0)
|
||||
// die("fcntl: %m");
|
||||
@ -200,7 +205,10 @@ input_notify(int prompt)
|
||||
void
|
||||
input_read(void)
|
||||
{
|
||||
if (interactive)
|
||||
rl_callback_read_char();
|
||||
else
|
||||
simple_input_read();
|
||||
}
|
||||
|
||||
void
|
||||
|
@ -21,8 +21,6 @@
|
||||
#include "client/client.h"
|
||||
#include "sysdep/unix/unix.h"
|
||||
|
||||
#define INPUT_BUF_LEN 2048
|
||||
|
||||
struct termios tty_save;
|
||||
|
||||
void
|
||||
@ -41,59 +39,17 @@ void
|
||||
input_notify(int prompt)
|
||||
{
|
||||
/* No ncurses -> no status to reveal/hide, print prompt manually. */
|
||||
if (!prompt)
|
||||
if (!prompt || !interactive)
|
||||
return;
|
||||
|
||||
printf("bird> ");
|
||||
fflush(stdout);
|
||||
}
|
||||
|
||||
|
||||
static int
|
||||
lastnb(char *str, int i)
|
||||
{
|
||||
while (i--)
|
||||
if ((str[i] != ' ') && (str[i] != '\t'))
|
||||
return str[i];
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
void
|
||||
input_read(void)
|
||||
{
|
||||
char buf[INPUT_BUF_LEN];
|
||||
|
||||
if ((fgets(buf, INPUT_BUF_LEN, stdin) == NULL) || (buf[0] == 0))
|
||||
{
|
||||
putchar('\n');
|
||||
cleanup();
|
||||
exit(0);
|
||||
}
|
||||
|
||||
int l = strlen(buf);
|
||||
if ((l+1) == INPUT_BUF_LEN)
|
||||
{
|
||||
printf("Input too long.\n");
|
||||
return;
|
||||
}
|
||||
|
||||
if (buf[l-1] == '\n')
|
||||
buf[--l] = '\0';
|
||||
|
||||
if (!interactive)
|
||||
printf("%s\n", buf);
|
||||
|
||||
if (l == 0)
|
||||
return;
|
||||
|
||||
if (lastnb(buf, l) == '?')
|
||||
{
|
||||
cmd_help(buf, strlen(buf));
|
||||
return;
|
||||
}
|
||||
|
||||
submit_command(buf);
|
||||
simple_input_read();
|
||||
}
|
||||
|
||||
static struct termios stored_tty;
|
||||
|
@ -37,6 +37,7 @@
|
||||
#include "client/reply_codes.h"
|
||||
|
||||
#define SERVER_READ_BUF_LEN 4096
|
||||
#define INPUT_BUF_LEN 2048
|
||||
|
||||
static char *opt_list = "s:vr";
|
||||
static int verbose, restricted, once;
|
||||
@ -422,6 +423,51 @@ server_read(void)
|
||||
}
|
||||
}
|
||||
|
||||
static int
|
||||
lastnb(char *str, int i)
|
||||
{
|
||||
while (i--)
|
||||
if ((str[i] != ' ') && (str[i] != '\t'))
|
||||
return str[i];
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
void
|
||||
simple_input_read(void)
|
||||
{
|
||||
char buf[INPUT_BUF_LEN];
|
||||
|
||||
if ((fgets(buf, INPUT_BUF_LEN, stdin) == NULL) || (buf[0] == 0))
|
||||
{
|
||||
if (interactive)
|
||||
putchar('\n');
|
||||
cleanup();
|
||||
exit(0);
|
||||
}
|
||||
|
||||
int l = strlen(buf);
|
||||
if ((l+1) == INPUT_BUF_LEN)
|
||||
{
|
||||
printf("Input too long.\n");
|
||||
return;
|
||||
}
|
||||
|
||||
if (buf[l-1] == '\n')
|
||||
buf[--l] = '\0';
|
||||
|
||||
if (l == 0)
|
||||
return;
|
||||
|
||||
if (lastnb(buf, l) == '?')
|
||||
{
|
||||
cmd_help(buf, strlen(buf));
|
||||
return;
|
||||
}
|
||||
|
||||
submit_command(buf);
|
||||
}
|
||||
|
||||
static void
|
||||
select_loop(void)
|
||||
{
|
||||
|
@ -68,5 +68,6 @@ void retrieve_symbols(void);
|
||||
void add_keywords_to_symbols(void);
|
||||
list *cli_get_symbol_list(void);
|
||||
uint cli_get_symbol_maxlen(void);
|
||||
void simple_input_read(void);
|
||||
|
||||
#endif
|
||||
|
Loading…
Reference in New Issue
Block a user