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
uuid::console::Shell::end_of_transmission
virtual void end_of_transmission()
The end of transmission character has been received.
Definition: shell_prompt.cpp:47
uuid::console::Shell::display_prompt
void display_prompt()
Output a prompt on the shell.
Definition: shell_prompt.cpp:54
uuid::console::Shell::display_banner
virtual void display_banner()
Output the startup banner.
Definition: shell_prompt.cpp:27
uuid::console::Shell::idle_timeout_
uint64_t idle_timeout_
Definition: console.h:1633
uuid::console::Shell::print
size_t print(const std::string &data)
Output a string.
Definition: shell_print.cpp:30
uuid::console::Shell::Mode::PASSWORD
@ PASSWORD
uuid::console::Shell::prompt_prefix
virtual std::string prompt_prefix()
Get the prefix to be used at the beginning of the command prompt.
Definition: shell_prompt.cpp:39
uuid::console::Shell::stop
void stop()
Stop this shell from running.
Definition: shell.cpp:72
uuid::console::Shell::context
unsigned int context() const
Get the context at the top of the stack.
Definition: console.h:979
uuid::console::Shell::PasswordData
Data for the Mode::PASSWORD shell mode.
Definition: console.h:1405
uuid::console::Shell::println
size_t println(const std::string &data)
Output a string followed by CRLF end of line characters.
Definition: shell_print.cpp:38
uuid::console::Shell::line_buffer_
std::string line_buffer_
Definition: console.h:1625
uuid::console::Shell::Mode::BLOCKING
@ BLOCKING
uuid::console::Shell::mode_data_
std::unique_ptr< ModeData > mode_data_
Definition: console.h:1629
uuid::console::Shell::Mode::DELAY
@ DELAY
uuid
Common utilities.
Definition: get_uptime_ms.cpp:28
uuid::console::Shell::PasswordData::password_prompt_
const __FlashStringHelper * password_prompt_
Definition: console.h:1421
uuid::console::Shell::hostname_text
virtual std::string hostname_text()
Get the hostname to be included in the command prompt.
Definition: shell_prompt.cpp:31
uuid::console::Shell::prompt_displayed_
bool prompt_displayed_
Definition: console.h:1631
uuid::console::Shell::prompt_suffix
virtual std::string prompt_suffix()
Get the prefix to be used at the end of the command prompt.
Definition: shell_prompt.cpp:43
uuid::console::Shell::mode_
Mode mode_
Definition: console.h:1628
uuid::console::Shell::context_text
virtual std::string context_text()
Get the text indicating the current context, to be included in the command prompt.
Definition: shell_prompt.cpp:35
uuid::console::Shell::Mode::NORMAL
@ NORMAL