summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKeith Wiles <keith.wiles@intel.com>2017-11-25 07:38:19 -0600
committerKeith Wiles <keith.wiles@intel.com>2017-11-25 07:48:59 -0600
commitcc677a061df5e85b8e883d7407287d5728439390 (patch)
tree2486869dccda75c5907f4e1317b56357e3a612a4
parent37794bf69f5b4cc632261b4ecc0e7084d23caff8 (diff)
downloaddpdk-draft-cli-cc677a061df5e85b8e883d7407287d5728439390.zip
dpdk-draft-cli-cc677a061df5e85b8e883d7407287d5728439390.tar.gz
dpdk-draft-cli-cc677a061df5e85b8e883d7407287d5728439390.tar.xz
update and fix cli
Signed-off-by: Keith Wiles <keith.wiles@intel.com>
-rw-r--r--lib/librte_cli/Makefile5
-rw-r--r--lib/librte_cli/cli.c164
-rw-r--r--lib/librte_cli/cli.h397
-rw-r--r--lib/librte_cli/cli_auto_complete.c7
-rw-r--r--lib/librte_cli/cli_cmds.c35
-rw-r--r--lib/librte_cli/cli_common.h7
-rw-r--r--lib/librte_cli/cli_file.c1
-rw-r--r--lib/librte_cli/cli_gapbuf.c2
-rw-r--r--lib/librte_cli/cli_gapbuf.h16
-rw-r--r--lib/librte_cli/cli_help.c4
-rw-r--r--lib/librte_cli/cli_history.c33
-rw-r--r--lib/librte_cli/cli_scrn.c40
-rw-r--r--lib/librte_cli/cli_scrn.h240
-rw-r--r--lib/librte_cli/cli_vt100.c323
-rw-r--r--lib/librte_cli/cli_vt100.h290
-rw-r--r--lib/librte_cli/cli_vt100_keys.c304
-rw-r--r--lib/librte_cli/cli_vt100_keys.h60
17 files changed, 721 insertions, 1207 deletions
diff --git a/lib/librte_cli/Makefile b/lib/librte_cli/Makefile
index 5a77d3e..13eb05b 100644
--- a/lib/librte_cli/Makefile
+++ b/lib/librte_cli/Makefile
@@ -42,6 +42,7 @@ LIBABIVER := 1
# all source are stored in SRCS-y
SRCS-y += cli.c
+SRCS-y += cli_input.c
SRCS-y += cli_cmds.c
SRCS-y += cli_map.c
SRCS-y += cli_gapbuf.c
@@ -53,7 +54,6 @@ SRCS-y += cli_history.c
SRCS-y += cli_search.c
SRCS-y += cli_cmap.c
SRCS-y += cli_vt100.c
-SRCS-y += cli_vt100_keys.c
SRCS-y += cli_scrn.c
SRCS-y += cli_string_fns.c
@@ -61,6 +61,7 @@ CFLAGS += -D_GNU_SOURCE
# install includes
SYMLINK-y-include += cli.h
+SYMLINK-y-include += cli_input.h
SYMLINK-y-include += cli_common.h
SYMLINK-y-include += cli_map.h
SYMLINK-y-include += cli_gapbuf.h
@@ -69,8 +70,6 @@ SYMLINK-y-include += cli_env.h
SYMLINK-y-include += cli_search.h
SYMLINK-y-include += cli_help.h
SYMLINK-y-include += cli_history.h
-SYMLINK-y-include += cli_vt100.h
-SYMLINK-y-include += cli_vt100_keys.h
SYMLINK-y-include += cli_scrn.h
SYMLINK-y-include += cli_string_fns.h
diff --git a/lib/librte_cli/cli.c b/lib/librte_cli/cli.c
index 83f43f5..0fac897 100644
--- a/lib/librte_cli/cli.c
+++ b/lib/librte_cli/cli.c
@@ -41,6 +41,7 @@
#include <rte_string_fns.h>
#include "cli.h"
+#include "cli_input.h"
#include "cli_string_fns.h"
int (*lua_dofile)(void *, const char *);
@@ -63,31 +64,6 @@ cli_nodes_unlimited(void)
return this_cli->flags & CLI_NODES_UNLIMITED;
}
-int
-cli_yield_io(void)
-{
- if (!this_cli)
- return 1;
- return this_cli->flags & CLI_YIELD_IO;
-}
-
-/* The CLI write routine, using write() call */
-void
-cli_write(const void *msg, int len)
-{
- if (!msg)
- return;
-
- if (len <= 0) {
- len = strlen(msg);
- if (!len)
- return;
- }
-
- if (write(fileno(this_scrn->fd_out), msg, len) != len)
- cli_printf("write() in cli_write() failed\n");
-}
-
/* Allocate a node from the CLI node pool */
static inline struct cli_node *
cli_alloc(void)
@@ -433,7 +409,7 @@ cli_add_tree(struct cli_node *parent, struct cli_tree *tree)
d = &t->dir;
if (!(n = cli_add_dir(d->name, parent))) {
- RTE_LOG(INFO, EAL,
+ RTE_LOG(ERR, EAL,
"Add directory %s failed\n", d->name);
return -1;
}
@@ -445,7 +421,7 @@ cli_add_tree(struct cli_node *parent, struct cli_tree *tree)
c = &t->cmd;
if (!cli_add_cmd(c->name, parent,
c->cfunc, c->short_desc)) {
- RTE_LOG(INFO, EAL,
+ RTE_LOG(ERR, EAL,
"Add command %s failed\n", c->name);
return -1;
}
@@ -455,7 +431,7 @@ cli_add_tree(struct cli_node *parent, struct cli_tree *tree)
f = &t->file;
if (!cli_add_file(f->name, parent,
f->ffunc, f->short_desc)) {
- RTE_LOG(INFO, EAL,
+ RTE_LOG(ERR, EAL,
"Add file %s failed\n", f->name);
return -1;
}
@@ -465,7 +441,7 @@ cli_add_tree(struct cli_node *parent, struct cli_tree *tree)
a = &t->alias;
if (!cli_add_alias(a->name, parent,
a->alias_atr, a->short_desc)) {
- RTE_LOG(INFO, EAL,
+ RTE_LOG(ERR, EAL,
"Add alias %s failed\n", a->name);
return -1;
}
@@ -474,7 +450,7 @@ cli_add_tree(struct cli_node *parent, struct cli_tree *tree)
case CLI_STR_NODE:
s = &t->str;
if (cli_add_str(s->name, s->sfunc, s->string)) {
- RTE_LOG(INFO, EAL,
+ RTE_LOG(ERR, EAL,
"Add string %s failed\n", s->name);
return -1;
}
@@ -482,7 +458,7 @@ cli_add_tree(struct cli_node *parent, struct cli_tree *tree)
case CLI_UNK_NODE:
default:
- RTE_LOG(INFO, EAL, "Unknown Node type %d\n", t->type);
+ RTE_LOG(ERR, EAL, "Unknown Node type %d\n", t->type);
return 0;
}
}
@@ -606,97 +582,6 @@ cli_execute(void)
return ret;
}
-/* Process the input for the CLI from the user */
-void
-cli_input(char *str, int n)
-{
- char c;
- int ret;
-
- RTE_ASSERT(this_cli->gb != NULL);
- RTE_ASSERT(str != NULL);
-
- while (n--) {
- c = *str++;
-
- ret = vt100_parse_input(this_cli->vt, c);
-
- if (ret < 0) {
- if (ret == VT100_DONE)
- if ((c >= ' ') && (c <= '~')) {
- /* Output the character typed */
- cli_write(&c, 1);
-
- /* Add the character to the buffer */
- gb_insert(this_cli->gb, c);
-
- /* Display the rest on insert */
- cli_save_cursor();
- cli_display_right();
- cli_restore_cursor();
- }
- } else if (ret != 0)
- /* Found a vt100 key sequence, execute function */
- if (ret < VT100_MAX_KEYS)
- vt100_cmd_list[ret].func();
- }
-}
-
-/* Poll the I/O routine for characters */
-static int
-cli_poll(char *c)
-{
- struct pollfd fds;
-
- fds.fd = fileno(this_scrn->fd_in);
- fds.events = POLLIN;
- fds.revents = 0;
-
- if (cli_use_timers())
- rte_timer_manage();
-
- if (poll(&fds, 1, 0)) {
- if ((fds.revents & (POLLERR | POLLNVAL)) == 0) {
- if ((fds.revents & POLLHUP))
- this_cli->quit_flag = 1;
- else if ((fds.revents & POLLIN))
- if (read(fds.fd, c, 1) > 0)
- return 1;
- } else
- cli_quit();
- }
- return 0;
-}
-
-/* Display a prompt and wait for a key press */
-char
-cli_pause(const char *msg, const char *keys)
-{
- char prompt[128], c;
-
- prompt[0] = '\0';
-
- if (msg) {
- strcpy(prompt, msg);
- strcat(prompt, ": ");
- cli_printf("%s", prompt);
- }
-
- if (!keys)
- keys = " qQ\n\r" vt100_q_escape;
-
- do {
- if (cli_poll(&c))
- if (strchr(keys, c)) {
- /* clear the line of the prompt */
- cli_printf("\r%*s\r", (int)strlen(prompt), " ");
- return c;
- }
- } while (this_cli->quit_flag == 0);
-
- return '\0';
-}
-
/* Main entry point into the CLI system to start accepting user input */
void
cli_start(const char *msg)
@@ -709,7 +594,7 @@ cli_start(const char *msg)
(msg == NULL) ? "Command Line Interface" : msg,
(this_cli->flags & CLI_USE_TIMERS) ? "" : "out");
- this_cli->prompt(0);
+ this_cli->plen = this_cli->prompt(0);
cli_execute_cmdfiles();
@@ -753,25 +638,28 @@ cli_create_root(const char *dirname)
}
/* Default CLI prompt routine */
-static void
+static int
__default_prompt(int cont)
{
char *str = cli_cwd_path();
+ int len = 0;
if (strlen(str) > 1) /* trim the trailing '/' from string */
str[strlen(str) - 1] = '\0';
- vt100_color(SCRN_GREEN, SCRN_NO_CHANGE, SCRN_OFF);
- cli_printf("%s:", (cont) ? " >> " : "DPDK-cli");
- vt100_color(SCRN_CYAN, SCRN_NO_CHANGE, SCRN_OFF);
- cli_printf("%s", str);
- vt100_color(SCRN_DEFAULT_FG, SCRN_DEFAULT_BG, SCRN_OFF);
- cli_printf("> ");
+ scrn_color(SCRN_GREEN, SCRN_NO_CHANGE, SCRN_OFF);
+ len += cli_printf("%s:", (cont) ? " >> " : "DPDK-cli");
+ scrn_color(SCRN_CYAN, SCRN_NO_CHANGE, SCRN_OFF);
+ len += cli_printf("%s", str);
+ scrn_color(SCRN_DEFAULT_FG, SCRN_DEFAULT_BG, SCRN_OFF);
+ len += cli_printf("> ");
+
+ return len;
}
/* Main entry point to create a CLI system */
int
-cli_create(int nb_entries, uint32_t nb_hist)
+cli_init(int nb_entries, uint32_t nb_hist)
{
int i;
size_t size;
@@ -821,7 +709,7 @@ cli_create(int nb_entries, uint32_t nb_hist)
if (scrn_create_with_defaults(SCRN_THEME_ON))
goto error_exit;
- cli->vt = vt100_create();
+ cli->vt = vt100_setup();
if (!cli->vt)
goto error_exit;
@@ -872,9 +760,15 @@ error_exit:
}
int
+cli_create(void)
+{
+ return cli_init(CLI_DEFAULT_NODES, CLI_DEFAULT_HIST_LINES);
+}
+
+int
cli_create_with_defaults(void)
{
- if (cli_create(CLI_DEFAULT_NODES, CLI_DEFAULT_HIST_LINES) == 0)
+ if (cli_init(CLI_DEFAULT_NODES, CLI_DEFAULT_HIST_LINES) == 0)
return cli_setup_with_defaults();
return -1;
}
@@ -889,7 +783,7 @@ cli_destroy(void)
return;
gb_destroy(cli->gb);
- vt100_destroy(cli->vt);
+ vt100_free(cli->vt);
scrn_destroy();
cli_history_delete();
@@ -1003,11 +897,11 @@ int
cli_execute_cmdfiles(void)
{
int i, cnt;
- const char *path;
cnt = this_cli->cmd_files.idx;
for (i = 0; i < cnt; i++) {
+ const char *path;
if ((path = this_cli->cmd_files.filename[i]) == NULL)
continue;
diff --git a/lib/librte_cli/cli.h b/lib/librte_cli/cli.h
index 5359316..295b4c4 100644
--- a/lib/librte_cli/cli.h
+++ b/lib/librte_cli/cli.h
@@ -56,8 +56,6 @@
#include <cli_help.h>
#include <cli_history.h>
#include <cli_map.h>
-#include <cli_vt100.h>
-#include <cli_vt100_keys.h>
#include <rte_string_fns.h>
@@ -117,8 +115,7 @@ typedef int (*cli_ffunc_t)(struct cli_node *node, char *buff, int len,
uint32_t opt);
/**< CLI function pointer type for a file type node */
-typedef void (*cli_prompt_t)(int continuation);
-/**< CLI prompt routine */
+typedef int (*cli_prompt_t)(int continuation); /**< CLI prompt routine */
typedef int (*cli_tree_t)(void);
/**< CLI function pointer type for user initialization */
@@ -156,9 +153,11 @@ struct cli {
TAILQ_HEAD(, cli_node) root; /**< head of node entries or root */
CIRCLEQ_HEAD(, cli_hist) hd_hist; /**< History circular queue */
- uint16_t flags; /**< Flags about CLI */
- volatile uint16_t quit_flag; /**< When set to non-zero quit */
+ uint32_t flags; /**< Flags about CLI */
uint32_t nb_nodes; /**< total number of nodes */
+ volatile uint16_t quit_flag; /**< When set to non-zero quit */
+
+ uint16_t plen; /**< Length of current prompt */
uint32_t nb_hist; /**< total number of history lines */
cli_files_t cmd_files; /**< array of command filename pointers */
@@ -188,6 +187,32 @@ struct cli {
RTE_DECLARE_PER_LCORE(struct cli *, cli);
#define this_cli RTE_PER_LCORE(cli)
+/* cli.flags */
+#define DISPLAY_LINE (1 << 0)
+#define CLEAR_TO_EOL (1 << 1)
+#define DISPLAY_PROMPT (1 << 2)
+#define PROMPT_CONTINUE (1 << 3)
+#define DELETE_CHAR (1 << 4)
+#define CLEAR_LINE (1 << 5)
+
+static inline void
+cli_set_flag(uint32_t x)
+{
+ this_cli->flags |= x;
+}
+
+static inline void
+cli_clr_flag(uint32_t x)
+{
+ this_cli->flags &= ~x;
+}
+
+static inline int
+cli_tst_flag(uint32_t x)
+{
+ return this_cli->flags & x;
+}
+
typedef union {
cli_cfunc_t cfunc; /**< Function pointer for commands */
cli_ffunc_t ffunc; /**< Function pointer for files */
@@ -231,48 +256,18 @@ struct cli_tree {
struct cli_alias alias; /**< alias nodes */
struct cli_str str; /**< string node */
};
-}; /**< Used to help create a directory tree */
-
-#define c_dir(n) \
- { \
- CLI_DIR_NODE, .dir = {(n) } \
- }
-#define c_cmd(n, f, h) \
- { \
- CLI_CMD_NODE, .cmd = {(n), (f), (h) } \
- }
-#define c_file(n, rw, h) \
- { \
- CLI_FILE_NODE, .file = {(n), (rw), (h) } \
- }
-#define c_alias(n, l, h) \
- { \
- CLI_ALIAS_NODE, .alias = {(n), (l), (h) } \
- }
-#define c_str(n, f, s) \
- { \
- CLI_STR_NODE, .str = {(n), (f), (s) } \
- }
-#define c_end() \
- { \
- CLI_UNK_NODE, .dir = { NULL } \
- }
+};
-/**
- * The CLI write routine, using write() call
- *
- * @note Uses thread variable this_cli.
- *
- * @param msg
- * The string to be written
- * @param len
- * Number of bytes to write or if -1 then strlen(msg) is used.
- * @return
- * N/A
- */
-void cli_write(const void *msg, int len);
+/**< Used to help create a directory tree */
+#define c_dir(n) { CLI_DIR_NODE, .dir = {(n)} }
+#define c_cmd(n, f, h) { CLI_CMD_NODE, .cmd = {(n), (f), (h)} }
+#define c_file(n, rw, h) { CLI_FILE_NODE, .file = {(n), (rw), (h)} }
+#define c_alias(n, l, h) { CLI_ALIAS_NODE, .alias = {(n), (l), (h)} }
+#define c_str(n, f, s) { CLI_STR_NODE, .str = {(n), (f), (s)} }
+#define c_end() { CLI_UNK_NODE, .dir = { NULL } }
-static inline void cli_set_user_state(void *val)
+static inline void
+cli_set_user_state(void *val)
{
this_cli->user_state = val;
}
@@ -285,7 +280,8 @@ static inline void cli_set_user_state(void *val)
* @return
* Pointer to current working directory.
*/
-static inline struct cli_node *get_root(void)
+static inline struct cli_node *
+get_root(void)
{
RTE_ASSERT(this_cli != NULL);
return this_cli->root.tqh_first;
@@ -299,7 +295,8 @@ static inline struct cli_node *get_root(void)
* @return
* Pointer to current working directory.
*/
-static inline struct cli_node *get_cwd(void)
+static inline struct cli_node *
+get_cwd(void)
{
RTE_ASSERT(this_cli != NULL);
return this_cli->bins[0];
@@ -315,7 +312,8 @@ static inline struct cli_node *get_cwd(void)
* @return
* None
*/
-static inline void set_cwd(struct cli_node *node)
+static inline void
+set_cwd(struct cli_node *node)
{
RTE_ASSERT(this_cli != NULL);
this_cli->bins[0] = node;
@@ -327,7 +325,8 @@ static inline void set_cwd(struct cli_node *node)
* @return
* 1 if true else 0
*/
-static inline int is_cli_valid(void)
+static inline int
+is_cli_valid(void)
{
return (this_cli) ? 1 : 0;
}
@@ -342,7 +341,8 @@ static inline int is_cli_valid(void)
* @return
* 0 failed to compare and 1 is equal.
*/
-static inline int is_match(const char *s1, const char *s2)
+static inline int
+is_match(const char *s1, const char *s2)
{
if (!s1 || !s2)
return 0;
@@ -365,7 +365,8 @@ static inline int is_match(const char *s1, const char *s2)
* @return
* True if node is one of the types given
*/
-static inline int is_node(struct cli_node *node, uint32_t types)
+static inline int
+is_node(struct cli_node *node, uint32_t types)
{
return node->type & types;
}
@@ -378,7 +379,8 @@ static inline int is_node(struct cli_node *node, uint32_t types)
* @return
* True if command else false if not
*/
-static inline int is_command(struct cli_node *node)
+static inline int
+is_command(struct cli_node *node)
{
return is_node(node, CLI_CMD_NODE);
}
@@ -391,7 +393,8 @@ static inline int is_command(struct cli_node *node)
* @return
* True if alias else false if not
*/
-static inline int is_alias(struct cli_node *node)
+static inline int
+is_alias(struct cli_node *node)
{
return is_node(node, CLI_ALIAS_NODE);
}
@@ -404,7 +407,8 @@ static inline int is_alias(struct cli_node *node)
* @return
* True if a file else false if not
*/
-static inline int is_file(struct cli_node *node)
+static inline int
+is_file(struct cli_node *node)
{
return is_node(node, CLI_FILE_NODE);
}
@@ -417,7 +421,8 @@ static inline int is_file(struct cli_node *node)
* @return
* True if directory else false if not
*/
-static inline int is_directory(struct cli_node *node)
+static inline int
+is_directory(struct cli_node *node)
{
return is_node(node, CLI_DIR_NODE);
}
@@ -430,7 +435,8 @@ static inline int is_directory(struct cli_node *node)
* @return
* True if executable else false if not
*/
-static inline int is_executable(struct cli_node *node)
+static inline int
+is_executable(struct cli_node *node)
{
return is_command(node) || is_alias(node);
}
@@ -443,7 +449,8 @@ static inline int is_executable(struct cli_node *node)
* @return
* -1 just to remove code having to return error anyway.
*/
-static inline int cli_usage(void)
+static inline int
+cli_usage(void)
{
if (this_cli && this_cli->exe_node) {
const char *p = this_cli->exe_node->short_desc;
@@ -461,7 +468,8 @@ static inline int cli_usage(void)
* @return
* String for the node type.
*/
-static inline const char *cli_node_type(struct cli_node *node)
+static inline const char *
+cli_node_type(struct cli_node *node)
{
const char *node_str[] = CLI_NODE_TYPES;
switch (node->type) {
@@ -493,7 +501,8 @@ static inline const char *cli_node_type(struct cli_node *node)
* @return
* Return the pointer to the cli->scratch buffer or buf with path string.
*/
-static inline char *cli_path_string(struct cli_node *node, char *path)
+static inline char *
+cli_path_string(struct cli_node *node, char *path)
{
if (!path)
path = this_cli->scratch;
@@ -521,7 +530,8 @@ static inline char *cli_path_string(struct cli_node *node, char *path)
* @return
* N/A
*/
-static inline char *cli_cwd_path(void)
+static inline char *
+cli_cwd_path(void)
{
return cli_path_string(get_cwd(), NULL);
}
@@ -537,179 +547,12 @@ static inline char *cli_cwd_path(void)
* @return
* N/A.
*/
-static inline void cli_pwd(struct cli_node *node)
+static inline void
+cli_pwd(struct cli_node *node)
{
cli_printf("%s", cli_path_string(node, NULL));
}
-/**
- * Move the vt100 cursor to the left one character
- *
- * @note Uses thread variable this_cli.
- *
- * @return
- * N/A
- */
-static inline void cli_cursor_left(void)
-{
- cli_write(vt100_left_arr, -1);
-}
-
-/**
- * Move the vt100 cursor to the right one character
- *
- * @note Uses thread variable this_cli.
- *
- * @return
- * N/A
- */
-static inline void cli_cursor_right(void)
-{
- cli_write(vt100_right_arr, -1);
-}
-
-/**
- * Save the vt100 cursor location
- *
- * @note Uses thread variable this_cli.
- *
- * @return
- * N/A
- */
-static inline void cli_save_cursor(void)
-{
- cli_write(vt100_save_cursor, -1);
-}
-
-/**
- * Restore the cursor to the saved location on the console
- *
- * @note Uses thread variable this_cli.
- *
- * @return
- * N/A
- */
-static inline void cli_restore_cursor(void)
-{
- cli_write(vt100_restore_cursor, -1);
-}
-
-/**
- * Print out the left side of the input in the Gap Buffer.
- *
- * @note Uses thread variable this_cli.
- *
- * @return
- * N/A
- */
-static inline void cli_display_left(void)
-{
- if (gb_left_data_size(this_cli->gb))
- cli_write(gb_start_of_buf(this_cli->gb),
- gb_left_data_size(this_cli->gb));
-}
-
-/**
- * Print out the right side of the input in the Gap Buffer.
- *
- * @note Uses thread variable this_cli.
- *
- * @return
- * N/A
- */
-static inline void cli_display_right(void)
-{
- if (gb_right_data_size(this_cli->gb))
- cli_write(gb_end_of_gap(this_cli->gb),
- gb_right_data_size(this_cli->gb));
-}
-
-/**
- * Print out the complete line in the Gap Buffer.
- *
- * @note Uses thread variable this_cli.
- *
- * @return
- * N/A
- */
-static inline void cli_display_line(void)
-{
- uint32_t i;
-
- this_cli->prompt(0);
-
- cli_display_left();
- cli_display_right();
-
- gb_move_gap_to_point(this_cli->gb);
-
- for (i = 0;
- i < (gb_data_size(this_cli->gb) - gb_point_offset(this_cli->gb));
- i++)
- cli_cursor_left();
-}
-
-/**
- * Clear the console screen
- *
- * @note Uses thread variable this_cli.
- *
- * @return
- * N/A
- */
-static inline void cli_clear_screen(void)
-{
- cli_write(vt100_clear_screen, -1);
-}
-
-/**
- * clear from cursor to end of line
- *
- * @note Uses thread variable this_cli.
- *
- * @return
- * N/A
- */
-static inline void cli_clear_to_eol(void)
-{
- cli_write(vt100_clear_right, -1);
-}
-
-/**
- * Clear the current line or the line given
- *
- * @note Uses thread variable this_cli.
- *
- * @param lineno
- * if lineno is -1 then clear the current line else the lineno given.
- * @return
- * N/A
- */
-static inline void cli_clear_line(int lineno)
-{
- if (lineno > 0)
- cli_printf(vt100_pos_cursor, lineno, 0);
- else
- cli_write("\r", 1);
-
- cli_write(vt100_clear_line, -1);
-}
-
-/**
- * Move the cursor up by the number of lines given
- *
- * @note Uses thread variable this_cli.
- *
- * @param lineno
- * Number of lines to move the cursor
- * @return
- * N/A
- */
-static inline void cli_move_cursor_up(int lineno)
-{
- while (lineno--)
- cli_printf(vt100_up_arr);
-}
/**
* Set the number of lines in history
@@ -721,7 +564,8 @@ static inline void cli_move_cursor_up(int lineno)
* @return
* zero on success or -1 on error
*/
-static inline int cli_set_history_size(uint32_t nb_hist)
+static inline int
+cli_set_history_size(uint32_t nb_hist)
{
return cli_set_history(nb_hist);
}
@@ -734,7 +578,8 @@ static inline int cli_set_history_size(uint32_t nb_hist)
* @return
* total number of line for history
*/
-static inline uint32_t cli_get_history_size(void)
+static inline uint32_t
+cli_get_history_size(void)
{
return this_cli->nb_hist;
}
@@ -747,7 +592,8 @@ static inline uint32_t cli_get_history_size(void)
* @return
* N/A
*/
-static inline void cli_history_list(void)
+static inline void
+cli_history_list(void)
{
cli_history_dump();
}
@@ -758,33 +604,15 @@ static inline void cli_history_list(void)
* @return
* Pointer to root node.
*/
-static inline struct cli_node *cli_root_node(void)
+static inline struct cli_node *
+cli_root_node(void)
{
return this_cli->root.tqh_first;
}
/**
- * Add a input text string the cli input parser
- *
- * @note Uses thread variable this_cli.
- *
- * @param str
- * Pointer to string to insert
- * @param n
- * Number of bytes in string
- * @return
- * N/A
- */
-void cli_input(char *str, int n);
-
-/**
* Create the CLI engine
*
- * @param prompt_func
- * Function pointer to call for displaying the prompt.
- * @param tree_func
- * The user supplied function to init the tree or can be NULL. If NULL then
- * a default tree is initialized with basic commands.
* @param nb_entries
* Total number of commands, files, aliases and directories. If 0 then use
* the default number of nodes. If -1 then unlimited number of nodes.
@@ -794,7 +622,7 @@ void cli_input(char *str, int n);
* @return
* 0 on success or -1
*/
-int cli_create(int nb_entries, uint32_t nb_hist);
+int cli_init(int nb_entries, uint32_t nb_hist);
/**
* Create the CLI engine with defaults
@@ -804,6 +632,8 @@ int cli_create(int nb_entries, uint32_t nb_hist);
*/
int cli_create_with_defaults(void);
+int cli_create(void);
+
int cli_setup(cli_prompt_t prompt, cli_tree_t default_func);
/**
@@ -1041,52 +871,6 @@ int cli_add_str(const char *name, cli_sfunc_t func, const char *str);
int cli_add_tree(struct cli_node *dir, struct cli_tree *tree);
/**
- * Set the I/O file descriptors
- *
- * @note Uses thread variable this_cli.
- *
- * @param in
- * File descriptor for input
- * @param out
- * File descriptor for output
- * @return
- * N/A
- */
-void cli_set_io(FILE *in, FILE *out);
-
-/**
- * Set the I/O to use stdin/stdout
- *
- * @note Uses thread variable this_cli.
- *
- * @return
- * 0 on success or non-0 on error
- */
-int cli_stdin_setup(void);
-
-/**
- * Restore the stdin/stdout tty params from setup
- *
- * @note Uses thread variable this_cli.
- *
- * @return
- * N/A
- */
-void cli_stdin_restore(void);
-
-/**
- * Pause and wait for input character
- *
- * @note Uses thread variable this_cli.
- *
- * @param keys
- * List of keys to force return, if NULL defaults to ESC and q/Q
- * @return
- * character that terminated the pause or zero.
- */
-char cli_pause(const char *msg, const char *keys);
-
-/**
* Add filenames to the CLI command list.
*
* @param filename
@@ -1094,7 +878,8 @@ char cli_pause(const char *msg, const char *keys);
* @return
* 0 is OK and -1 if error
*/
-static inline int cli_add_cmdfile(const char *filename)
+static inline int
+cli_add_cmdfile(const char *filename)
{
if (this_cli->cmd_files.idx >= MAX_CMD_FILES)
return -1;
@@ -1160,16 +945,6 @@ int cli_use_timers(void);
int cli_nodes_unlimited(void);
/**
- * return true if calling yield should are enabled.
- *
- * @note Uses thread variable this_cli.
- *
- * @return
- * non-zero if true else 0
- */
-int cli_yield_io(void);
-
-/**
* shutdown the CLI command interface.
*
*/
diff --git a/lib/librte_cli/cli_auto_complete.c b/lib/librte_cli/cli_auto_complete.c
index 063e180..583ff92 100644
--- a/lib/librte_cli/cli_auto_complete.c
+++ b/lib/librte_cli/cli_auto_complete.c
@@ -36,6 +36,7 @@
#include <rte_string_fns.h>
#include "cli.h"
+#include "cli_input.h"
#include "cli_auto_complete.h"
#include "cli_string_fns.h"
@@ -228,7 +229,7 @@ cli_auto_complete(void)
ret = complete_args(argc, argv, CLI_ALL_TYPE);
if (ret)
- cli_display_line();
+ cli_redisplay_line();
return;
}
@@ -242,7 +243,7 @@ cli_auto_complete(void)
/* if we get an error then redisplay the line */
if (ret)
- cli_display_line();
+ cli_redisplay_line();
} else {
char *save = alloca(size + 1);
@@ -265,6 +266,6 @@ cli_auto_complete(void)
/* insert the saved string back to the input buffer */
gb_str_insert(this_cli->gb, save, size);
- cli_display_line();
+ cli_redisplay_line();
}
}
diff --git a/lib/librte_cli/cli_cmds.c b/lib/librte_cli/cli_cmds.c
index c7c2bf0..d916648 100644
--- a/lib/librte_cli/cli_cmds.c
+++ b/lib/librte_cli/cli_cmds.c
@@ -41,11 +41,9 @@
#include <rte_debug.h>
#include <rte_log.h>
#include <rte_string_fns.h>
-#if RTE_VERSION >= RTE_VERSION_NUM(17, 5, 0, 0)
-#include <rte_bus_pci.h>
-#endif
#include "cli.h"
+#include "cli_input.h"
#include "cli_cmds.h"
#include "cli_cmap.h"
#include "cli_map.h"
@@ -572,36 +570,6 @@ delay_cmd(int argc __rte_unused, char **argv)
return 0;
}
-static struct cli_map cli_debug_map[] = {
- { 10, "debug pci" },
- { 20, "debug dev" },
- { -1, NULL }
-};
-
-static int
-dbg_cmd(int argc, char **argv)
-{
- struct cli_map *m;
-
- m = cli_mapping(cli_debug_map, argc, argv);
- if (!m)
- return -1;
- switch (m->index) {
- case 10:
-#if RTE_VERSION < RTE_VERSION_NUM(17, 5, 0, 0)
- rte_eal_pci_dump(stdout);
-#else
- rte_pci_dump(stdout);
-#endif
- break;
- case 20: rte_eal_devargs_dump(stdout); break;
- default:
- cli_help_show_group("debug");
- return -1;
- }
- return 0;
-}
-
static int
mkdir_cmd(int argc, char **argv)
{
@@ -725,7 +693,6 @@ c_cmd("sizes", sizes_cmd, "sizes # display some internal sizes"),
c_cmd("cmap", core_cmd, "cmap # display the core mapping"),
c_cmd("hugepages", huge_cmd, "hugepages # display hugepage info"),
c_cmd("path", path_cmd, "display the execution path for commands"),
-c_cmd("debug", dbg_cmd, "debug commands for pci and dev"),
c_cmd("env", env_cmd, "Show/del/get/set environment variables"),
c_cmd("script", script_cmd, "load and process cli command files"),
c_cmd("echo", echo_cmd, "simple echo a string to the screen"),
diff --git a/lib/librte_cli/cli_common.h b/lib/librte_cli/cli_common.h
index 59c2de5..844fd86 100644
--- a/lib/librte_cli/cli_common.h
+++ b/lib/librte_cli/cli_common.h
@@ -70,17 +70,20 @@ extern "C" {
* N/A
*/
-static inline void
+static inline int
__attribute__((format(printf, 1, 2)))
cli_printf(const char *fmt, ...)
{
va_list vaList;
+ int n;
va_start(vaList, fmt);
- vfprintf(this_scrn->fd_out, fmt, vaList);
+ n = vfprintf(this_scrn->fd_out, fmt, vaList);
va_end(vaList);
fflush(this_scrn->fd_out);
+
+ return n;
}
#ifdef __cplusplus
diff --git a/lib/librte_cli/cli_file.c b/lib/librte_cli/cli_file.c
index 0da43bc..5078758 100644
--- a/lib/librte_cli/cli_file.c
+++ b/lib/librte_cli/cli_file.c
@@ -32,6 +32,7 @@
*/
#include "cli.h"
+#include "cli_input.h"
#include "cli_file.h"
struct cli_node *
diff --git a/lib/librte_cli/cli_gapbuf.c b/lib/librte_cli/cli_gapbuf.c
index 117ffc6..d059579 100644
--- a/lib/librte_cli/cli_gapbuf.c
+++ b/lib/librte_cli/cli_gapbuf.c
@@ -173,7 +173,7 @@ gb_dump(struct gapbuf *gb, const char *msg)
for (p = gb->buf; p <= gb->ebuf; p++)
fprintf(stderr, "%c", (p == gb->point) ? '^' : ' ');
fprintf(stderr, "\n");
- cli_display_line();
+ cli_redisplay_line();
#else
(void)gb;
(void)msg;
diff --git a/lib/librte_cli/cli_gapbuf.h b/lib/librte_cli/cli_gapbuf.h
index 7695342..8d0bc3b 100644
--- a/lib/librte_cli/cli_gapbuf.h
+++ b/lib/librte_cli/cli_gapbuf.h
@@ -627,21 +627,31 @@ gb_del(struct gapbuf *gb, int cnt)
* @param str
* String to put at point
* @param
- * Size of the string to insert at point
+ * Size of the string to insert at point, if zero use strlen() to find length
* @return
- * N/AS
+ * Number of bytes inserted
*/
-static inline void
+static inline uint32_t
gb_str_insert(struct gapbuf *gb, char *str, uint32_t size)
{
+ int len;
+
+ if (size == 0)
+ size = strlen(str);
+ if (size == 0)
+ return 0;
+
gb_move_gap_to_point(gb);
if (size > gb_gap_size(gb))
gb_expand_gap(gb, size);
+ len = size;
do {
gb_putc(gb, *str++);
} while(--size);
+
+ return len;
}
/********************************************************/
diff --git a/lib/librte_cli/cli_help.c b/lib/librte_cli/cli_help.c
index bb7addb..adbb931 100644
--- a/lib/librte_cli/cli_help.c
+++ b/lib/librte_cli/cli_help.c
@@ -32,9 +32,11 @@
*/
#include "cli.h"
+#include "cli_input.h"
int
-cli_help_add(const char *group, struct cli_map *map, const char **help_data)
+cli_help_add(const
+char *group, struct cli_map *map, const char **help_data)
{
struct help_node *node;
diff --git a/lib/librte_cli/cli_history.c b/lib/librte_cli/cli_history.c
index 16aa053..711bc3f 100644
--- a/lib/librte_cli/cli_history.c
+++ b/lib/librte_cli/cli_history.c
@@ -44,8 +44,7 @@ cli_hist_alloc(void)
if (!CIRCLEQ_EMPTY(&cli->free_hist)) {
hist = (struct cli_hist *)CIRCLEQ_FIRST(&cli->free_hist);
- if (hist)
- CIRCLEQ_REMOVE(&cli->free_hist, hist, next);
+ CIRCLEQ_REMOVE(&cli->free_hist, hist, next);
}
return hist;
}
@@ -118,10 +117,11 @@ cli_history_line(int lineno)
if (!cli || !cli->hist_mem)
return NULL;
- if (!CIRCLEQ_EMPTY(&cli->hd_hist))
+ if (!CIRCLEQ_EMPTY(&cli->hd_hist)) {
CIRCLEQ_FOREACH(h, &cli->hd_hist, next) {
- if (i++ == lineno)
- return h->line;
+ if (i++ == lineno)
+ return h->line;
+ }
}
return NULL;
}
@@ -137,8 +137,13 @@ cli_history_prev(void)
if (!CIRCLEQ_EMPTY(&cli->hd_hist)) {
struct cli_hist *hist;
- if (!cli->curr_hist)
- cli->curr_hist = CIRCLEQ_FIRST(&cli->hd_hist);
+ if (!cli->curr_hist) {
+ cli->curr_hist = CIRCLEQ_LAST(&cli->hd_hist);
+ return cli->curr_hist->line;
+ }
+
+ if (cli->curr_hist == CIRCLEQ_FIRST(&cli->hd_hist))
+ return cli->curr_hist->line;
hist = CIRCLEQ_LOOP_PREV(&cli->hd_hist, cli->curr_hist, next);
cli->curr_hist = hist;
@@ -160,7 +165,10 @@ cli_history_next(void)
struct cli_hist *hist;
if (!cli->curr_hist)
- cli->curr_hist = CIRCLEQ_LAST(&cli->hd_hist);
+ return NULL;
+
+ if (cli->curr_hist == CIRCLEQ_LAST(&cli->hd_hist))
+ return (char *)(uintptr_t)"";
hist = CIRCLEQ_LOOP_NEXT(&cli->hd_hist, cli->curr_hist, next);
cli->curr_hist = hist;
@@ -210,18 +218,21 @@ cli_set_history(uint32_t nb_hist)
if (!cli)
return -1;
- size = nb_hist * sizeof(struct cli_hist);
-
if (nb_hist == 0) {
cli_history_delete();
return 0;
}
- if (nb_hist != cli->nb_hist)
+ if (cli->hist_mem && (nb_hist == cli->nb_hist))
+ return 0;
+
+ if (cli->hist_mem)
cli_history_delete();
cli->nb_hist = nb_hist;
+ size = nb_hist * sizeof(struct cli_hist);
+
cli->hist_mem = malloc(size);
if (cli->hist_mem) {
uint32_t i;
diff --git a/lib/librte_cli/cli_scrn.c b/lib/librte_cli/cli_scrn.c
index 3c443eb..a577761 100644
--- a/lib/librte_cli/cli_scrn.c
+++ b/lib/librte_cli/cli_scrn.c
@@ -39,12 +39,16 @@
#include <string.h>
#include <stdarg.h>
#include <unistd.h>
+#include <signal.h>
+#include <sys/ioctl.h>
#include <rte_atomic.h>
#include <rte_malloc.h>
#include <rte_spinlock.h>
+#include <cli.h>
#include "cli_scrn.h"
+#include "cli_input.h"
RTE_DEFINE_PER_LCORE(struct cli_scrn *, scrn);
@@ -154,10 +158,35 @@ scrn_stdin_restore(void)
printf("%s: system command failed\n", __func__);
}
+static void
+handle_winch(int sig)
+{
+ struct winsize w;
+
+ if (sig != SIGWINCH)
+ return;
+
+ ioctl(0, TIOCGWINSZ, &w);
+
+ this_scrn->nrows = w.ws_row;
+ this_scrn->ncols = w.ws_col;
+
+ /* Need to refreash the screen */
+ //cli_clear_screen();
+ cli_clear_line(-1);
+ cli_redisplay_line();
+}
+
int
-scrn_create(int scrn_type, int16_t nrows, int16_t ncols, int theme)
+scrn_create(int scrn_type, int theme)
{
+ struct winsize w;
struct cli_scrn *scrn = this_scrn;
+ struct sigaction sa;
+
+ memset(&sa, 0, sizeof(struct sigaction));
+ sa.sa_handler = handle_winch;
+ sigaction(SIGWINCH, &sa, NULL);
if (!scrn) {
scrn = malloc(sizeof(struct cli_scrn));
@@ -170,8 +199,10 @@ scrn_create(int scrn_type, int16_t nrows, int16_t ncols, int theme)
rte_atomic32_set(&scrn->pause, SCRN_SCRN_PAUSED);
- scrn->nrows = nrows;
- scrn->ncols = ncols;
+ ioctl(0, TIOCGWINSZ, &w);
+
+ scrn->nrows = w.ws_row;
+ scrn->ncols = w.ws_col;
scrn->theme = theme;
scrn->type = scrn_type;
@@ -187,8 +218,6 @@ scrn_create(int scrn_type, int16_t nrows, int16_t ncols, int theme)
scrn_color(SCRN_DEFAULT_FG, SCRN_DEFAULT_BG, SCRN_OFF);
- scrn_erase(nrows);
-
return 0;
}
@@ -196,7 +225,6 @@ int
scrn_create_with_defaults(int theme)
{
return scrn_create(SCRN_STDIN_TYPE,
- SCRN_DEFAULT_ROWS, SCRN_DEFAULT_COLS,
(theme)? SCRN_THEME_ON : SCRN_THEME_OFF);
}
diff --git a/lib/librte_cli/cli_scrn.h b/lib/librte_cli/cli_scrn.h
index 1faa118..48f41aa 100644
--- a/lib/librte_cli/cli_scrn.h
+++ b/lib/librte_cli/cli_scrn.h
@@ -51,19 +51,120 @@ extern "C" {
#include <string.h>
#include <stdio.h>
#include <stdarg.h>
+#include <unistd.h>
#include <rte_atomic.h>
#include <rte_per_lcore.h>
+#define VT100_INITIALIZE -1
+
+#define vt100_open_square '['
+#define vt100_escape 0x1b
+#define vt100_del 0x7f
+#define ESC "\033"
+
+/* Key codes */
+#define vt100_word_left ESC "b"
+#define vt100_word_right ESC "f"
+#define vt100_suppr ESC "[3~"
+#define vt100_tab "\011"
+
+/* Action codes for cli_vt100 */
+#define vt100_bell "\007"
+#define vt100_bs "\010"
+#define vt100_bs_clear "\b \b"
+
+/* cursor codes */
+#define vt100_cursor_off ESC "[?25l"
+#define vt100_cursor_on ESC "[?25h"
+#define vt100_save_cursor ESC "7"
+#define vt100_restore_cursor ESC "8"
+#define vt100_line_feed ESC "D"
+#define vt100_crnl ESC "E"
+#define vt100_reverse_line_feed ESC "M"
+#define vt100_up_arr ESC "[A"
+#define vt100_down_arr ESC "[B"
+#define vt100_right_arr ESC "[C"
+#define vt100_left_arr ESC "[D"
+#define vt100_up_lines ESC "[%dA"
+#define vt100_down_lines ESC "[%dB"
+#define vt100_right_columns ESC "[%dC"
+#define vt100_left_columns ESC "[%dD"
+#define vt100_home ESC "[H"
+
+#define vt100_pos ESC "[%d;%dH"
+#define vt100_setw ESC "[%d;r"
+#define vt100_clear_right ESC "[0K"
+#define vt100_clear_left ESC "[1K"
+#define vt100_clear_down ESC "[0J"
+#define vt100_clear_up ESC "[1J"
+#define vt100_clear_line ESC "[2K"
+#define vt100_clear_screen ESC "[2J"
+#define vt100_pos_cursor ESC "[%d;%dH"
+#define vt100_multi_right ESC "\133%uC"
+#define vt100_multi_left ESC "\133%uD"
+
+/* Result of parsing : it must be synchronized with
+ * vt100_commands[] in vt100_keys.c */
+enum {
+ VT100_INVALID_KEY = 0,
+ VT100_KEY_UP_ARR,
+ VT100_KEY_DOWN_ARR,
+ VT100_KEY_RIGHT_ARR,
+ VT100_KEY_LEFT_ARR,
+ VT100_KEY_BKSPACE,
+ VT100_KEY_RETURN,
+ VT100_KEY_CTRL_A,
+ VT100_KEY_CTRL_E,
+ VT100_KEY_CTRL_K,
+ VT100_KEY_CTRL_Y,
+ VT100_KEY_CTRL_C,
+ VT100_KEY_CTRL_F,
+ VT100_KEY_CTRL_B,
+ VT100_KEY_SUPPR,
+ VT100_KEY_TAB,
+ VT100_KEY_CTRL_D,
+ VT100_KEY_CTRL_L,
+ VT100_KEY_RETURN2,
+ VT100_KEY_META_BKSPACE,
+ VT100_KEY_WLEFT,
+ VT100_KEY_WRIGHT,
+ VT100_KEY_CTRL_W,
+ VT100_KEY_CTRL_P,
+ VT100_KEY_CTRL_N,
+ VT100_KEY_META_D,
+ VT100_KEY_CTRL_X,
+ VT100_MAX_KEYS
+};
+
+extern const char *vt100_commands[];
+
+enum vt100_parse_state {
+ VT100_INIT,
+ VT100_ESCAPE,
+ VT100_ESCAPE_CSI,
+ VT100_DONE = -1,
+ VT100_CONTINUE = -2
+};
+
+#define VT100_BUF_SIZE 8
+struct cli_vt100 {
+ int bufpos; /** Current offset into buffer */
+ char buf[VT100_BUF_SIZE]; /** cli_vt100 command buffer */
+ enum vt100_parse_state state; /** current cli_vt100 parser state */
+};
+
+struct vt100_cmds {
+ const char *str;
+ void (*func)(void);
+};
+
/** scrn version number */
#define SCRN_VERSION "2.0.0"
/* Add more defines for new types */
#define SCRN_STDIN_TYPE 0
-#define SCRN_DEFAULT_ROWS 44
-#define SCRN_DEFAULT_COLS 132
-
/** Structure to hold information about the screen and control access. */
struct cli_scrn {
rte_atomic32_t pause; /**< Pause the update of the screen. */
@@ -71,12 +172,15 @@ struct cli_scrn {
uint16_t nrows; /**< Max number of rows. */
uint16_t ncols; /**< Max number of columns. */
uint16_t theme; /**< Current theme state on or off */
- uint16_t type; /**< screen I/O type */
+ uint16_t type; /**< screen I/O type */
struct termios oldterm; /**< Old terminal setup information */
FILE *fd_out; /**< File descriptor for output */
FILE *fd_in; /**< File descriptor for input */
};
+/** A single byte to hold port of a Red/Green/Blue color value */
+typedef uint8_t scrn_rgb_t;
+
RTE_DECLARE_PER_LCORE(struct cli_scrn *, scrn);
#define this_scrn RTE_PER_LCORE(scrn)
@@ -105,6 +209,31 @@ typedef enum {
/** A single byte to hold port of a Red/Green/Blue color value */
typedef uint8_t cli_rgb_t;
+static inline int
+scrn_write(const void *str, int len)
+{
+ if (len <= 0)
+ len = strlen(str);
+
+ if (write(fileno(this_scrn->fd_out), str, len) != len)
+ fprintf(stderr, "%s: Write failed\n", __func__);
+
+ return len;
+}
+
+static inline int
+scrn_read(char *buf, int len)
+{
+ int n = 0;
+
+ if (!buf || !len)
+ return 0;
+
+ while(len--)
+ n += read(fileno(this_scrn->fd_in), buf++, 1);
+ return n;
+}
+
static inline void
__attribute__((format(printf, 1, 2)))
scrn_puts(const char *fmt, ...)
@@ -127,7 +256,7 @@ void scrn_fprintf(int16_t r, int16_t c, FILE *f, const char *fmt, ...);
#define _s(_x, _y) static __inline__ void _x { _y; }
/** position cursor to row and column */
-_s(scrn_pos(int r, int c), scrn_puts("\033[%d;%dH", r, c))
+_s(scrn_pos(int r, int c), scrn_puts(vt100_pos, r, c))
/** Move cursor to the top left of the screen */
_s(scrn_top(void), scrn_puts("\033H"))
@@ -195,9 +324,23 @@ _s(scrn_setw(int t), scrn_puts("\033[%d;r", t))
/** Cursor postion report */
_s(scrn_cpos(void), scrn_puts("\033[6n"))
-/* Report Cursor Position <ESC>[{ROW};{COLUMN}R
- Generated by the device in response to a Query Cursor Position request;
- reports current cursor position. */
+/** Cursor move right <n> characters */
+_s(scrn_cnright(int n), scrn_puts("\033[%dC", n))
+
+/** Cursor move left <n> characters */
+_s(scrn_cnleft(int n), scrn_puts("\033[%dD", n))
+
+/** New line */
+_s(scrn_newline(void), scrn_puts("\033[20h"))
+
+/** Move one character right */
+_s(scrn_cright(void), scrn_puts("\033[C"))
+
+/** Move one character left */
+_s(scrn_cleft(void), scrn_puts("\033[D"))
+
+/** Move cursor to begining of line */
+_s(scrn_bol(void), scrn_puts("\r"))
/** Return the version string */
static __inline__ const char *
@@ -262,7 +405,6 @@ scrn_center_col(int16_t ncols, const char *msg)
static __inline__ void
scrn_erase(int16_t nrows)
{
-
scrn_setw(1); /* Clear the window to full screen. */
scrn_pos(nrows + 1, 1); /* Put cursor on the last row. */
}
@@ -335,12 +477,90 @@ scrn_rgb(uint8_t fg_bg, cli_rgb_t r, cli_rgb_t g, cli_rgb_t b)
scrn_puts("\033[%d;2;%d;%d;%dm", fg_bg, r, g, b);
}
+/** Set the foreground color + attribute at the current cursor position */
+static __inline__ int
+scrn_fgcolor_str(char *str, scrn_color_e color, scrn_attr_e attr)
+{
+ return snprintf(str, 16, ESC "[%d;%dm", attr, color + 30);
+}
+
+/** Set the background color + attribute at the current cursor position */
+static __inline__ int
+scrn_bgcolor_str(char *str, scrn_color_e color, scrn_attr_e attr)
+{
+ return snprintf(str, 16, ESC "[%d;%dm", attr, color + 40);
+}
+
+/** Set the foreground/background color + attribute at the current cursor position */
+static __inline__ int
+scrn_fgbgcolor_str(char *str, scrn_color_e fg, scrn_color_e bg, scrn_attr_e attr)
+{
+ return snprintf(str, 16, ESC "[%d;%d;%dm", attr, fg + 30, bg + 40);
+}
+
+/**
+ * Main routine to set color for foreground and background and attribute at
+ * the current position.
+ */
+static __inline__ int
+scrn_color_str(char *str, scrn_color_e fg, scrn_color_e bg, scrn_attr_e attr)
+{
+ if ( (fg != SCRN_NO_CHANGE) && (bg != SCRN_NO_CHANGE))
+ return scrn_fgbgcolor_str(str, fg, bg, attr);
+ else if (fg == SCRN_NO_CHANGE)
+ return scrn_bgcolor_str(str, bg, attr);
+ else if (bg == SCRN_NO_CHANGE)
+ return scrn_fgcolor_str(str, fg, attr);
+ else
+ return 0;
+}
+
+/** Setup for 256 RGB color methods. A routine to output RGB color codes if supported */
+static __inline__ int
+scrn_rgb_str(char *str, uint8_t fg_bg, scrn_rgb_t r, scrn_rgb_t g, scrn_rgb_t b)
+{
+ return snprintf(str, 16, ESC "[%d;2;%d;%d;%dm", fg_bg, r, g, b);
+}
+
/** External functions used for positioning the cursor and outputing a string
like printf */
-int scrn_create(int scrn_type, int16_t nrows, int16_t ncols, int theme);
+int scrn_create(int scrn_type, int theme);
int scrn_create_with_defaults(int theme);
void scrn_destroy(void);
+/**
+ * Create the cli_vt100 structure
+ *
+ * @return
+ * Pointer to cli_vt100 structure or NULL on error
+ */
+struct cli_vt100 *vt100_setup(void);
+
+/**
+ * Destroy the cli_vt100 structure
+ *
+ * @param
+ * The pointer to the cli_vt100 structure.
+ */
+void vt100_free(struct cli_vt100 *vt);
+
+/**
+ * Input a new character.
+ *
+ * @param vt
+ * The pointer to the cli_vt100 structure
+ * @param c
+ * The character to parse for cli_vt100 commands
+ * @return
+ * -1 if the character is not part of a control sequence
+ * -2 if c is not the last char of a control sequence
+ * Else the index in vt100_commands[]
+ */
+int vt100_parse_input(struct cli_vt100 *vt, uint8_t c);
+
+void vt100_do_cmd(int idx);
+struct vt100_cmds *vt100_get_cmds(void);
+
#ifdef __cplusplus
}
#endif
diff --git a/lib/librte_cli/cli_vt100.c b/lib/librte_cli/cli_vt100.c
index aa2465e..4a2ae43 100644
--- a/lib/librte_cli/cli_vt100.c
+++ b/lib/librte_cli/cli_vt100.c
@@ -1,7 +1,7 @@
/*-
* BSD LICENSE
*
- * Copyright(c) 2010-2014 Intel Corporation. All rights reserved.
+ * Copyright(c) 2016-2017 Intel Corporation. All rights reserved.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
@@ -31,36 +31,293 @@
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
-/*
- * Copyright (c) 2009, Olivier MATZ <zer0@droids-corp.org>
- * All rights reserved.
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions are met:
- *
- * * Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- * * Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution.
- * * Neither the name of the University of California, Berkeley nor the
- * names of its contributors may be used to endorse or promote products
- * derived from this software without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND ANY
- * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
- * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
- * DISCLAIMED. IN NO EVENT SHALL THE REGENTS AND CONTRIBUTORS BE LIABLE FOR ANY
- * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
- * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
- * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
- * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
- * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
- * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- */
-
#include "cli.h"
-#include "cli_vt100.h"
-#include "cli_vt100_keys.h"
+#include "cli_input.h"
+#include "cli_scrn.h"
+#include "cli_auto_complete.h"
+
+static inline void
+key_up_arr(void)
+{
+ struct gapbuf *gb = this_cli->gb;
+ char *line;
+
+ line = cli_history_prev();
+ if (line) {
+ gb_reset_buf(gb);
+ gb_set_point(gb, gb_str_insert(gb, line, 0));
+ cli_set_flag(DISPLAY_LINE | CLEAR_LINE);
+ }
+}
+
+static inline void
+key_down_arr(void)
+{
+ struct gapbuf *gb = this_cli->gb;
+ char *line;
+
+ line = cli_history_next();
+ if (line) {
+ gb_reset_buf(gb);
+ gb_set_point(gb, gb_str_insert(gb, line, 0));
+ cli_set_flag(DISPLAY_LINE | CLEAR_LINE);
+ }
+}
+
+static inline void
+key_right_arr(void)
+{
+ struct gapbuf *gb = this_cli->gb;
+
+ if (!gb_eof(gb)) {
+ scrn_write(vt100_right_arr, 0);
+ gb_move_right(gb);
+ }
+}
+
+static inline void
+key_left_arr(void)
+{
+ struct gapbuf *gb = this_cli->gb;
+
+ if (!gb_point_at_start(gb)) {
+ scrn_write(vt100_left_arr, 0);
+ gb_move_left(gb);
+ }
+}
+
+static inline void
+key_backspace(void)
+{
+ struct gapbuf *gb = this_cli->gb;
+
+ if (!gb_point_at_start(gb)) {
+ cli_cursor_left();
+
+ gb_move_left(gb);
+
+ gb_del(gb, 1);
+
+ cli_set_flag(DELETE_CHAR);
+ }
+}
+
+static inline void
+key_return(void)
+{
+ cli_write("\n", 1);
+
+ cli_execute();
+
+ /* Init buffer must be after execute of command */
+ gb_reset_buf(this_cli->gb);
+
+ /* If not quit command then print prompt */
+ if (!this_cli->quit_flag)
+ this_cli->flags |= DISPLAY_PROMPT;
+ this_cli->curr_hist = NULL;
+}
+
+static inline void
+key_ctrl_a(void)
+{
+ cli_printf(vt100_multi_left, gb_left_data_size(this_cli->gb));
+ gb_set_point(this_cli->gb, 0);
+}
+
+static inline void
+key_ctrl_e(void)
+{
+ cli_printf(vt100_multi_right, gb_right_data_size(this_cli->gb));
+ gb_set_point(this_cli->gb, -1);
+}
+
+static inline void
+key_ctrl_k(void)
+{
+ struct cli *cli = this_cli;
+
+ cli_clear_to_eol();
+ gb_move_gap_to_point(cli->gb);
+ free(cli->kill);
+ if (gb_right_data_size(cli->gb))
+ cli->kill = strndup(gb_end_of_gap(cli->gb),
+ gb_right_data_size(cli->gb) + 1);
+ gb_del(cli->gb, gb_right_data_size(cli->gb));
+}
+
+static inline void
+key_ctrl_y(void)
+{
+ struct cli *cli = this_cli;
+
+ /* Yank and put are Not supported yet */
+ if (cli->kill) {
+ gb_str_insert(cli->gb, cli->kill, strlen(cli->kill));
+ cli_clear_line(-1);
+ cli_redisplay_line();
+ }
+}
+
+static inline void
+key_ctrl_c(void)
+{
+ gb_reset_buf(this_cli->gb);
+ cli_clear_line(-1);
+ this_cli->plen = this_cli->prompt(0);
+ this_cli->curr_hist = NULL;
+}
+
+static inline void
+key_ctrl_f(void)
+{
+ key_right_arr();
+}
+
+static inline void
+key_ctrl_b(void)
+{
+ key_left_arr();
+}
+
+static inline void
+key_suppr(void)
+{
+ gb_del(this_cli->gb, 1);
+ cli_display_right();
+ cli_clear_to_eol();
+}
+
+static inline void
+key_tab(void)
+{
+ cli_auto_complete();
+}
+
+static inline void
+key_ctrl_d(void)
+{
+ gb_dump(this_cli->gb, NULL);
+}
+
+static inline void
+key_ctrl_l(void)
+{
+ cli_clear_screen();
+ cli_clear_line(-1);
+ cli_redisplay_line();
+}
+
+static inline void
+key_return2(void)
+{
+ key_return();
+}
+
+static inline void
+key_meta_backspace(void)
+{
+}
+
+/* meta+b or command+b or window+b or super+b */
+static inline void
+key_word_left(void)
+{
+ do {
+ key_left_arr();
+ if (gb_get_prev(this_cli->gb) == ' ')
+ break;
+ } while (!gb_point_at_start(this_cli->gb));
+}
+
+static inline void
+key_word_right(void)
+{
+ while (!gb_point_at_end(this_cli->gb)) {
+ key_right_arr();
+ if (gb_get(this_cli->gb) == ' ')
+ break;
+ }
+}
+
+static inline void
+key_ctrl_w(void)
+{
+ key_meta_backspace();
+}
+
+static inline void
+key_ctrl_p(void)
+{
+ key_up_arr();
+}
+
+static inline void
+key_ctrl_n(void)
+{
+ key_down_arr();
+}
+
+static inline void
+key_meta_d(void)
+{
+}
+
+static inline void
+key_ctrl_x(void)
+{
+ this_cli->quit_flag = 1;
+}
+
+static inline void
+key_invalid(void)
+{
+}
+
+/* Order must be maintained see cli_vt100.h */
+static struct vt100_cmds vt100_cmd_list[] = {
+ { "Invalid", key_invalid },
+ { vt100_up_arr, key_up_arr }, /* Move cursor up one line */
+ { vt100_down_arr, key_down_arr }, /* Move cursor down on line */
+ { vt100_right_arr, key_right_arr }, /* Move cursor right */
+ { vt100_left_arr, key_left_arr }, /* Move cursor left */
+ { "\177", key_backspace }, /* Cursor Left + delete */
+ { "\n", key_return }, /* Execute command */
+ { "\001", key_ctrl_a }, /* Same as key_left_arr */
+ { "\005", key_ctrl_e }, /* Same as key_right_arr */
+ { "\013", key_ctrl_k }, /* Kill to end of line */
+ { "\031", key_ctrl_y }, /* Put the kill buffer not working */
+ { "\003", key_ctrl_c }, /* Reset line and start over */
+ { "\006", key_ctrl_f }, /* Same as key_right_arr */
+ { "\002", key_ctrl_b }, /* Same as key_left_arr */
+ { vt100_suppr, key_suppr }, /* delete 1 char from the left */
+ { vt100_tab, key_tab }, /* Auto complete */
+ { "\004", key_ctrl_d }, /* Debug output if enabled */
+ { "\014", key_ctrl_l }, /* redraw screen */
+ { "\r", key_return2 }, /* Same as key_return */
+ { "\033\177", key_meta_backspace },/* Delete word left */
+ { vt100_word_left, key_word_left }, /* Word left */
+ { vt100_word_right, key_word_right }, /* Word right */
+ { "\027", key_ctrl_w }, /* Same as key_meta_backspace */
+ { "\020", key_ctrl_p }, /* Same as key_up_arr */
+ { "\016", key_ctrl_n }, /* Same as key_down_arr */
+ { "\033\144", key_meta_d }, /* Delete word right */
+ { "\030", key_ctrl_x }, /* Terminate application */
+ { NULL, NULL }
+};
+
+void
+vt100_do_cmd(int idx)
+{
+ if (idx < VT100_MAX_KEYS)
+ vt100_cmd_list[idx].func();
+}
+
+struct vt100_cmds *
+vt100_get_cmds(void)
+{
+ return vt100_cmd_list;
+}
static int
vt100_find_cmd(char *buf, unsigned int size)
@@ -69,7 +326,7 @@ vt100_find_cmd(char *buf, unsigned int size)
size_t cmdlen;
int i;
- for (i = 0, cmd = vt100_cmd_list; cmd->str; cmd++, i++) {
+ for (i = 0, cmd = vt100_get_cmds(); cmd->str; cmd++, i++) {
cmdlen = strnlen(cmd->str, VT100_BUF_SIZE);
if ((size == cmdlen) && !strncmp(buf, cmd->str, cmdlen))
return i;
@@ -129,7 +386,7 @@ vt100_parse_input(struct cli_vt100 *vt, uint8_t c)
}
struct cli_vt100 *
-vt100_create(void)
+vt100_setup(void)
{
struct cli_vt100 *vt;
@@ -143,7 +400,7 @@ vt100_create(void)
}
void
-vt100_destroy(struct cli_vt100 *vt)
+vt100_free(struct cli_vt100 *vt)
{
if (vt)
free(vt);
diff --git a/lib/librte_cli/cli_vt100.h b/lib/librte_cli/cli_vt100.h
deleted file mode 100644
index 116dc86..0000000
--- a/lib/librte_cli/cli_vt100.h
+++ /dev/null
@@ -1,290 +0,0 @@
-/*-
- * BSD LICENSE
- *
- * Copyright(c) 2010-2014 Intel Corporation. All rights reserved.
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- *
- * * Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- * * Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in
- * the documentation and/or other materials provided with the
- * distribution.
- * * Neither the name of Intel Corporation nor the names of its
- * contributors may be used to endorse or promote products derived
- * from this software without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
- * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
- * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
- * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
- * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
- * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
- * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
- * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
- * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
- * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
- * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- */
-
-/*
- * Copyright (c) 2009, Olivier MATZ <zer0@droids-corp.org>
- * All rights reserved.
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions are met:
- *
- * * Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- * * Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution.
- * * Neither the name of the University of California, Berkeley nor the
- * names of its contributors may be used to endorse or promote products
- * derived from this software without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND ANY
- * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
- * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
- * DISCLAIMED. IN NO EVENT SHALL THE REGENTS AND CONTRIBUTORS BE LIABLE FOR ANY
- * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
- * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
- * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
- * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
- * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
- * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- */
-
-#ifndef _VT100_H_
-#define _VT100_H_
-
-#include <stdio.h>
-#include <stdint.h>
-
-#include <cli_scrn.h>
-
-#ifdef __cplusplus
-extern "C" {
-#endif
-
-#define VT100_INITIALIZE -1
-
-#define vt100_open_square '['
-#define vt100_escape 0x1b
-#define vt100_del 0x7f
-#define vt100_q_escape "\033"
-
-/* Key codes */
-#define vt100_up_arr "\033[A"
-#define vt100_down_arr "\033[B"
-#define vt100_right_arr "\033[C"
-#define vt100_left_arr "\033[D"
-#define vt100_word_left "\033b"
-#define vt100_word_right "\033f"
-#define vt100_suppr "\033[3~"
-#define vt100_tab "\011"
-
-/* Action codes for cli_vt100 */
-#define vt100_bell "\007"
-#define vt100_bs "\010"
-#define vt100_bs_clear "\b \b"
-#define vt100_crnl "\012\015"
-#define vt100_home "\033M\033E"
-
-/* cursor codes */
-#define vt100_pos "\033[%d;%dH"
-#define vt100_setw "\033[%d;r"
-#define vt100_save_cursor "\0337"
-#define vt100_restore_cursor "\0338"
-#define vt100_clear_right "\033[0K"
-#define vt100_clear_left "\033[1K"
-#define vt100_clear_down "\033[0J"
-#define vt100_clear_up "\033[1J"
-#define vt100_clear_line "\033[2K"
-#define vt100_clear_screen "\033[2J"
-#define vt100_pos_cursor "\033[%d;%dH"
-#define vt100_multi_right "\033\133%uC"
-#define vt100_multi_left "\033\133%uD"
-
-/* Result of parsing : it must be synchronized with
- * vt100_commands[] in vt100_keys.c */
-enum {
- VT100_INVALID_KEY = 0,
- VT100_KEY_UP_ARR,
- VT100_KEY_DOWN_ARR,
- VT100_KEY_RIGHT_ARR,
- VT100_KEY_LEFT_ARR,
- VT100_KEY_BKSPACE,
- VT100_KEY_RETURN,
- VT100_KEY_CTRL_A,
- VT100_KEY_CTRL_E,
- VT100_KEY_CTRL_K,
- VT100_KEY_CTRL_Y,
- VT100_KEY_CTRL_C,
- VT100_KEY_CTRL_F,
- VT100_KEY_CTRL_B,
- VT100_KEY_SUPPR,
- VT100_KEY_TAB,
- VT100_KEY_CTRL_D,
- VT100_KEY_CTRL_L,
- VT100_KEY_RETURN2,
- VT100_KEY_META_BKSPACE,
- VT100_KEY_WLEFT,
- VT100_KEY_WRIGHT,
- VT100_KEY_CTRL_W,
- VT100_KEY_CTRL_P,
- VT100_KEY_CTRL_N,
- VT100_KEY_META_D,
- VT100_KEY_CTRL_X,
- VT100_MAX_KEYS
-};
-
-extern const char *vt100_commands[];
-
-enum vt100_parse_state {
- VT100_INIT,
- VT100_ESCAPE,
- VT100_ESCAPE_CSI,
- VT100_DONE = -1,
- VT100_CONTINUE = -2
-};
-
-#define VT100_BUF_SIZE 8
-struct cli_vt100 {
- int bufpos; /** Current offset into buffer */
- char buf[VT100_BUF_SIZE]; /** cli_vt100 command buffer */
- enum vt100_parse_state state; /** current cli_vt100 parser state */
-};
-
-/** A single byte to hold port of a Red/Green/Blue color value */
-typedef uint8_t scrn_rgb_t;
-
-/** Macro to reduce typing and screen clutter */
-#define cli_puts(...) scrn_puts(__VA_ARGS__)
-
-/** Set the foreground color + attribute at the current cursor position */
-static __inline__ void
-vt100_fgcolor(scrn_color_e color, scrn_attr_e attr)
-{
- cli_puts("\033[%d;%dm", attr, color + 30);
-}
-
-/** Set the background color + attribute at the current cursor position */
-static __inline__ void
-vt100_bgcolor(scrn_color_e color, scrn_attr_e attr)
-{
- cli_puts("\033[%d;%dm", attr, color + 40);
-}
-
-/** Set the foreground/background color + attribute at the current cursor position */
-static __inline__ void
-vt100_fgbgcolor(scrn_color_e fg, scrn_color_e bg, scrn_attr_e attr)
-{
- cli_puts("\033[%d;%d;%dm", attr, fg + 30, bg + 40);
-}
-
-/**
- * Main routine to set color for foreground and background and attribute at
- * the current position.
- */
-static __inline__ void
-vt100_color(scrn_color_e fg, scrn_color_e bg, scrn_attr_e attr)
-{
- if ( (fg != SCRN_NO_CHANGE) && (bg != SCRN_NO_CHANGE))
- vt100_fgbgcolor(fg, bg, attr);
- else if (fg == SCRN_NO_CHANGE)
- vt100_bgcolor(bg, attr);
- else if (bg == SCRN_NO_CHANGE)
- vt100_fgcolor(fg, attr);
-}
-
-/** Setup for 256 RGB color methods. A routine to output RGB color codes if supported */
-static __inline__ void
-vt100_rgb(uint8_t fg_bg, scrn_rgb_t r, scrn_rgb_t g, scrn_rgb_t b)
-{
- cli_puts("\033[%d;2;%d;%d;%dm", fg_bg, r, g, b);
-}
-
-/** Set the foreground color + attribute at the current cursor position */
-static __inline__ int
-vt100_fgcolor_str(char *str, scrn_color_e color, scrn_attr_e attr)
-{
- return snprintf(str, 16, "\033[%d;%dm", attr, color + 30);
-}
-
-/** Set the background color + attribute at the current cursor position */
-static __inline__ int
-vt100_bgcolor_str(char *str, scrn_color_e color, scrn_attr_e attr)
-{
- return snprintf(str, 16, "\033[%d;%dm", attr, color + 40);
-}
-
-/** Set the foreground/background color + attribute at the current cursor position */
-static __inline__ int
-vt100_fgbgcolor_str(char *str, scrn_color_e fg, scrn_color_e bg, scrn_attr_e attr)
-{
- return snprintf(str, 16, "\033[%d;%d;%dm", attr, fg + 30, bg + 40);
-}
-
-/**
- * Main routine to set color for foreground and background and attribute at
- * the current position.
- */
-static __inline__ int
-vt100_color_str(char *str, scrn_color_e fg, scrn_color_e bg, scrn_attr_e attr)
-{
- if ( (fg != SCRN_NO_CHANGE) && (bg != SCRN_NO_CHANGE))
- return vt100_fgbgcolor_str(str, fg, bg, attr);
- else if (fg == SCRN_NO_CHANGE)
- return vt100_bgcolor_str(str, bg, attr);
- else if (bg == SCRN_NO_CHANGE)
- return vt100_fgcolor_str(str, fg, attr);
- else
- return 0;
-}
-
-/** Setup for 256 RGB color methods. A routine to output RGB color codes if supported */
-static __inline__ int
-vt100_rgb_str(char *str, uint8_t fg_bg, scrn_rgb_t r, scrn_rgb_t g, scrn_rgb_t b)
-{
- return snprintf(str, 16, "\033[%d;2;%d;%d;%dm", fg_bg, r, g, b);
-}
-
-/**
- * Create the cli_vt100 structure
- *
- * @return
- * Pointer to cli_vt100 structure or NULL on error
- */
-struct cli_vt100 *vt100_create(void);
-
-/**
- * Destroy the cli_vt100 structure
- *
- * @param
- * The pointer to the cli_vt100 structure.
- */
-void vt100_destroy(struct cli_vt100 *vt);
-
-/**
- * Input a new character.
- *
- * @param vt
- * The pointer to the cli_vt100 structure
- * @param c
- * The character to parse for cli_vt100 commands
- * @return
- * -1 if the character is not part of a control sequence
- * -2 if c is not the last char of a control sequence
- * Else the index in vt100_commands[]
- */
-int vt100_parse_input(struct cli_vt100 *vt, uint8_t c);
-
-#ifdef __cplusplus
-}
-#endif
-
-#endif /* _VT100_H_ */
diff --git a/lib/librte_cli/cli_vt100_keys.c b/lib/librte_cli/cli_vt100_keys.c
deleted file mode 100644
index 1a87531..0000000
--- a/lib/librte_cli/cli_vt100_keys.c
+++ /dev/null
@@ -1,304 +0,0 @@
-/*-
- * BSD LICENSE
- *
- * Copyright(c) 2016-2017 Intel Corporation. All rights reserved.
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- *
- * * Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- * * Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in
- * the documentation and/or other materials provided with the
- * distribution.
- * * Neither the name of Intel Corporation nor the names of its
- * contributors may be used to endorse or promote products derived
- * from this software without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
- * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
- * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
- * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
- * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
- * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
- * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
- * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
- * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
- * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
- * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- */
-
-#include "cli.h"
-#include "cli_vt100_keys.h"
-#include "cli_auto_complete.h"
-
-static inline void
-key_ctrl_x(void)
-{
- this_cli->quit_flag = 1;
-}
-
-static inline void
-key_up_arr(void)
-{
- char *line;
-
- line = cli_history_prev();
- if (line) {
- gb_reset_buf(this_cli->gb);
- cli_clear_line(-1);
- gb_str_insert(this_cli->gb, line, strlen(line));
- cli_display_line();
- }
-}
-
-static inline void
-key_down_arr(void)
-{
- char *line;
-
- line = cli_history_next();
- if (line) {
- gb_reset_buf(this_cli->gb);
- cli_clear_line(-1);
- gb_str_insert(this_cli->gb, line, strlen(line));
- cli_display_line();
- }
-}
-
-static inline void
-key_right_arr(void)
-{
- if (!gb_eof(this_cli->gb)) {
- cli_write(vt100_right_arr, -1);
- gb_move_right(this_cli->gb);
- }
-}
-
-static inline void
-key_left_arr(void)
-{
- if (!gb_point_at_start(this_cli->gb)) {
- cli_write(vt100_left_arr, -1);
- gb_move_left(this_cli->gb);
- }
-}
-
-static inline void
-key_backspace(void)
-{
- struct gapbuf *gb = this_cli->gb;
-
- if (!gb_point_at_start(gb)) {
- cli_cursor_left();
- cli_save_cursor();
-
- gb_move_left(gb);
-
- gb_del(gb, 1);
-
- cli_display_right();
- cli_write(" ", 1);
-
- cli_restore_cursor();
- }
-}
-
-static inline void
-key_return(void)
-{
- cli_write("\n", 1);
-
- cli_execute();
-
- /* Init buffer must be after execute of command */
- gb_reset_buf(this_cli->gb);
-
- /* Found quit command */
- if (!this_cli->quit_flag)
- this_cli->prompt(0);
-}
-
-static inline void
-key_ctrl_a(void)
-{
- cli_printf(vt100_multi_left, gb_left_data_size(this_cli->gb));
- gb_set_point(this_cli->gb, 0);
-}
-
-static inline void
-key_ctrl_e(void)
-{
- cli_printf(vt100_multi_right, gb_right_data_size(this_cli->gb));
- gb_set_point(this_cli->gb, -1);
-}
-
-static inline void
-key_ctrl_k(void)
-{
- struct cli *cli = this_cli;
-
- cli_clear_to_eol();
- gb_move_gap_to_point(cli->gb);
- free(cli->kill);
- if (gb_right_data_size(cli->gb))
- cli->kill = strndup(gb_end_of_gap(cli->gb),
- gb_right_data_size(cli->gb) + 1);
- gb_del(cli->gb, gb_right_data_size(cli->gb));
-}
-
-static inline void
-key_ctrl_y(void)
-{
- struct cli *cli = this_cli;
-
- /* Yank and put are Not supported yet */
- if (cli->kill) {
- gb_str_insert(cli->gb, cli->kill, strlen(cli->kill));
- cli_clear_line(-1);
- cli_display_line();
- }
-}
-
-static inline void
-key_ctrl_c(void)
-{
- gb_reset_buf(this_cli->gb);
- cli_clear_line(-1);
- this_cli->prompt(0);
-}
-
-static inline void
-key_ctrl_f(void)
-{
- key_right_arr();
-}
-
-static inline void
-key_ctrl_b(void)
-{
- key_left_arr();
-}
-
-static inline void
-key_suppr(void)
-{
- gb_del(this_cli->gb, 1);
- cli_display_right();
- cli_clear_to_eol();
-}
-
-static inline void
-key_tab(void)
-{
- cli_auto_complete();
-}
-
-static inline void
-key_ctrl_d(void)
-{
- gb_dump(this_cli->gb, NULL);
-}
-
-static inline void
-key_ctrl_l(void)
-{
- cli_clear_screen();
- cli_clear_line(-1);
- cli_display_line();
-}
-
-static inline void
-key_return2(void)
-{
- key_return();
-}
-
-static inline void
-key_meta_backspace(void)
-{
-}
-
-/* meta+b or command+b or window+b or super+b */
-static inline void
-key_word_left(void)
-{
- do {
- key_left_arr();
- if (gb_get_prev(this_cli->gb) == ' ')
- break;
- } while (!gb_point_at_start(this_cli->gb));
-}
-
-static inline void
-key_word_right(void)
-{
- while (!gb_point_at_end(this_cli->gb)) {
- key_right_arr();
- if (gb_get(this_cli->gb) == ' ')
- break;
- }
-}
-
-static inline void
-key_ctrl_w(void)
-{
- key_meta_backspace();
-}
-
-static inline void
-key_ctrl_p(void)
-{
- key_up_arr();
-}
-
-static inline void
-key_ctrl_n(void)
-{
- key_down_arr();
-}
-
-static inline void
-key_meta_d(void)
-{
-}
-
-static inline void
-key_invalid(void)
-{
-}
-
-/* Order must be maintained see cli_vt100.h */
-struct vt100_cmds vt100_cmd_list[] = {
- { "Invalid", key_invalid },
- { vt100_up_arr, key_up_arr }, /* Move cursor up one line */
- { vt100_down_arr, key_down_arr }, /* Move cursor down on line */
- { vt100_right_arr, key_right_arr }, /* Move cursor right */
- { vt100_left_arr, key_left_arr }, /* Move cursor left */
- { "\177", key_backspace }, /* Cursor Left + delete */
- { "\n", key_return }, /* Execute command */
- { "\001", key_ctrl_a }, /* Same as key_left_arr */
- { "\005", key_ctrl_e }, /* Same as key_right_arr */
- { "\013", key_ctrl_k }, /* Kill to end of line */
- { "\031", key_ctrl_y }, /* Put the kill buffer not working */
- { "\003", key_ctrl_c }, /* Reset line and start over */
- { "\006", key_ctrl_f }, /* Same as key_right_arr */
- { "\002", key_ctrl_b }, /* Same as key_left_arr */
- { vt100_suppr, key_suppr }, /* delete 1 char from the left */
- { vt100_tab, key_tab }, /* Auto complete */
- { "\004", key_ctrl_d }, /* Debug output if enabled */
- { "\014", key_ctrl_l }, /* redraw screen */
- { "\r", key_return2 }, /* Same as key_return */
- { "\033\177", key_meta_backspace }, /* Delete word left */
- { vt100_word_left, key_word_left }, /* Word left */
- { vt100_word_right, key_word_right }, /* Word right */
- { "\027", key_ctrl_w }, /* Same as key_meta_backspace */
- { "\020", key_ctrl_p }, /* Same as key_up_arr */
- { "\016", key_ctrl_n }, /* Same as key_down_arr */
- { "\033\144", key_meta_d }, /* Delete word right */
- { "\030", key_ctrl_x }, /* Terminate application */
- { NULL, NULL }
-};
diff --git a/lib/librte_cli/cli_vt100_keys.h b/lib/librte_cli/cli_vt100_keys.h
deleted file mode 100644
index 5baa6e1..0000000
--- a/lib/librte_cli/cli_vt100_keys.h
+++ /dev/null
@@ -1,60 +0,0 @@
-/*-
- * BSD LICENSE
- *
- * Copyright(c) 2016-2017 Intel Corporation. All rights reserved.
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- *
- * * Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- * * Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in
- * the documentation and/or other materials provided with the
- * distribution.
- * * Neither the name of Intel Corporation nor the names of its
- * contributors may be used to endorse or promote products derived
- * from this software without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
- * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
- * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
- * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
- * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
- * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
- * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
- * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
- * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
- * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
- * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- */
-
-#ifndef _CLI_VT100_KEYS_H_
-#define _CLI_VT100_KEYS_H_
-
-/**
- * @file
- * RTE Command line interface
- *
- */
-
-#include "cli.h"
-
-#ifdef __cplusplus
-extern "C" {
-#endif
-
-struct vt100_cmds {
- const char *str;
- void (*func)(void);
-};
-
-extern struct vt100_cmds vt100_cmd_list[];
-
-#ifdef __cplusplus
-}
-#endif
-
-#endif /* _CLI_VT100_KEYS_H_ */