ConsoleUI.h Source File

Back to the index.

ConsoleUI.h
Go to the documentation of this file.
1 #ifndef CONSOLEUI_H
2 #define CONSOLEUI_H
3 
4 /*
5  * Copyright (C) 2007-2010 Anders Gavare. All rights reserved.
6  *
7  * Redistribution and use in source and binary forms, with or without
8  * modification, are permitted provided that the following conditions are met:
9  *
10  * 1. Redistributions of source code must retain the above copyright
11  * notice, this list of conditions and the following disclaimer.
12  * 2. Redistributions in binary form must reproduce the above copyright
13  * notice, this list of conditions and the following disclaimer in the
14  * documentation and/or other materials provided with the distribution.
15  * 3. The name of the author may not be used to endorse or promote products
16  * derived from this software without specific prior written permission.
17  *
18  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
19  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
20  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
21  * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
22  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
23  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
24  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
25  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
26  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
27  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
28  * SUCH DAMAGE.
29  */
30 
31 #include <termios.h>
32 
33 #include "UI.h"
34 
35 
36 /**
37  * \brief Text-terminal based User Interface.
38  */
39 class ConsoleUI
40  : public UI
41 {
42 public:
43  /**
44  * \brief Constructs a text console %UI instance.
45  *
46  * @param gxemul Pointer to the owning GXemul instance.
47  */
48  ConsoleUI(GXemul *gxemul);
49 
50  virtual ~ConsoleUI();
51 
52  /**
53  * \brief Initializes the terminal for blocking, non-echo I/O.
54  */
55  virtual void Initialize();
56 
57  /**
58  * \brief Updates UI items. Not used for %ConsoleUI.
59  */
60  virtual void UpdateUI();
61 
62  /**
63  * \brief Prints the text console startup banner.
64  */
65  virtual void ShowStartupBanner();
66 
67  /**
68  * \brief Shows a debug message, by printing it to stdout.
69  *
70  * @param msg The message to show.
71  */
72  virtual void ShowDebugMessage(const string& msg);
73 
74  /**
75  * \brief Shows a debug message for a Component, by printing it to
76  * stdout.
77  *
78  * See UI::ShowDebugMessage(Component*,const string&) for
79  * a longer comment.
80  *
81  * @param component A pointer to the Component.
82  * @param msg The message to show.
83  */
84  virtual void ShowDebugMessage(Component* component, const string& msg);
85 
86  /**
87  * \brief Does nothing for the %ConsoleUI.
88  *
89  * @param command The command being executed.
90  */
91  virtual void ShowCommandMessage(const string& command);
92 
93  /**
94  * \brief Shows a fatal error message, by printing it to stderr.
95  *
96  * @param msg The error message to show.
97  */
98  virtual void FatalError(const string& msg);
99 
100  /**
101  * \brief Redisplays the interactive command input line.
102  *
103  * For the %ConsoleUI, this function displays a prompt ("GXemul> ")
104  * followed by the input line, placing the cursor position at
105  * the correct position on the input line.
106  *
107  * @param inputline The entire input line.
108  * @param cursorPosition The current cursor position. 0 is at the
109  * leftmost position.
110  */
111  virtual void RedisplayInputLine(const string& inputline,
112  size_t cursorPosition);
113 
114  /**
115  * \brief Executed by the CommandInterpreter when a line has been
116  * completed (with a newline).
117  *
118  * For the %ConsoleUI, this simply outputs a newline character.
119  */
120  virtual void InputLineDone();
121 
122  /**
123  * \brief Runs the text console main loop.
124  *
125  * As long as the RunState is not Quitting:
126  * <ul>
127  * <li>If an emulation is Running, the main loop lets the
128  * emulation run, until Ctrl-C is pressed.
129  * <li>Otherwise, if the RunState is Paused, the main loop shows
130  * a prompt and lets the user input commands.
131  * </ul>
132  */
133  virtual int MainLoop();
134 
135  virtual void Shutdown();
136 
137 private:
138  /**
139  * \brief Shows the %GXemul&gt; prompt, reads characters from stdin
140  * until a newline char, and executes the resulting command.
141  *
142  * This function is blocking.
143  */
144  void ReadAndExecuteCommand();
145 
146 private:
147  bool m_consoleIsInitialized;
148  struct termios m_oldTermios;
149  struct termios m_currentTermios;
150 };
151 
152 
153 #endif // CONSOLEUI_H
ConsoleUI::InputLineDone
virtual void InputLineDone()
Executed by the CommandInterpreter when a line has been completed (with a newline).
Definition: ConsoleUI.cc:255
ConsoleUI::ShowCommandMessage
virtual void ShowCommandMessage(const string &command)
Does nothing for the ConsoleUI.
Definition: ConsoleUI.cc:207
GXemul
The main emulator class.
Definition: GXemul.h:54
ConsoleUI::MainLoop
virtual int MainLoop()
Runs the text console main loop.
Definition: ConsoleUI.cc:267
ConsoleUI::Initialize
virtual void Initialize()
Initializes the terminal for blocking, non-echo I/O.
Definition: ConsoleUI.cc:98
ConsoleUI::ConsoleUI
ConsoleUI(GXemul *gxemul)
Constructs a text console UI instance.
Definition: ConsoleUI.cc:37
UI.h
UI
Base class for a User Interface.
Definition: UI.h:40
ConsoleUI::FatalError
virtual void FatalError(const string &msg)
Shows a fatal error message, by printing it to stderr.
Definition: ConsoleUI.cc:215
ConsoleUI
Text-terminal based User Interface.
Definition: ConsoleUI.h:39
ConsoleUI::~ConsoleUI
virtual ~ConsoleUI()
Definition: ConsoleUI.cc:44
ConsoleUI::ShowStartupBanner
virtual void ShowStartupBanner()
Prints the text console startup banner.
Definition: ConsoleUI.cc:131
Component
A Component is a node in the configuration tree that makes up an emulation setup.
Definition: Component.h:62
ConsoleUI::Shutdown
virtual void Shutdown()
Shuts down the UI.
Definition: ConsoleUI.cc:262
ConsoleUI::ShowDebugMessage
virtual void ShowDebugMessage(const string &msg)
Shows a debug message, by printing it to stdout.
Definition: ConsoleUI.cc:161
ConsoleUI::RedisplayInputLine
virtual void RedisplayInputLine(const string &inputline, size_t cursorPosition)
Redisplays the interactive command input line.
Definition: ConsoleUI.cc:222
ConsoleUI::UpdateUI
virtual void UpdateUI()
Updates UI items. Not used for ConsoleUI.
Definition: ConsoleUI.cc:125

Generated on Tue Mar 24 2020 14:04:48 for GXemul by doxygen 1.8.17