summaryrefslogtreecommitdiff
path: root/components
diff options
context:
space:
mode:
authorBernard Xiong <[email protected]>2018-07-04 07:15:03 +0800
committerGitHub <[email protected]>2018-07-04 07:15:03 +0800
commit33fb280140c0bd9d235433f393942502d681aee4 (patch)
tree71b77d03010792a79ae9d8ba86fda09d9b07ae6d /components
parenteb821ae0319279cf8bad01438c958be92577f998 (diff)
parentefada8768e688504a961c0f185ffbecd46266300 (diff)
Merge pull request #1601 from aozima/shell_dev
update shell prompt.
Diffstat (limited to 'components')
-rw-r--r--components/finsh/shell.c72
-rw-r--r--components/finsh/shell.h10
2 files changed, 75 insertions, 7 deletions
diff --git a/components/finsh/shell.c b/components/finsh/shell.c
index 6bdb418120..29034bb286 100644
--- a/components/finsh/shell.c
+++ b/components/finsh/shell.c
@@ -34,6 +34,7 @@
* 2011-02-23 Bernard fix variable section end issue of finsh shell
* initialization when use GNU GCC compiler.
* 2016-11-26 armink add password authentication
+ * 2018-07-02 aozima add custome prompt support.
*/
#include <rthw.h>
@@ -56,17 +57,54 @@ 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 "
#define _PROMPT "finsh "
static char finsh_prompt[RT_CONSOLEBUF_SIZE + 1] = {0};
+ /* check prompt mode */
+ if (!shell->prompt_mode)
+ {
+ finsh_prompt[0] = '\0';
+ 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
@@ -82,7 +120,34 @@ const char *finsh_get_prompt()
return finsh_prompt;
}
-#endif
+
+/**
+ * @ingroup finsh
+ *
+ * This function get the prompt mode of finsh shell.
+ *
+ * @return prompt the prompt mode, 0 disable prompt mode, other values enable prompt mode.
+ */
+rt_uint32_t finsh_get_prompt_mode(void)
+{
+ RT_ASSERT(shell != RT_NULL);
+ return shell->prompt_mode;
+}
+
+/**
+ * @ingroup finsh
+ *
+ * This function set the prompt mode of finsh shell.
+ *
+ * The parameter 0 disable prompt mode, other values enable prompt mode.
+ *
+ * @param prompt the prompt mode
+ */
+void finsh_set_prompt_mode(rt_uint32_t prompt_mode)
+{
+ RT_ASSERT(shell != RT_NULL);
+ shell->prompt_mode = prompt_mode;
+}
static char finsh_getchar(void)
{
@@ -789,6 +854,7 @@ int finsh_system_init(void)
#endif /* RT_USING_HEAP */
rt_sem_init(&(shell->rx_sem), "shrx", 0, 0);
+ finsh_set_prompt_mode(1);
if (tid != NULL && result == RT_EOK)
rt_thread_startup(tid);
diff --git a/components/finsh/shell.h b/components/finsh/shell.h
index 06b81de518..d0fd66ee78 100644
--- a/components/finsh/shell.h
+++ b/components/finsh/shell.h
@@ -44,12 +44,10 @@
#endif
#define FINSH_OPTION_ECHO 0x01
-#if defined(FINSH_USING_MSH) || (defined(RT_USING_DFS) && defined(DFS_USING_WORKDIR))
+
#define FINSH_PROMPT finsh_get_prompt()
const char* finsh_get_prompt(void);
-#else
-#define FINSH_PROMPT "finsh>>"
-#endif
+int finsh_set_prompt(const char * prompt);
#ifdef FINSH_USING_HISTORY
#ifndef FINSH_HISTORY_LINES
@@ -86,6 +84,7 @@ struct finsh_shell
enum input_stat stat;
rt_uint8_t echo_mode:1;
+ rt_uint8_t prompt_mode: 1;
#ifdef FINSH_USING_HISTORY
rt_uint16_t current_history;
@@ -118,6 +117,9 @@ int finsh_system_init(void);
void finsh_set_device(const char* device_name);
const char* finsh_get_device(void);
+rt_uint32_t finsh_get_prompt_mode(void);
+void finsh_set_prompt_mode(rt_uint32_t prompt_mode);
+
#ifdef FINSH_USING_AUTH
rt_err_t finsh_set_password(const char *password);
const char *finsh_get_password(void);