ConsoleUI.cc Source File
Back to the index.
Go to the documentation of this file.
39 , m_consoleIsInitialized(false)
47 if (m_consoleIsInitialized)
48 tcsetattr(STDIN_FILENO, TCSANOW, &m_oldTermios);
54 static struct termios g_curTermios;
56 static void ReshowCurrentCommandBuffer()
71 std::cout <<
"^C (already attempting to interrupt, please wait)\n";
78 ReshowCurrentCommandBuffer();
92 tcsetattr(STDIN_FILENO, TCSANOW, &g_curTermios);
93 ReshowCurrentCommandBuffer();
100 if (m_consoleIsInitialized)
103 tcgetattr(STDIN_FILENO, &m_oldTermios);
104 m_currentTermios = m_oldTermios;
107 m_currentTermios.c_lflag &= ~ICANON;
108 m_currentTermios.c_cc[VTIME] = 0;
109 m_currentTermios.c_cc[VMIN] = 1;
110 m_currentTermios.c_lflag &= ~ECHO;
112 tcsetattr(STDIN_FILENO, TCSANOW, &m_currentTermios);
117 g_curTermios = m_currentTermios;
121 m_consoleIsInitialized =
true;
137 static vector<string> SplitIntoRows(
const string &msg,
bool addEmptyLines)
140 vector<string> result;
143 for (
size_t i=0, n=msg.length(); i<n; i++) {
146 if (line.length() > 0 || addEmptyLines)
147 result.push_back(line);
154 if (line.length() > 0)
155 result.push_back(line);
163 vector<string> lines = SplitIntoRows(msg,
true);
165 for (
size_t i=0; i<lines.size(); ++i) {
167 if (isatty(fileno(stdout)))
193 vector<string> lines = SplitIntoRows(msg,
false);
199 for (i=0; i<componentName.length() + 2; i++)
202 ss << componentName <<
": " << lines[0] <<
"\n";
204 for (i=1; i<lines.size(); ++i)
205 ss << spaces << lines[i] <<
"\n";
227 size_t cursorPosition)
229 std::cout <<
"\rGXemul> " << inputline <<
" \rGXemul> ";
231 for (
size_t pos = 0; pos < cursorPosition; pos++)
232 std::cout << (
string() + inputline[pos]);
245 return std::cin.get();
249 void ConsoleUI::ReadAndExecuteCommand()
309 ReadAndExecuteCommand();
313 oldRunState = runState;
bool PreRunCheck(GXemul *gxemul)
Checks the state of this component and all its children, before starting execution.
virtual void InputLineDone()
Executed by the CommandInterpreter when a line has been completed (with a newline).
virtual void ShowCommandMessage(const string &command)
Does nothing for the ConsoleUI.
bool IsInterrupting() const
Returns whether or not the current emulation is being interrupted.
bool AddKey(stringchar key)
Adds a character (keypress) to the current command buffer.
virtual int MainLoop()
Runs the text console main loop.
CommandInterpreter & GetCommandInterpreter()
Gets a reference to the CommandInterpreter.
virtual void Initialize()
Initializes the terminal for blocking, non-echo I/O.
ConsoleUI(GXemul *gxemul)
Constructs a text console UI instance.
refcount_ptr< Component > GetRootComponent()
Gets a pointer to the root configuration component.
Base class for a User Interface.
void SetRunState(RunState newState)
Sets the RunState.
void ConsoleUI_SIGCONT_Handler(int n)
Restore terminal settings after a CTRL-Z.
virtual void FatalError(const string &msg)
Shows a fatal error message, by printing it to stderr.
void Execute(const int longestTotalRun=100000)
Run the emulation for "a while".
void ConsoleUI_SIGINT_Handler(int n)
CTRL-C handler which sets the run state to Paused.
virtual void ShowStartupBanner()
Prints the text console startup banner.
string GenerateShortestPossiblePath() const
Generates a short string representation of the path to the Component.
RunState GetRunState() const
Gets the current RunState.
A Component is a node in the configuration tree that makes up an emulation setup.
virtual void Shutdown()
Shuts down the UI.
virtual void ShowDebugMessage(const string &msg)
Shows a debug message, by printing it to stdout.
virtual void RedisplayInputLine(const string &inputline, size_t cursorPosition)
Redisplays the interactive command input line.
void ReshowCurrentCommandBuffer()
Re-displays the current command buffer.
virtual void UpdateUI()
Updates UI items. Not used for ConsoleUI.
void FlushCachedState()
Resets the cached state of this component and all its children.
static string Version()
Returns the GXemul version string.
bool GetQuietMode() const
Gets the current quiet mode setting.
void Interrupt()
Interrupts emulation.
void ClearCurrentCommandBuffer()
Clears the current command buffer.
Generated on Tue Aug 25 2020 19:25:06 for GXemul by
1.8.18