diff options
author | Tom Rini <trini@konsulko.com> | 2023-10-12 08:15:31 -0400 |
---|---|---|
committer | Tom Rini <trini@konsulko.com> | 2023-10-12 08:15:31 -0400 |
commit | f9a47ac8d97da2b3aaf463f268a9a872a8d921df (patch) | |
tree | 0a67c8aa5bd018d376f8073147cea33c6772861b /include/cli.h | |
parent | 429d59c3e5e6a3d3d6cd9f3c59c075e9037459c0 (diff) | |
parent | 7e5b637483e03ce303ce84ec6b24156c6658ef46 (diff) |
Merge branch '2023-10-12-expo-add-support-for-edting-lines-of-text'
To quote the author:
So far expo only supports menus. These are quite flexible for various
kinds of settings, but cannot deal with free-form input, such as a
serial number or a machine name.
This series adds support for a textline object, which is a single line
of text. It has a maximum length and its value is stored within the expo
structure.
U-Boot already has a command-line editor which provides most of the
features needed by expo. But the code runs in its own loop and only
returns when the line is finished. This is not suitable for expo, which
must handle a keypress at a time, returning to its caller after each
one.
In order to use the CLI code, some significant refactoring is included
here. This mostly involves moving the internal loop of the CLI to a
separate function and recording its state in a struct, just as was done
for single keypresses some time back. A minor addition is support for
Ctrl-W to delete a word, since strangely this is currently only present
in the simple version.
The video-console system provides most of the features needed by
testline, but a few things are missing. This series provides:
- primitive cursor support so the user can see where he is typing
- saving and restoring of the text-entry context, so that expo can allow
the user to continue where he left off, including deleting previously
entered characters correctly (for Truetype)
- obtaining the nominal width of a string of n characters, so that a
suitable width can be chosen for the textline object
Note that no support is provided for clearing the cursor. This was
addressed in a previous series[1] which could perhaps be rebased. For
this implementation, the cursor is therefore not enabled for the normal
command line, only for expo.
Reading and writing textline objects is supported for FDT and
environment, but not for CMOS RAM, since it would likely use too much
RAM to store a string.
In terms of code size, the overall size increase is 180 bytes for
Thumb02 boards, 160 of whcih is the addition of Ctrl-W to delete a word.
[1] https://patchwork.ozlabs.org/project/uboot/list/?series=280178&state=*
Diffstat (limited to 'include/cli.h')
-rw-r--r-- | include/cli.h | 51 |
1 files changed, 51 insertions, 0 deletions
diff --git a/include/cli.h b/include/cli.h index 094a6602d70..e183d561369 100644 --- a/include/cli.h +++ b/include/cli.h @@ -8,6 +8,7 @@ #define __CLI_H #include <stdbool.h> +#include <linux/types.h> /** * struct cli_ch_state - state information for reading cmdline characters @@ -25,6 +26,29 @@ struct cli_ch_state { }; /** + * struct cli_line_state - state of the line editor + * + * @num: Current cursor position, where 0 is the start + * @eol_num: Number of characters in the buffer + * @insert: true if in 'insert' mode + * @history: true if history should be accessible + * @cmd_complete: true if tab completion should be enabled (requires @prompt to + * be set) + * @buf: Buffer containing line + * @prompt: Prompt for the line + */ +struct cli_line_state { + uint num; + uint eol_num; + uint len; + bool insert; + bool history; + bool cmd_complete; + char *buf; + const char *prompt; +}; + +/** * Go into the command loop * * This will return if we get a timeout waiting for a command. See @@ -229,4 +253,31 @@ void cli_ch_init(struct cli_ch_state *cch); */ int cli_ch_process(struct cli_ch_state *cch, int ichar); +/** + * cread_line_process_ch() - Process a character for line input + * + * @cls: CLI line state + * @ichar: Character to process + * Return: 0 if input is complete, with line in cls->buf, -EINTR if input was + * cancelled with Ctrl-C, -EAGAIN if more characters are needed + */ +int cread_line_process_ch(struct cli_line_state *cls, char ichar); + +/** + * cli_cread_init() - Set up a new cread struct + * + * Sets up a new cread state, with history and cmd_complete set to false + * + * After calling this, you can use cread_line_process_ch() to process characters + * received from the user. + * + * @cls: CLI line state + * @buf: Text buffer containing the initial text + * @buf_size: Buffer size, including nul terminator + */ +void cli_cread_init(struct cli_line_state *cls, char *buf, uint buf_size); + +/** cread_print_hist_list() - Print the command-line history list */ +void cread_print_hist_list(void); + #endif |