Public Member Functions | Protected Member Functions | Private Member Functions | Private Attributes | List of all members
uuid::console::StreamConsole Class Reference

A command shell console using a Stream for input/output. More...

#include <uuid/console.h>

Inheritance diagram for uuid::console::StreamConsole:
Inheritance graph
[legend]
Collaboration diagram for uuid::console::StreamConsole:
Collaboration graph
[legend]

Public Member Functions

 StreamConsole (std::shared_ptr< Commands > commands, Stream &stream, unsigned int context=0, unsigned int flags=0)
 Create a new StreamConsole shell with the given commands, default context and initial flags. More...
 
size_t write (uint8_t data) override
 Write one byte to the output stream. More...
 
size_t write (const uint8_t *buffer, size_t size) override
 Write an array of bytes to the output stream. More...
 
- Public Member Functions inherited from uuid::console::Shell
void start ()
 Perform startup process for this shell. More...
 
void loop_one ()
 Perform one execution step of this shell. More...
 
bool running () const
 Determine if this shell is still running. More...
 
void stop ()
 Stop this shell from running. More...
 
virtual void operator<< (std::shared_ptr< uuid::log::Message > message)
 Add a new log message. More...
 
uuid::log::Level log_level () const
 Get the current log level. More...
 
void log_level (uuid::log::Level level)
 Set the current log level. More...
 
size_t maximum_command_line_length () const
 Get the maximum length of a command line. More...
 
void maximum_command_line_length (size_t length)
 Set the maximum length of a command line. More...
 
size_t maximum_log_messages () const
 Get the maximum number of queued log messages. More...
 
void maximum_log_messages (size_t count)
 Set the maximum number of queued log messages. More...
 
unsigned long idle_timeout () const
 Get the idle timeout. More...
 
void idle_timeout (unsigned long timeout)
 Set the idle timeout. More...
 
unsigned int context () const
 Get the context at the top of the stack. More...
 
void enter_context (unsigned int context)
 Push a new context onto the stack. More...
 
virtual bool exit_context ()
 Pop a context off the stack. More...
 
void add_flags (unsigned int flags)
 Add one or more flags to the current flags. More...
 
bool has_flags (unsigned int flags, unsigned int not_flags=0) const
 Check if the current flags include all of the specified flags and none of the specified not_flags. More...
 
bool has_all_flags (unsigned int flags) const
 Check if the current flags include all of the specified flags. More...
 
bool has_any_flags (unsigned int flags) const
 Check if the current flags include any of the specified flags. More...
 
void remove_flags (unsigned int flags)
 Remove one or more flags from the current flags. More...
 
void enter_password (const __FlashStringHelper *prompt, password_function function)
 Prompt for a password to be entered on this shell. More...
 
void delay_for (unsigned long ms, delay_function function)
 Stop executing anything on this shell for a period of time. More...
 
void delay_until (uint64_t ms, delay_function function)
 Stop executing anything on this shell until a future time is reached. More...
 
void block_with (blocking_function function)
 Execute a blocking function on this shell until it returns true. More...
 
int available () final override
 Check for available input. More...
 
int read () final override
 Read one byte from the available input. More...
 
int peek () final override
 Read one byte from the available input without advancing to the next one. More...
 
void flush () override
 Does nothing. More...
 
size_t print (const std::string &data)
 Output a string. More...
 
size_t println (const std::string &data)
 Output a string followed by CRLF end of line characters. More...
 
size_t printf (const char *format,...)
 Output a message. More...
 
size_t printf (const __FlashStringHelper *format,...)
 Output a message. More...
 
size_t printfln (const char *format,...)
 Output a message followed by CRLF end of line characters. More...
 
size_t printfln (const __FlashStringHelper *format,...)
 Output a message followed by CRLF end of line characters. More...
 
Commands::AvailableCommands available_commands () const
 Get the available commands in the current context and with the current flags. More...
 
void print_all_available_commands ()
 Output a list of all available commands with their arguments. More...
 

Protected Member Functions

 StreamConsole (Stream &stream)
 Constructor used by intermediate derived classes for multiple inheritance. More...
 
- Protected Member Functions inherited from uuid::console::Shell
 Shell ()=default
 Default constructor used by intermediate derived classes for multiple inheritance. More...
 
 Shell (std::shared_ptr< Commands > commands, unsigned int context=0, unsigned int flags=0)
 Create a new Shell with the given commands, default context and initial flags. More...
 
virtual void erase_current_line ()
 Output ANSI escape sequence to erase the current line. More...
 
virtual void erase_characters (size_t count)
 Output ANSI escape sequence to erase characters. More...
 
virtual void started ()
 Startup complete event. More...
 
virtual void display_banner ()
 Output the startup banner. More...
 
virtual std::string hostname_text ()
 Get the hostname to be included in the command prompt. More...
 
virtual std::string context_text ()
 Get the text indicating the current context, to be included in the command prompt. More...
 
virtual std::string prompt_prefix ()
 Get the prefix to be used at the beginning of the command prompt. More...
 
