aboutsummaryrefslogtreecommitdiffstats
path: root/vlib
diff options
context:
space:
mode:
Diffstat (limited to 'vlib')
-rw-r--r--vlib/vlib/unix/cli.c61
-rw-r--r--vlib/vlib/unix/main.c2
-rw-r--r--vlib/vlib/unix/unix.h4
3 files changed, 65 insertions, 2 deletions
diff --git a/vlib/vlib/unix/cli.c b/vlib/vlib/unix/cli.c
index 809be73331e..601995619c8 100644
--- a/vlib/vlib/unix/cli.c
+++ b/vlib/vlib/unix/cli.c
@@ -56,6 +56,12 @@
/* ANSI sequences. */
#define ANSI_CLEAR CSI "2J" CSI "1;1H"
+#define ANSI_RESET CSI "0m"
+#define ANSI_BOLD CSI "1m"
+#define ANSI_DIM CSI "2m"
+#define ANSI_DRED ANSI_DIM CSI "31m"
+#define ANSI_BRED ANSI_BOLD CSI "31m"
+#define ANSI_CLEAR CSI "2J" CSI "1;1H"
/** Maximum depth into a byte stream from which to compile a Telnet
* protocol message. This is a saftey measure. */
@@ -68,6 +74,31 @@
#define UNIX_CLI_STDIN_FD 0
+typedef struct {
+ u8 * line;
+ u32 length;
+} unix_cli_banner_t;
+
+#define _(a) { .line = (u8 *)(a), .length = sizeof(a) - 1 }
+/** Plain welcome banner. */
+static unix_cli_banner_t unix_cli_banner[] = {
+_(" _______ _ _ _____ ___ \n"),
+_(" __/ __/ _ \\ (_)__ | | / / _ \\/ _ \\\n"),
+_(" _/ _// // / / / _ \\ | |/ / ___/ ___/\n"),
+_(" /_/ /____(_)_/\\___/ |___/_/ /_/ \n"),
+_("\n")
+};
+/** ANSI color welcome banner. */
+static unix_cli_banner_t unix_cli_banner_color[] = {
+_(ANSI_BRED " _______ _ " ANSI_RESET " _ _____ ___ \n"),
+_(ANSI_BRED " __/ __/ _ \\ (_)__ " ANSI_RESET " | | / / _ \\/ _ \\\n"),
+_(ANSI_BRED " _/ _// // / / / _ \\" ANSI_RESET " | |/ / ___/ ___/\n"),
+_(ANSI_BRED " /_/ /____(_)_/\\___/" ANSI_RESET " |___/_/ /_/ \n"),
+_("\n")
+};
+#undef _
+
+
/** Unix CLI session. */
typedef struct {
u32 unix_file_index;
@@ -468,18 +499,44 @@ static u8 unix_cli_terminal_type(u8 * term, uword len)
return 0;
}
-/** \brief Emit initial prompt on a connection. */
+/** \brief Emit initial welcome banner and prompt on a connection. */
static void unix_cli_file_welcome(unix_cli_main_t * cm, unix_cli_file_t * cf)
{
unix_main_t * um = &unix_main;
unix_file_t * uf = pool_elt_at_index (um->file_pool, cf->unix_file_index);
+ unix_cli_banner_t *banner;
+ int i, len;
/*
* Put the first bytes directly into the buffer so that further output is
* queued until everything is ready. (oterwise initial prompt can appear
* mid way through VPP initialization)
*/
- unix_cli_add_pending_output (uf, cf,
+ unix_cli_add_pending_output (uf, cf, (u8 *)"\r", 1);
+
+ if (!um->cli_no_banner)
+ {
+ if (cf->ansi_capable)
+ {
+ banner = unix_cli_banner_color;
+ len = ARRAY_LEN(unix_cli_banner_color);
+ }
+ else
+ {
+ banner = unix_cli_banner;
+ len = ARRAY_LEN(unix_cli_banner);
+ }
+
+ for (i = 0; i < len; i++)
+ {
+ unix_vlib_cli_output_cooked(cf, uf,
+ banner[i].line,
+ banner[i].length);
+ }
+ }
+
+ /* Prompt. */
+ unix_vlib_cli_output_raw (cf, uf,
cm->cli_prompt,
vec_len (cm->cli_prompt));
diff --git a/vlib/vlib/unix/main.c b/vlib/vlib/unix/main.c
index d6976b10751..1d8bd282c09 100644
--- a/vlib/vlib/unix/main.c
+++ b/vlib/vlib/unix/main.c
@@ -312,6 +312,8 @@ unix_config (vlib_main_t * vm, unformat_input_t * input)
;
else if (unformat (input, "cli-line-mode"))
um->cli_line_mode = 1;
+ else if (unformat (input, "cli-no-banner"))
+ um->cli_no_banner = 1;
else if (unformat (input, "cli-history-limit %d", &um->cli_history_limit))
;
else if (unformat (input, "full-coredump"))
diff --git a/vlib/vlib/unix/unix.h b/vlib/vlib/unix/unix.h
index 269b9df5975..20aec675ee0 100644
--- a/vlib/vlib/unix/unix.h
+++ b/vlib/vlib/unix/unix.h
@@ -103,12 +103,16 @@ typedef struct {
/* CLI log file. GIGO. */
u8 *log_filename;
int log_fd;
+
/* Don't put CLI connections into character mode */
int cli_line_mode;
/* Maximum amount of command line history to keep per session */
u32 cli_history_limit;
+ /* Suppress the welcome banner at CLI session start */
+ int cli_no_banner;
+
/* Store the original state of stdin when it's a tty */
struct termios tio_stdin;
int tio_isset;