My Project
shell_prompt.cpp
1 /*
2  * uuid-console - Microcontroller console shell
3  * Copyright 2019 Simon Arlott
4  *
5  * This program is free software: you can redistribute it and/or modify
6  * it under the terms of the GNU General Public License as published by
7  * the Free Software Foundation, either version 3 of the License, or
8  * (at your option) any later version.
9  *
10  * This program is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13  * GNU General Public License for more details.
14  *
15  * You should have received a copy of the GNU General Public License
16  * along with this program. If not, see <http://www.gnu.org/licenses/>.
17  */
18 
19 #include <uuid/console.h>
20 
21 #include <string>
22 
23 namespace uuid {
24 
25 namespace console {
26 
28 
29 }
30 
31 std::string Shell::hostname_text() {
32  return std::string{};
33 }
34 
35 std::string Shell::context_text() {
36  return std::string{};
37 }
38 
39 std::string Shell::prompt_prefix() {
40  return std::string{};
41 }
42 
43 std::string Shell::prompt_suffix() {
44  return std::string{'$'};
45 }
46 
48  if (idle_timeout_ > 0) {
49  println();
50  stop();
51  }
52 }
53 
55  switch (mode_) {
56  case Mode::DELAY:
57  case Mode::BLOCKING:
58  break;
59 
60  case Mode::PASSWORD:
61  print(reinterpret_cast<Shell::PasswordData*>(mode_data_.get())->password_prompt_);
62  break;
63 
64  case Mode::NORMAL:
65  std::string hostname = hostname_text();
66  std::string context = context_text();
67 
69  if (!hostname.empty()) {
70  print(hostname);
71  print(' ');
72  }
73  if (!context.empty()) {
74  print(context);
75  print(' ');
76  }
78  print(' ');
80  prompt_displayed_ = true;
81  break;
82  }
83 }
84 
85 } // namespace console
86 
87 } // namespace uuid
Data for the Mode::PASSWORD shell mode.
Definition: console.h:1405
const __FlashStringHelper * password_prompt_
Definition: console.h:1421
size_t println(const std::string &data)
Output a string followed by CRLF end of line characters.
Definition: shell_print.cpp:38
virtual void end_of_transmission()
The end of transmission character has been received.
size_t print(const std::string &data)
Output a string.
Definition: shell_print.cpp:30
virtual std::string prompt_prefix()
Get the prefix to be used at the beginning of the command prompt.
unsigned int context() const
Get the context at the top of the stack.
Definition: console.h:979
virtual std::string hostname_text()
Get the hostname to be included in the command prompt.
std::string line_buffer_
Definition: console.h:1625
uint64_t idle_timeout_
Definition: console.h:1633
virtual std::string prompt_suffix()
Get the prefix to be used at the end of the command prompt.
virtual void display_banner()
Output the startup banner.
virtual std::string context_text()
Get the text indicating the current context, to be included in the command prompt.
void display_prompt()
Output a prompt on the shell.
std::unique_ptr< ModeData > mode_data_
Definition: console.h:1629
void stop()
Stop this shell from running.
Definition: shell.cpp:72
Common utilities.