virtual std::string prompt_suffix ()
 Get the prefix to be used at the end of the command prompt. More...
 
virtual void end_of_transmission ()
 The end of transmission character has been received. More...
 
virtual void stopped ()
 Stop request event. More...
 
void invoke_command (const std::string &line)
 Invoke a command on the shell. More...
 

Private Member Functions

 StreamConsole (const StreamConsole &)=delete
 
StreamConsoleoperator= (const StreamConsole &)=delete
 
bool available_char () override
 Check for at least one character of available input. More...
 
int read_one_char () override
 Read one character from the available input. More...
 
int peek_one_char () override
 Read one character from the available input without advancing to the next one. More...
 

Private Attributes

Stream & stream_
 

Additional Inherited Members

- Public Types inherited from uuid::console::Shell
using password_function = std::function< void(Shell &shell, bool completed, const std::string &password)>
 Function to handle the response to a password entry prompt. More...
 
using delay_function = std::function< void(Shell &shell)>
 Function to handle the end of an execution delay. More...
 
using blocking_function = std::function< bool(Shell &shell, bool stop)>
 Function to handle a blocking operation. More...
 
- Static Public Member Functions inherited from uuid::console::Shell
static void loop_all ()
 Loop through all registered shell objects. More...
 
static const uuid::log::Loggerlogger ()
 Get the built-in uuid::log::Logger instance for shells. More...
 
- Static Public Attributes inherited from uuid::console::Shell
static constexpr size_t MAX_COMMAND_LINE_LENGTH = 80
 
static constexpr size_t MAX_LOG_MESSAGES = 20
 

Detailed Description

A command shell console using a Stream for input/output.

Must be constructed within a std::shared_ptr.

Derived classes must call the public Shell(std::shared_ptr<Commands>, unsigned int, unsigned int) constructor explicitly.

Since
0.1.0

Definition at line 1855 of file console.h.

Constructor & Destructor Documentation

◆ StreamConsole() [1/2]

uuid::console::StreamConsole::StreamConsole ( std::shared_ptr< Commands commands,
Stream &  stream,
unsigned int  context = 0,
unsigned int  flags = 0 
)

Create a new StreamConsole shell with the given commands, default context and initial flags.

The default context is put on the stack and cannot be removed.

Derived classes must not use this constructor. They must call both the public Shell(std::shared_ptr<Commands>, unsigned int, unsigned int) and StreamConsole(Stream&) constructors explicitly.

Parameters
[in]commandsCommands available for execution in this shell.
[in]streamStream used for the input/output of this shell.
[in]contextDefault context for the shell.
[in]flagsInitial flags for the shell.
Since
0.1.0

Definition at line 36 of file stream_console.cpp.

◆ StreamConsole() [2/2]

uuid::console::StreamConsole::StreamConsole ( Stream &  stream)
explicitprotected

Constructor used by intermediate derived classes for multiple inheritance.

This does not initialise the shell completely so the outer derived class must call the public Shell(std::shared_ptr<Commands>, unsigned int, unsigned int) constructor or there will be no commands. Does not put any default context on the stack.

Since
0.1.0

Definition at line 30 of file stream_console.cpp.

Member Function Documentation

◆ available_char()

bool uuid::console::StreamConsole::available_char ( )
overrideprivatevirtual

Check for at least one character of available input.

Returns
True if a character is available, otherwise false.
Since
0.2.0

Implements uuid::console::Shell.

Definition at line 49 of file stream_console.cpp.

◆ peek_one_char()

int uuid::console::StreamConsole::peek_one_char ( )
overrideprivatevirtual

Read one character from the available input without advancing to the next one.

Returns
An unsigned char if input is available, otherwise -1.
Since
0.2.0

Implements uuid::console::Shell.

Definition at line 57 of file stream_console.cpp.

◆ read_one_char()

int uuid::console::StreamConsole::read_one_char ( )
overrideprivatevirtual

Read one character from the available input.

Returns
An unsigned char if input is available, otherwise -1.
Since
0.1.0

Implements uuid::console::Shell.

Definition at line 53 of file stream_console.cpp.

◆ write() [1/2]

size_t uuid::console::StreamConsole::write ( uint8_t  data)
overridevirtual

Write one byte to the output stream.

Parameters
[in]dataData to be output.
Returns
The number of bytes that were output.
Since
0.1.0

Implements uuid::console::Shell.

Definition at line 41 of file stream_console.cpp.

◆ write() [2/2]

size_t uuid::console::StreamConsole::write ( const uint8_t *  buffer,
size_t  size 
)
overridevirtual

Write an array of bytes to the output stream.

Parameters
[in]bufferBuffer to be output.
[in]sizeLength of the buffer.
Returns
The number of bytes that were output.
Since
0.1.0

Implements uuid::console::Shell.

Definition at line 45 of file stream_console.cpp.

Member Data Documentation

◆ stream_

Stream& uuid::console::StreamConsole::stream_
private

Stream used for the input/output of this shell.

Since
0.1.0

Definition at line 1935 of file console.h.


The documentation for this class was generated from the following files: