openMSX
ImGuiConsole.hh
Go to the documentation of this file.
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 "ConsoleLine.hh"
10
11#include "Observer.hh"
12#include "circular_buffer.hh"
13
14#include <string>
15
16struct ImGuiInputTextCallbackData;
17
18namespace openmsx {
19
20class ImGuiConsole final : public ImGuiPart
21 , private InterpreterOutput
22 , private Observer<Setting>
23{
24public:
27
28 [[nodiscard]] zstring_view iniName() const override { return "console"; }
29 void save(ImGuiTextBuffer& buf) override;
30 void loadLine(std::string_view name, zstring_view value) override;
31 void paint(MSXMotherBoard* motherBoard) override;
32
33public:
34 bool show = false;
35
36private:
37 void print(std::string_view text, imColor color = imColor::TEXT);
38 void newLineConsole(ConsoleLine line);
39 static int textEditCallbackStub(ImGuiInputTextCallbackData* data);
40 int textEditCallback(ImGuiInputTextCallbackData* data);
41 void colorize(std::string_view line);
42 void putHistory(std::string command);
43 void saveHistory();
44 void loadHistory();
45
46 // InterpreterOutput
47 void output(std::string_view text) override;
48 [[nodiscard]] unsigned getOutputColumns() const override;
49
50 // Observer
51 void update(const Setting& setting) noexcept override;
52
53private:
54 BooleanSetting consoleSetting;
55
57 std::string historyBackupLine;
58 int historyPos = -1; // -1: new line, 0..history.size()-1 browsing history.
59
60 circular_buffer<ConsoleLine> lines; // output lines
61
62 std::string commandBuffer; // collect multi-line commands
63
64 std::string prompt;
65 std::string inputBuf;
66 ConsoleLine coloredInputBuf;
67
68 unsigned columns = 80; // gets recalculated
69 bool scrollToBottom = false;
70 bool wasShown = false;
71 bool wrap = true;
72
73 static constexpr auto persistentElements = std::tuple{
75 PersistentElement{"wrap", &ImGuiConsole::wrap}
76 };
77};
78
79} // namespace openmsx
80
81#endif
BaseSetting * setting
Circular buffer class, based on boost::circular_buffer/.
This class represents a single text line in the console.
void paint(MSXMotherBoard *motherBoard) override
void save(ImGuiTextBuffer &buf) override
zstring_view iniName() const override
void loadLine(std::string_view name, zstring_view value) override
ImGuiManager & manager
Definition ImGuiPart.hh:30
Generic Gang-of-Four Observer class, templatized edition.
Definition Observer.hh:10
Like std::string_view, but with the extra guarantee that it refers to a zero-terminated string.
This file implemented 3 utility functions:
Definition Autofire.cc:11