semf
shell.h
Go to the documentation of this file.
1
10#ifndef SEMF_COMMUNICATION_ESH_SHELL_H_
11#define SEMF_COMMUNICATION_ESH_SHELL_H_
12
22#include <array>
23#include <cstdint>
24#include <string_view>
25
26namespace semf::esh
27{
33class Shell
34{
35public:
39 struct Config
40 {
42 char* const lineBuffer;
44 const size_t lineBufferSize;
46 char** const argvBuffer;
48 const size_t argvBufferSize;
52 const size_t numberOfEntries;
54 bool echo;
56 std::string_view prompt;
57 };
63 Shell(UartHardware& uart, const Config& config);
64 Shell(const Shell& other) = delete;
65 virtual ~Shell() = default;
71 void addCommand(Command& cmd);
75 void start();
79 void loop();
82
83private:
85 static constexpr char kDelete = '\177';
87 static constexpr char kEscape = '\33';
88
93 void onCharAvailable(char character);
98 void onTabDone(size_t charCount);
100 void onExecuted();
102 void onArrowUp();
104 void onArrowDown();
106 void updateStateAndPrint();
108 void onError(Error error);
110 void readNextCharacter();
111
113 const Config m_config;
115 History m_history;
117 Printer m_printer;
119 LinkedList<Command> m_commands;
121 Tabulator m_tab;
123 Processor m_processor;
125 ArrowControl m_arrow;
127 int m_count = 0;
129 SEMF_SLOT(m_onCharAvailableSlot, Shell, *this, onCharAvailable, char);
131 SEMF_SLOT(m_restartShell, Shell, *this, start);
133 SEMF_SLOT(m_onTabDoneSlot, Shell, *this, onTabDone, size_t);
135 SEMF_SLOT(m_onExecutedSlot, Shell, *this, onExecuted);
137 SEMF_SLOT(m_onArrowUpSlot, Shell, *this, onArrowUp);
139 SEMF_SLOT(m_onArrowDownSlot, Shell, *this, onArrowDown);
141 SEMF_SLOT(m_readNextCharSlot, Shell, *this, readNextCharacter);
143 SEMF_SLOT(m_onErrorSlot, Shell, *this, onError, Error);
144};
145} // namespace semf::esh
146#endif // SEMF_COMMUNICATION_ESH_SHELL_H_
Class for representing errors. Every error should have a unique source code. As a user feel encourage...
Definition: error.h:22
LinkedList is an managed double linked list implementation.
Definition: linkedlist.h:43
Class for using UART hardware.
Definition: uarthardware.h:22
Detect up-arrow and down-arrow key strokes via the Printer.
Definition: arrowcontrol.h:23
Wrapper class for shell command. The user has to create object of this class for adding their functio...
Definition: command.h:28
Manages the shell's history.
Definition: history.h:24
Class for string related UART communication. Using this class outside of an esh-context can make sens...
Definition: printer.h:25
Manages esh's command parsing and execution.
Definition: processor.h:26
This class manages a semf's embedded shell (esh) operating on a single UART. The esh can be used for ...
Definition: shell.h:34
void start()
Starts the reading process of the shell. The user should call this function once.
Definition: shell.cpp:39
virtual ~Shell()=default
Shell(const Shell &other)=delete
void addCommand(Command &cmd)
Adds a command to the shell.
Definition: shell.cpp:34
void loop()
Performs the command execution.
Definition: shell.cpp:46
SEMF_SIGNAL(error, Error)
Shell(UartHardware &uart, const Config &config)
Constructor.
Definition: shell.cpp:17
Handles the command auto completion.
Definition: tabulator.h:28
Configuarion parameters of the shell.
Definition: shell.h:40
const size_t numberOfEntries
Definition: shell.h:52
char *const lineBuffer
Definition: shell.h:42
const size_t lineBufferSize
Definition: shell.h:44
std::string_view prompt
Definition: shell.h:56
char **const argvBuffer
Definition: shell.h:46
const size_t argvBufferSize
Definition: shell.h:48