Chapter 2. API Reference
History
linenoiseHistorySetMaxLen() This function sets the number of most recently typed commands to be kept
in memory. Users can navigate the history using up/down arrows.
linenoiseHistoryAdd() Linenoise does not automatically add commands to history. Instead, applications
need to call this function to add command strings to the history.
linenoiseHistorySave() Function saves command history from RAM to a text file, for example on an SD
card or on a filesystem in flash memory.
linenoiseHistoryLoad() Counterpart to linenoiseHistorySave(), loads history from a file.
linenoiseHistoryFree() Releases memory used to store command history. Call this function when done
working with linenoise library.
Splitting of command line into arguments
console component provides
guments. The function returns the number of arguments found (argc) and fills an array of pointers which can be
passed as argv argument to any function which accepts arguments in argc, argv format.
The command line is split into arguments according to the following rules:
• Arguments are separated by spaces
• If spaces within arguments are required, they can be escaped using \ (backslash) character.
• Other escape sequences which are recognized are \\ (which produces literal backslash) and \", which pro-
duces a double quote.
• Arguments can be quoted using double quotes. Quotes may appear only in the beginning and at the end of the
argument. Quotes within the argument must be escaped as mentioned above. Quotes surrounding the argument
are stripped by esp_console_split_argv function.
Examples:
• abc def 1 20 .3 ⟶ [ abc, def, 1, 20, .3 ]
• abc "123 456" def ⟶ [ abc, 123 456, def ]
• `a\ b\\c\" ⟶ [ a b\c" ]
Argument parsing
For argument parsing, console component includes
argtable3. Github repository also includes examples.
Command registration and dispatching
console component includes utility functions which handle registration of commands, matching commands typed
by the user to registered ones, and calling these commands with the arguments given on the command line.
Application first initializes command registration module using a call to esp_console_init(), and calls
esp_console_cmd_register()
For each command, application provides the following information (in the form of esp_console_cmd_t struc-
ture):
• Command name (string without spaces)
• Help text explaining what the command does
• Optional hint text listing the arguments of the command. If application uses Argtable3 for argument pars-
ing, hint text can be generated automatically by providing a pointer to argtable argument definitions structure
instead.
• The command handler function.
A few other functions are provided by the command registration module:
Espressif Systems
esp_console_split_argv()
argtable3
function to register command handlers.
799
Submit Document Feedback
function to split command line string into ar-
library. Please see
tutorial
for an introduction to
Release v4.4
Need help?
Do you have a question about the ESP32-S2 and is the answer not in the manual?