mirror of
https://github.com/espressif/openthread.git
synced 2026-08-18 16:39:52 +00:00
[cli] add support to configure prompt output (#12884)
This commit introduces the ability to configure whether the CLI interpreter outputs the prompt string (`> `) at runtime. - Adds `mPromptEnabled` boolean flag (enabled by default) under the `OPENTHREAD_CONFIG_CLI_PROMPT_ENABLE` configuration. - Adds the `Interpreter::SetPromptConfig()` method to toggle this behavior. - Updates `Interpreter::OutputPrompt()` to check `mPromptEnabled` before emitting the prompt string.
This commit is contained in:
+15
-3
@@ -79,6 +79,9 @@ Interpreter::Interpreter(Instance *aInstance, otCliOutputCallback aCallback, voi
|
||||
, Utils(aInstance, *this)
|
||||
, mCommandIsPending(false)
|
||||
, mInternalDebugCommand(false)
|
||||
#if OPENTHREAD_CONFIG_CLI_PROMPT_ENABLE
|
||||
, mPromptEnabled(true)
|
||||
#endif
|
||||
, mTimer(*aInstance, HandleTimer, this)
|
||||
#if OPENTHREAD_FTD || OPENTHREAD_MTD
|
||||
#if OPENTHREAD_CONFIG_SNTP_CLIENT_ENABLE
|
||||
@@ -415,6 +418,10 @@ otError Interpreter::SetUserCommands(const otCliCommand *aCommands, uint8_t aLen
|
||||
return error;
|
||||
}
|
||||
|
||||
#if OPENTHREAD_CONFIG_CLI_PROMPT_ENABLE
|
||||
void Interpreter::SetPromptConfig(bool aEnabled) { mPromptEnabled = aEnabled; }
|
||||
#endif
|
||||
|
||||
#if OPENTHREAD_FTD || OPENTHREAD_MTD
|
||||
|
||||
/**
|
||||
@@ -8427,7 +8434,9 @@ void Interpreter::Initialize(otInstance *aInstance, otCliOutputCallback aCallbac
|
||||
void Interpreter::OutputPrompt(void)
|
||||
{
|
||||
#if OPENTHREAD_CONFIG_CLI_PROMPT_ENABLE
|
||||
static const char sPrompt[] = "> ";
|
||||
static const char kPrompt[] = "> ";
|
||||
|
||||
VerifyOrExit(mPromptEnabled);
|
||||
|
||||
// The `OutputFormat()` below is adding the prompt which is not
|
||||
// part of any command output, so we set the `EmittingCommandOutput`
|
||||
@@ -8435,9 +8444,12 @@ void Interpreter::OutputPrompt(void)
|
||||
// log (under `OPENTHREAD_CONFIG_CLI_LOG_INPUT_OUTPUT_ENABLE`).
|
||||
|
||||
SetEmittingCommandOutput(false);
|
||||
OutputFormat("%s", sPrompt);
|
||||
OutputFormat("%s", kPrompt);
|
||||
SetEmittingCommandOutput(true);
|
||||
#endif // OPENTHREAD_CONFIG_CLI_PROMPT_ENABLE
|
||||
|
||||
exit:
|
||||
return;
|
||||
#endif
|
||||
}
|
||||
|
||||
void Interpreter::HandleTimer(Timer &aTimer)
|
||||
|
||||
@@ -184,6 +184,17 @@ public:
|
||||
*/
|
||||
otError SetUserCommands(const otCliCommand *aCommands, uint8_t aLength, void *aContext);
|
||||
|
||||
#if OPENTHREAD_CONFIG_CLI_PROMPT_ENABLE
|
||||
/**
|
||||
* Configures whether or not the CLI interpreter outputs prompt string.
|
||||
*
|
||||
* It is enabled by default.
|
||||
*
|
||||
* @param[in] aEnabled TRUE to enable outputting prompt, FALSE to disable.
|
||||
*/
|
||||
void SetPromptConfig(bool aEnabled);
|
||||
#endif
|
||||
|
||||
protected:
|
||||
static Interpreter *sInterpreter;
|
||||
|
||||
@@ -353,6 +364,9 @@ private:
|
||||
UserCommandsEntry mUserCommands[kMaxUserCommandEntries];
|
||||
bool mCommandIsPending;
|
||||
bool mInternalDebugCommand;
|
||||
#if OPENTHREAD_CONFIG_CLI_PROMPT_ENABLE
|
||||
bool mPromptEnabled;
|
||||
#endif
|
||||
|
||||
TimerMilliContext mTimer;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user