Make luaconsole even easier to use.

This commit is contained in:
2021-11-04 14:49:25 -04:00
parent 0a00ecaaa8
commit 7966707450
4 changed files with 50 additions and 55 deletions

View File

@@ -8,9 +8,9 @@
// 1. Print the prompt suggested by 'get_prompt'.
// 2. Read a line of text from stdin.
// 3. Add the line to the LuaConsole using 'add'.
// 4. Get the command words using 'words'.
// 5. If the words are empty, do nothing.
// 6. If the words contain something, execute and call 'clear'.
// 4. Get the command words using 'get_command'.
// 5. If the command is empty, do nothing.
// 6. If the command is nonempty, execute it and call 'clear'.
//
// The 'words' returned by the luaconsole can be empty, meaning
// that there's no command to execute. If the words are nonempty,
@@ -43,32 +43,31 @@ private:
StringVec words_;
std::string prompt_;
void split_words();
void clear_command();
void clear_raw_input();
public:
LuaConsole();
~LuaConsole();
// Fetch the stored prompt. Also clears the stored prompt. You should fetch
// and print the prompt after 'add' or 'clear'.
std::string get_prompt();
// Get the command words.
// Fetch the recommended prompt.
//
// You should update the prompt immediately after 'add'.
//
const std::string &get_prompt() { return prompt_; }
// Fetch the command to execute.
//
// You should fetch the command after calling 'add'.
// Returns the empty vector if there is no command.
// If there is a command, the first word is the command word.
// See the file comment for certain built-in command words.
//
const StringVec &words() const { return words_; }
StringVec get_command();
// Add a line of text that was just read from the console.
// If more input is needed, stores the ">> " prompt.
//
void add(std::string line);
// Call 'clear' after executing an action.
// Stores the "> " prompt.
void clear();
};
#endif // LUACONSOLE_HPP