nshlib/prompt: extend NSH prompt string management

Currently NSH prompt is defined at build time, thus improper for AMP cases
where the same NSH binary is used on different nodes as the same NSH prompt
shows on all nodes.

This patch attempts to support runtime prompt string population from ordered
sources:
  - the environment variable defined by NSH_PROMPT_ENV plus suffix
  - the NSH_PROMPT_STRING
  - the HOSTNAME plus suffix
The suffix is defined by NSH_PROMPT_SUFFIX so that to clearly separate the
command inputs.

Changes in `nshlib/`

- Kconfig:       add configs NSH_PROMPT_MAX/ENV/SUFFIX etc
- nsh.h:         adjust g_nshprompt defs, add nsh_update_prompt
- nsh_parse.c    relocate g_nshpromt to nsh_prompt.c
- nsh_init.c     revise to use nsh_update_prompt once
- nsh_session.c  revise to use methods in nsh_prompt.c
- Makefile       add nsh_prompt.c
- CMakeLists.txt add nsh_prompt.c

New additions in `nshlib/`

- nsh_prompt.c   prompt related data structures and methods.

Signed-off-by: Yanfeng Liu <yfliu2008@qq.com>
This commit is contained in:
Yanfeng Liu
2024-02-22 03:11:50 +08:00
committed by Xiang Xiao
parent f1137b3b55
commit 31908b3128
8 changed files with 147 additions and 12 deletions

View File

@@ -110,10 +110,14 @@ void nsh_initialize(void)
FAR struct console_stdio_s *pstate;
#endif
#if defined(CONFIG_NSH_READLINE) && defined(CONFIG_READLINE_TABCOMPLETION)
/* Configure the NSH prompt */
/* populate NSH prompt string */
readline_prompt(g_nshprompt);
nsh_update_prompt();
#if defined(CONFIG_NSH_READLINE) && defined(CONFIG_READLINE_TABCOMPLETION)
/* Configure readline prompt */
readline_prompt(nsh_prompt());
# ifdef CONFIG_READLINE_HAVE_EXTMATCH
/* Set up for tab completion on NSH commands */