21 #ifndef TERMINAL_HPP_INCLUDED 22 #define TERMINAL_HPP_INCLUDED 26 #include <type_traits> 31 static constexpr
const char *
cmd_notfound =
": command not found (type \"help\" for a list of available commands)";
32 static constexpr
const char *
cmd_list =
"List of commands:";
59 template<
typename Tp,
bool _terminal_echo = true>
65 using char_type =
typename stream_device_type::fifo_type::char_type;
71 static constexpr
bool terminal_echo = _terminal_echo;
72 static constexpr
const char * newline =
"\r\n";
73 static constexpr
const char * prompt =
"# ";
74 static constexpr std::size_t cmd_buf_size = 80;
79 unsigned cmd_index = 0;
83 using resources =
typename stream_device_type::resources;
88 stream_device_type::open();
92 stream_device_type::close();
96 template<
typename cmd_hooks>
99 bool flush_tx =
false;
101 while(stream_device_type::rx_fifo.pop(c)) {
106 tx_stream << newline;
108 cmd_buf[cmd_index] = 0;
111 cmd_hooks::template execute<cmd_hooks>(cmd_buf, tx_stream);
116 else if((c >= 32) && (c <= 126) && (cmd_index < cmd_buf_size))
121 cmd_buf[cmd_index++] = c;
144 template<std::size_t... Args>
146 static constexpr std::size_t value = 0;
149 template<std::size_t T, std::size_t... Args>
150 struct max<T, Args...> {
151 static constexpr std::size_t value = T > max<Args...>::value ? T : max<Args...>::value;
156 template<
typename... Args>
162 template<
typename HL>
164 if(strcmp(
"help", cmd_buf) == 0) {
166 HL::template list<HL>(cout);
173 template<
typename HL>
177 template<
typename T,
typename... Args>
180 template<
typename HL>
182 if(strcmp(T::cmd, cmd_buf) == 0) {
192 static constexpr
unsigned cmd_maxlen = 8;
195 static constexpr
unsigned cmd_maxlen = mpl::max<8, strlen(T::cmd), strlen(Args::cmd)...>::value;
198 template<
typename HL>
200 cout <<
" " << T::cmd;
201 for(
int n = HL::cmd_maxlen - strlen(T::cmd) + 3 ; n > 0; n--)
211 #endif // TERMINAL_HPP_INCLUDED Definition: terminal.hpp:157
void open() const
Definition: terminal.hpp:87
ostream< Tp > & endl(ostream< Tp > &st)
manipulator, outputs newline and flushes the output stream
Definition: poorman_ostream.hpp:75
Definition: poorman_ostream.hpp:29
typename stream_device_type::fifo_type::char_type char_type
Definition: terminal.hpp:65
typename stream_device_type::resources resources
Definition: terminal.hpp:83
static void execute(const char *cmd_buf, poorman::ostream< char > &cout)
Definition: terminal.hpp:181
virtual ostream & put(char_type c)=0
static void execute(const char *cmd_buf, poorman::ostream< char > &cout)
Definition: terminal.hpp:163
Simple vt100-like terminal.
Definition: terminal.hpp:60
poorman::ostream< char_type > & flush()
Definition: fifo_stream.hpp:55
static constexpr const char * cmd_list
Definition: terminal.hpp:32
tx_stream_type tx_stream
Definition: terminal.hpp:69
terminal()
Definition: terminal.hpp:85
Tp stream_device_type
Definition: terminal.hpp:64
poorman::ostream< char_type > & put(char_type c)
Definition: fifo_stream.hpp:40
static void list(poorman::ostream< char > &cout)
Definition: terminal.hpp:199
void process_input(void)
Definition: terminal.hpp:97
static void list(poorman::ostream< char > &)
Definition: terminal.hpp:174
static constexpr const char * cmd_notfound
Definition: terminal.hpp:31
Definition: terminal.hpp:134
void close()
Definition: terminal.hpp:91