| e8555c89 Andy McCall |
1 |
#ifndef IMGUI_CONSOLE_HH |
| 2 |
#define IMGUI_CONSOLE_HH |
| 3 |
|
| 4 |
#include "ImGuiPart.hh" |
| 5 |
#include "ImGuiUtils.hh" |
| 6 |
|
| 7 |
#include "BooleanSetting.hh" |
| 8 |
#include "CompletionCandidate.hh" |
| 9 |
#include "ConsoleLine.hh" |
| 10 |
#include "InterpreterOutput.hh" |
| 11 |
|
| 12 |
#include "Observer.hh" |
| 13 |
#include "circular_buffer.hh" |
| 14 |
#include "function_ref.hh" |
| 15 |
|
| 16 |
#include <string> |
| 17 |
|
| 18 |
struct ImGuiInputTextCallbackData; |
| 19 |
|
| 20 |
namespace openmsx { |
| 21 |
|
| 22 |
class ImGuiConsole final : public ImGuiPart |
| 23 |
, private InterpreterOutput |
| 24 |
, private Observer<Setting> |
| 25 |
{ |
| 26 |
public: |
| 27 |
explicit ImGuiConsole(ImGuiManager& manager); |
| 28 |
~ImGuiConsole(); |
| 29 |
|
| 30 |
[[nodiscard]] zstring_view iniName() const override { return "console"; } |
| 31 |
void save(ImGuiTextBuffer& buf) override; |
| 32 |
void loadLine(std::string_view name, zstring_view value) override; |
| 33 |
void paint(MSXMotherBoard* motherBoard) override; |
| 34 |
|
| 35 |
public: |
| 36 |
bool show = false; |
| 37 |
|
| 38 |
struct CompletionPopupLayout { |
| 39 |
std::vector<float> columnWidths = {}; |
| 40 |
gl::vec2 size = {}; |
| 41 |
bool needXScrollBar = false; |
| 42 |
bool needYScrollBar = false; |
| 43 |
}; |
| 44 |
|
| 45 |
private: |
| 46 |
void print(std::string_view text, imColor color = imColor::TEXT); |
| 47 |
void newLineConsole(ConsoleLine line); |
| 48 |
static int textEditCallbackStub(ImGuiInputTextCallbackData* data); |
| 49 |
int textEditCallback(ImGuiInputTextCallbackData* data); |
| 50 |
void doEdit(ImGuiInputTextCallbackData* data); |
| 51 |
void tabEdit(ImGuiInputTextCallbackData* data, function_ref<std::string(std::string_view)> action); |
| 52 |
void colorize(std::string_view line); |
| 53 |
void putHistory(std::string command); |
| 54 |
void saveHistory(); |
| 55 |
void loadHistory(); |
| 56 |
|
| 57 |
|
| 58 |
void output(std::string_view text) override; |
| 59 |
[[nodiscard]] unsigned getOutputColumns() const override; |
| 60 |
void setCompletions(std::vector<CompletionCandidate> completions) override; |
| 61 |
|
| 62 |
|
| 63 |
void update(const Setting& setting) noexcept override; |
| 64 |
|
| 65 |
private: |
| 66 |
BooleanSetting consoleSetting; |
| 67 |
|
| 68 |
circular_buffer<std::string> history; |
| 69 |
std::string historyBackupLine; |
| 70 |
int historyPos = -1; |
| 71 |
|
| 72 |
circular_buffer<ConsoleLine> lines; |
| 73 |
|
| 74 |
std::string commandBuffer; |
| 75 |
|
| 76 |
std::string prompt; |
| 77 |
std::string inputBuf; |
| 78 |
ConsoleLine coloredInputBuf; |
| 79 |
|
| 80 |
unsigned columns = 80; |
| 81 |
bool scrollToBottom = false; |
| 82 |
bool wasShown = false; |
| 83 |
bool wrap = true; |
| 84 |
|
| 85 |
|
| 86 |
|
| 87 |
std::vector<CompletionCandidate> completions; |
| 88 |
CompletionPopupLayout popupLayout; |
| 89 |
int completionIndex = -1; |
| 90 |
|
| 91 |
std::vector<ImWchar> replayInput; |
| 92 |
CompletionCandidate completionReplacement; |
| 93 |
float textCursorScrnPosX = 0.0f; |
| 94 |
bool replayBackspace = false; |
| 95 |
bool completionPopupOpen = false; |
| 96 |
|
| 97 |
static constexpr auto persistentElements = std::tuple{ |
| 98 |
PersistentElement{"show", &ImGuiConsole::show}, |
| 99 |
PersistentElement{"wrap", &ImGuiConsole::wrap} |
| 100 |
}; |
| 101 |
}; |
| 102 |
|
| 103 |
} |
| 104 |
|
| 105 |
#endif |