summaryrefslogtreecommitdiff
path: root/components/finsh/shell.c
diff options
context:
space:
mode:
authoraozima <[email protected]>2018-07-02 16:23:00 +0800
committeraozima <[email protected]>2018-07-02 16:23:00 +0800
commit4f1112f838fbd4b17e9d1e77cd36c72e32d0ae7f (patch)
treed3c4fe83937f45536386174aeba346a41760c9a5 /components/finsh/shell.c
parent85e732ddafba1e2fdf0da3589332e161c16514b2 (diff)
[shell] add finsh_set_prompt().
Diffstat (limited to 'components/finsh/shell.c')
-rw-r--r--components/finsh/shell.c35
1 files changed, 32 insertions, 3 deletions
diff --git a/components/finsh/shell.c b/components/finsh/shell.c
index 667e7ac12a..0109a761bc 100644
--- a/components/finsh/shell.c
+++ b/components/finsh/shell.c
@@ -56,11 +56,35 @@ ALIGN(RT_ALIGN_SIZE)
static char finsh_thread_stack[FINSH_THREAD_STACK_SIZE];
#endif
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)
#include <dfs_posix.h>
-#endif
+#endif /* RT_USING_DFS */
+
const char *finsh_get_prompt()
{
#define _MSH_PROMPT "msh "
@@ -74,6 +98,12 @@ const char *finsh_get_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
if (msh_is_used()) strcpy(finsh_prompt, _MSH_PROMPT);
else
@@ -89,7 +119,6 @@ const char *finsh_get_prompt()
return finsh_prompt;
}
-#endif
/**
* @ingroup finsh