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) {
189 vector<string> lines = SplitIntoRows(msg,
false);
195 for (i=0; i<componentName.length() + 2; i++)
198 ss << componentName <<
": " << lines[0] <<
"\n";
200 for (i=1; i<lines.size(); ++i)
201 ss << spaces << lines[i] <<
"\n";
223 size_t cursorPosition)
225 std::cout <<
"\rGXemul> " << inputline <<
" \rGXemul> ";
227 for (
size_t pos = 0; pos < cursorPosition; pos++)
228 std::cout << (
string() + inputline[pos]);
241 return std::cin.get();
245 void ConsoleUI::ReadAndExecuteCommand()
305 ReadAndExecuteCommand();
309 oldRunState = runState;
void SetRunState(RunState newState)
Sets the RunState.
void ClearCurrentCommandBuffer()
Clears the current command buffer.
RunState GetRunState() const
Gets the current RunState.
virtual void ShowDebugMessage(const string &msg)
Shows a debug message, by printing it to stdout.
bool GetQuietMode() const
Gets the current quiet mode setting.
void Interrupt()
Interrupts emulation.
virtual void ShowStartupBanner()
Prints the text console startup banner.
string GenerateShortestPossiblePath() const
Generates a short string representation of the path to the Component.
virtual void InputLineDone()
Executed by the CommandInterpreter when a line has been completed (with a newline).
void ConsoleUI_SIGINT_Handler(int n)
CTRL-C handler which sets the run state to Paused.
static string Version()
Returns the GXemul version string.
CommandInterpreter & GetCommandInterpreter()
Gets a reference to the CommandInterpreter.
virtual void Shutdown()
Shuts down the UI.
virtual void Initialize()
Initializes the terminal for blocking, non-echo I/O.
virtual void ShowCommandMessage(const string &command)
Does nothing for the ConsoleUI.
A Component is a node in the configuration tree that makes up an emulation setup. ...
bool PreRunCheck(GXemul *gxemul)
Checks the state of this component and all its children, before starting execution.
void ConsoleUI_SIGCONT_Handler(int n)
Restore terminal settings after a CTRL-Z.
void FlushCachedState()
Resets the cached state of this component and all its children.
bool AddKey(stringchar key)
Adds a character (keypress) to the current command buffer.
bool IsInterrupting() const
Returns whether or not the current emulation is being interrupted.
void ReshowCurrentCommandBuffer()
Re-displays the current command buffer.
virtual void UpdateUI()
Updates UI items. Not used for ConsoleUI.
ConsoleUI(GXemul *gxemul)
Constructs a text console UI instance.
virtual void RedisplayInputLine(const string &inputline, size_t cursorPosition)
Redisplays the interactive command input line.
virtual void FatalError(const string &msg)
Shows a fatal error message, by printing it to stderr.
refcount_ptr< Component > GetRootComponent()
Gets a pointer to the root configuration component.
Base class for a User Interface.
void Execute(const int longestTotalRun=100000)
Run the emulation for "a while".
virtual int MainLoop()
Runs the text console main loop.