[shell] add finsh_set_prompt().
This commit is contained in:
parent
85e732ddaf
commit
4f1112f838
@ -56,11 +56,35 @@ ALIGN(RT_ALIGN_SIZE)
|
|||||||
static char finsh_thread_stack[FINSH_THREAD_STACK_SIZE];
|
static char finsh_thread_stack[FINSH_THREAD_STACK_SIZE];
|
||||||
#endif
|
#endif
|
||||||
struct finsh_shell *shell;
|
struct finsh_shell *shell;
|
||||||
|
static char *finsh_prompt_custom = RT_NULL;
|
||||||
|
|
||||||
|
#ifdef RT_USING_HEAP
|
||||||
|
int finsh_set_prompt(const char * prompt)
|
||||||
|
{
|
||||||
|
if(finsh_prompt_custom)
|
||||||
|
{
|
||||||
|
rt_free(finsh_prompt_custom);
|
||||||
|
finsh_prompt_custom = RT_NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* strdup */
|
||||||
|
if(prompt)
|
||||||
|
{
|
||||||
|
finsh_prompt_custom = rt_malloc(strlen(prompt)+1);
|
||||||
|
if(finsh_prompt_custom)
|
||||||
|
{
|
||||||
|
strcpy(finsh_prompt_custom, prompt);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
#endif /* RT_USING_HEAP */
|
||||||
|
|
||||||
#if defined(FINSH_USING_MSH) || (defined(RT_USING_DFS) && defined(DFS_USING_WORKDIR))
|
|
||||||
#if defined(RT_USING_DFS)
|
#if defined(RT_USING_DFS)
|
||||||
#include <dfs_posix.h>
|
#include <dfs_posix.h>
|
||||||
#endif
|
#endif /* RT_USING_DFS */
|
||||||
|
|
||||||
const char *finsh_get_prompt()
|
const char *finsh_get_prompt()
|
||||||
{
|
{
|
||||||
#define _MSH_PROMPT "msh "
|
#define _MSH_PROMPT "msh "
|
||||||
@ -74,6 +98,12 @@ const char *finsh_get_prompt()
|
|||||||
return finsh_prompt;
|
return finsh_prompt;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if(finsh_prompt_custom)
|
||||||
|
{
|
||||||
|
strncpy(finsh_prompt, finsh_prompt_custom, sizeof(finsh_prompt)-1);
|
||||||
|
return finsh_prompt;
|
||||||
|
}
|
||||||
|
|
||||||
#ifdef FINSH_USING_MSH
|
#ifdef FINSH_USING_MSH
|
||||||
if (msh_is_used()) strcpy(finsh_prompt, _MSH_PROMPT);
|
if (msh_is_used()) strcpy(finsh_prompt, _MSH_PROMPT);
|
||||||
else
|
else
|
||||||
@ -89,7 +119,6 @@ const char *finsh_get_prompt()
|
|||||||
|
|
||||||
return finsh_prompt;
|
return finsh_prompt;
|
||||||
}
|
}
|
||||||
#endif
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @ingroup finsh
|
* @ingroup finsh
|
||||||
|
@ -44,12 +44,10 @@
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
#define FINSH_OPTION_ECHO 0x01
|
#define FINSH_OPTION_ECHO 0x01
|
||||||
#if defined(FINSH_USING_MSH) || (defined(RT_USING_DFS) && defined(DFS_USING_WORKDIR))
|
|
||||||
#define FINSH_PROMPT finsh_get_prompt()
|
#define FINSH_PROMPT finsh_get_prompt()
|
||||||
const char* finsh_get_prompt(void);
|
const char* finsh_get_prompt(void);
|
||||||
#else
|
int finsh_set_prompt(const char * prompt);
|
||||||
#define FINSH_PROMPT "finsh>>"
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#ifdef FINSH_USING_HISTORY
|
#ifdef FINSH_USING_HISTORY
|
||||||
#ifndef FINSH_HISTORY_LINES
|
#ifndef FINSH_HISTORY_LINES
|
||||||
|
Loading…
x
Reference in New Issue
Block a user