Reformat code.
This commit is contained in:
@@ -760,4 +760,4 @@ const UndoSystem *
|
|||||||
Buffer::Undo() const
|
Buffer::Undo() const
|
||||||
{
|
{
|
||||||
return undo_sys_.get();
|
return undo_sys_.get();
|
||||||
}
|
}
|
||||||
|
|||||||
2
Buffer.h
2
Buffer.h
@@ -591,4 +591,4 @@ private:
|
|||||||
kte::SwapRecorder *swap_rec_ = nullptr;
|
kte::SwapRecorder *swap_rec_ = nullptr;
|
||||||
|
|
||||||
mutable std::mutex buffer_mutex_;
|
mutable std::mutex buffer_mutex_;
|
||||||
};
|
};
|
||||||
|
|||||||
43
Command.cc
43
Command.cc
@@ -1109,33 +1109,34 @@ cmd_theme_set_by_name(const CommandContext &ctx)
|
|||||||
static bool
|
static bool
|
||||||
cmd_theme_set_by_name(CommandContext &ctx)
|
cmd_theme_set_by_name(CommandContext &ctx)
|
||||||
{
|
{
|
||||||
|
|
||||||
# if defined(KTE_BUILD_GUI) && defined(KTE_USE_QT)
|
# if defined(KTE_BUILD_GUI) && defined(KTE_USE_QT)
|
||||||
// Qt GUI build: schedule theme change for frontend
|
// Qt GUI build: schedule theme change for frontend
|
||||||
std::string name = ctx.arg;
|
std::string name = ctx.arg;
|
||||||
// trim spaces
|
// trim spaces
|
||||||
auto ltrim = [](std::string &s) {
|
auto ltrim = [](std::string &s) {
|
||||||
s.erase(s.begin(), std::find_if(s.begin(), s.end(), [](unsigned char ch) {
|
s.erase(s.begin(), std::find_if(s.begin(), s.end(), [](unsigned char ch) {
|
||||||
return !std::isspace(ch);
|
return !std::isspace(ch);
|
||||||
}));
|
}));
|
||||||
};
|
};
|
||||||
auto rtrim = [](std::string &s) {
|
auto rtrim = [](std::string &s) {
|
||||||
s.erase(std::find_if(s.rbegin(), s.rend(), [](unsigned char ch) {
|
s.erase(std::find_if(s.rbegin(), s.rend(), [](unsigned char ch) {
|
||||||
return !std::isspace(ch);
|
return !std::isspace(ch);
|
||||||
}).base(), s.end());
|
}).base(), s.end());
|
||||||
};
|
};
|
||||||
ltrim(name);
|
ltrim (name);
|
||||||
rtrim(name);
|
rtrim (name);
|
||||||
if (name.empty()) {
|
if (name.empty()) {
|
||||||
ctx.editor.SetStatus("theme: provide a name (e.g., nord, solarized-dark, gruvbox-light, eink)");
|
ctx.editor.SetStatus("theme: provide a name (e.g., nord, solarized-dark, gruvbox-light, eink)");
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
kte::gThemeChangeRequest = name;
|
kte::gThemeChangeRequest= name;
|
||||||
kte::gThemeChangePending = true;
|
kte::gThemeChangePending=true;
|
||||||
ctx.editor.SetStatus(std::string("Theme requested: ") + name);
|
ctx.editor.SetStatus (std::string("Theme requested: ") + name);
|
||||||
return true;
|
return true;
|
||||||
# else
|
# else
|
||||||
(void) ctx;
|
(void) ctx;
|
||||||
// No-op in terminal build
|
// No-op in terminal build
|
||||||
return true;
|
return true;
|
||||||
# endif
|
# endif
|
||||||
}
|
}
|
||||||
@@ -4990,4 +4991,4 @@ Execute(Editor &ed, const std::string &name, const std::string &arg, int count)
|
|||||||
return false;
|
return false;
|
||||||
CommandContext ctx{ed, arg, count};
|
CommandContext ctx{ed, arg, count};
|
||||||
return cmd->handler ? cmd->handler(ctx) : false;
|
return cmd->handler ? cmd->handler(ctx) : false;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -164,4 +164,4 @@ void InstallDefaultCommands();
|
|||||||
// Returns true if the command executed successfully.
|
// Returns true if the command executed successfully.
|
||||||
bool Execute(Editor &ed, CommandId id, const std::string &arg = std::string(), int count = 0);
|
bool Execute(Editor &ed, CommandId id, const std::string &arg = std::string(), int count = 0);
|
||||||
|
|
||||||
bool Execute(Editor &ed, const std::string &name, const std::string &arg = std::string(), int count = 0);
|
bool Execute(Editor &ed, const std::string &name, const std::string &arg = std::string(), int count = 0);
|
||||||
|
|||||||
@@ -577,4 +577,4 @@ Editor::UArgGet()
|
|||||||
int n = (ucount_ > 0) ? ucount_ : 1;
|
int n = (ucount_ > 0) ? ucount_ : 1;
|
||||||
UArgClear();
|
UArgClear();
|
||||||
return n;
|
return n;
|
||||||
}
|
}
|
||||||
|
|||||||
2
Editor.h
2
Editor.h
@@ -662,4 +662,4 @@ public:
|
|||||||
private:
|
private:
|
||||||
std::string replace_find_tmp_;
|
std::string replace_find_tmp_;
|
||||||
std::string replace_with_tmp_;
|
std::string replace_with_tmp_;
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -19,4 +19,4 @@ public:
|
|||||||
|
|
||||||
// Shutdown/cleanup
|
// Shutdown/cleanup
|
||||||
virtual void Shutdown() = 0;
|
virtual void Shutdown() = 0;
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -127,4 +127,4 @@ GUIConfig::LoadFromFile(const std::string &path)
|
|||||||
}
|
}
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -30,4 +30,4 @@ public:
|
|||||||
|
|
||||||
// Load from explicit path. Returns true if file existed and was parsed.
|
// Load from explicit path. Returns true if file existed and was parsed.
|
||||||
bool LoadFromFile(const std::string &path);
|
bool LoadFromFile(const std::string &path);
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -942,4 +942,4 @@ SyntaxInk(const TokenKind k)
|
|||||||
}
|
}
|
||||||
} // namespace kte
|
} // namespace kte
|
||||||
|
|
||||||
#endif // KTE_USE_QT
|
#endif // KTE_USE_QT
|
||||||
|
|||||||
@@ -79,4 +79,4 @@ HelpText::Text()
|
|||||||
" : theme NAME Set GUI theme (amber, eink, everforest, gruvbox, kanagawa-paper, lcars, nord, old-book, plan9, solarized, weyland-yutani, zenburn)\n"
|
" : theme NAME Set GUI theme (amber, eink, everforest, gruvbox, kanagawa-paper, lcars, nord, old-book, plan9, solarized, weyland-yutani, zenburn)\n"
|
||||||
" : background MODE Set background: light | dark (affects eink, gruvbox, old-book, solarized)\n"
|
" : background MODE Set background: light | dark (affects eink, gruvbox, old-book, solarized)\n"
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -10,4 +10,4 @@ public:
|
|||||||
// Project maintainers can customize the returned string below
|
// Project maintainers can customize the returned string below
|
||||||
// (in HelpText.cc) without touching the help command logic.
|
// (in HelpText.cc) without touching the help command logic.
|
||||||
static std::string Text();
|
static std::string Text();
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -34,4 +34,4 @@ struct LineHighlight {
|
|||||||
std::vector<HighlightSpan> spans;
|
std::vector<HighlightSpan> spans;
|
||||||
std::uint64_t version{0}; // buffer version used for this line
|
std::uint64_t version{0}; // buffer version used for this line
|
||||||
};
|
};
|
||||||
} // namespace kte
|
} // namespace kte
|
||||||
|
|||||||
@@ -391,4 +391,4 @@ GUIFrontend::LoadGuiFont_(const char * /*path*/, const float size_px)
|
|||||||
|
|
||||||
io.Fonts->Build();
|
io.Fonts->Build();
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -33,4 +33,4 @@ private:
|
|||||||
SDL_GLContext gl_ctx_ = nullptr;
|
SDL_GLContext gl_ctx_ = nullptr;
|
||||||
int width_ = 1280;
|
int width_ = 1280;
|
||||||
int height_ = 800;
|
int height_ = 800;
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -158,17 +158,17 @@ map_key(const SDL_Keycode key,
|
|||||||
ascii_key = static_cast<int>(key);
|
ascii_key = static_cast<int>(key);
|
||||||
}
|
}
|
||||||
bool ctrl2 = (mod & KMOD_CTRL) != 0;
|
bool ctrl2 = (mod & KMOD_CTRL) != 0;
|
||||||
// If user typed a literal 'C' (uppercase) or '^' as a control qualifier, keep k-prefix active
|
// If user typed a literal 'C' (uppercase) or '^' as a control qualifier, keep k-prefix active
|
||||||
// Do NOT treat lowercase 'c' as a qualifier; 'c' is a valid k-command (BufferClose).
|
// Do NOT treat lowercase 'c' as a qualifier; 'c' is a valid k-command (BufferClose).
|
||||||
if (ascii_key == 'C' || ascii_key == '^') {
|
if (ascii_key == 'C' || ascii_key == '^') {
|
||||||
k_ctrl_pending = true;
|
k_ctrl_pending = true;
|
||||||
// Keep waiting for the next suffix; show status and suppress ensuing TEXTINPUT
|
// Keep waiting for the next suffix; show status and suppress ensuing TEXTINPUT
|
||||||
if (ed)
|
if (ed)
|
||||||
ed->SetStatus("C-k C _");
|
ed->SetStatus("C-k C _");
|
||||||
suppress_textinput_once = true;
|
suppress_textinput_once = true;
|
||||||
out.hasCommand = false;
|
out.hasCommand = false;
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
// Otherwise, consume the k-prefix now for the actual suffix
|
// Otherwise, consume the k-prefix now for the actual suffix
|
||||||
k_prefix = false;
|
k_prefix = false;
|
||||||
if (ascii_key != 0) {
|
if (ascii_key != 0) {
|
||||||
@@ -298,7 +298,7 @@ ImGuiInputHandler::ProcessSDLEvent(const SDL_Event &e)
|
|||||||
// High-resolution trackpads can deliver fractional wheel deltas. Accumulate
|
// High-resolution trackpads can deliver fractional wheel deltas. Accumulate
|
||||||
// precise values and emit one scroll step per whole unit.
|
// precise values and emit one scroll step per whole unit.
|
||||||
float dy = 0.0f;
|
float dy = 0.0f;
|
||||||
#if SDL_VERSION_ATLEAST(2,0,18)
|
#if SDL_VERSION_ATLEAST(2, 0, 18)
|
||||||
dy = e.wheel.preciseY;
|
dy = e.wheel.preciseY;
|
||||||
#else
|
#else
|
||||||
dy = static_cast<float>(e.wheel.y);
|
dy = static_cast<float>(e.wheel.y);
|
||||||
@@ -308,7 +308,7 @@ ImGuiInputHandler::ProcessSDLEvent(const SDL_Event &e)
|
|||||||
dy = -dy;
|
dy = -dy;
|
||||||
#endif
|
#endif
|
||||||
if (dy != 0.0f) {
|
if (dy != 0.0f) {
|
||||||
wheel_accum_y_ += dy;
|
wheel_accum_y_ += dy;
|
||||||
float abs_accum = wheel_accum_y_ >= 0.0f ? wheel_accum_y_ : -wheel_accum_y_;
|
float abs_accum = wheel_accum_y_ >= 0.0f ? wheel_accum_y_ : -wheel_accum_y_;
|
||||||
int steps = static_cast<int>(abs_accum);
|
int steps = static_cast<int>(abs_accum);
|
||||||
if (steps > 0) {
|
if (steps > 0) {
|
||||||
@@ -439,14 +439,12 @@ ImGuiInputHandler::ProcessSDLEvent(const SDL_Event &e)
|
|||||||
}
|
}
|
||||||
|
|
||||||
// If editor universal argument is active, consume digit TEXTINPUT
|
// If editor universal argument is active, consume digit TEXTINPUT
|
||||||
if (ed_ &&ed_
|
if (ed_ && ed_
|
||||||
|
|
||||||
|
|
||||||
|
->
|
||||||
->
|
UArg() != 0
|
||||||
UArg() != 0
|
) {
|
||||||
)
|
|
||||||
{
|
|
||||||
const char *txt = e.text.text;
|
const char *txt = e.text.text;
|
||||||
if (txt && *txt) {
|
if (txt && *txt) {
|
||||||
unsigned char c0 = static_cast<unsigned char>(txt[0]);
|
unsigned char c0 = static_cast<unsigned char>(txt[0]);
|
||||||
@@ -473,16 +471,16 @@ ImGuiInputHandler::ProcessSDLEvent(const SDL_Event &e)
|
|||||||
ascii_key = static_cast<int>(c0);
|
ascii_key = static_cast<int>(c0);
|
||||||
}
|
}
|
||||||
if (ascii_key != 0) {
|
if (ascii_key != 0) {
|
||||||
// Qualifier via TEXTINPUT: uppercase 'C' or '^' only
|
// Qualifier via TEXTINPUT: uppercase 'C' or '^' only
|
||||||
if (ascii_key == 'C' || ascii_key == '^') {
|
if (ascii_key == 'C' || ascii_key == '^') {
|
||||||
k_ctrl_pending_ = true;
|
k_ctrl_pending_ = true;
|
||||||
if (ed_)
|
if (ed_)
|
||||||
ed_->SetStatus("C-k C _");
|
ed_->SetStatus("C-k C _");
|
||||||
// Keep k-prefix active; do not emit a command
|
// Keep k-prefix active; do not emit a command
|
||||||
k_prefix_ = true;
|
k_prefix_ = true;
|
||||||
produced = true;
|
produced = true;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
// Map via k-prefix table; do not pass Ctrl for TEXTINPUT case
|
// Map via k-prefix table; do not pass Ctrl for TEXTINPUT case
|
||||||
CommandId id;
|
CommandId id;
|
||||||
bool pass_ctrl = k_ctrl_pending_;
|
bool pass_ctrl = k_ctrl_pending_;
|
||||||
@@ -608,4 +606,4 @@ ImGuiInputHandler::Poll(MappedInput &out)
|
|||||||
out = q_.front();
|
out = q_.front();
|
||||||
q_.pop();
|
q_.pop();
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -46,4 +46,4 @@ private:
|
|||||||
// command per whole step and keep the fractional remainder.
|
// command per whole step and keep the fractional remainder.
|
||||||
float wheel_accum_y_ = 0.0f;
|
float wheel_accum_y_ = 0.0f;
|
||||||
float wheel_accum_x_ = 0.0f; // reserved for future horizontal scrolling
|
float wheel_accum_x_ = 0.0f; // reserved for future horizontal scrolling
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -927,4 +927,4 @@ ImGuiRenderer::Draw(Editor &ed)
|
|||||||
ed.SetFilePickerVisible(false);
|
ed.SetFilePickerVisible(false);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -11,4 +11,4 @@ public:
|
|||||||
~ImGuiRenderer() override = default;
|
~ImGuiRenderer() override = default;
|
||||||
|
|
||||||
void Draw(Editor &ed) override;
|
void Draw(Editor &ed) override;
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -28,4 +28,4 @@ public:
|
|||||||
// Poll for input and translate it to a command. Non-blocking.
|
// Poll for input and translate it to a command. Non-blocking.
|
||||||
// Returns true if a command is available in 'out'. Returns false if no input.
|
// Returns true if a command is available in 'out'. Returns false if no input.
|
||||||
virtual bool Poll(MappedInput &out) = 0;
|
virtual bool Poll(MappedInput &out) = 0;
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -230,4 +230,4 @@ KLookupEscCommand(const int ascii_key, CommandId &out) -> bool
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -27,4 +27,4 @@ KLowerAscii(const int key)
|
|||||||
if (key >= 'A' && key <= 'Z')
|
if (key >= 'A' && key <= 'Z')
|
||||||
return key + ('a' - 'A');
|
return key + ('a' - 'A');
|
||||||
return key;
|
return key;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -20,4 +20,4 @@ private:
|
|||||||
std::string last_pat_;
|
std::string last_pat_;
|
||||||
|
|
||||||
void build_bad_char(const std::string &pattern);
|
void build_bad_char(const std::string &pattern);
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -982,4 +982,4 @@ GUIFrontend::Shutdown()
|
|||||||
delete app_;
|
delete app_;
|
||||||
app_ = nullptr;
|
app_ = nullptr;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -33,4 +33,4 @@ private:
|
|||||||
QWidget *window_ = nullptr; // owned
|
QWidget *window_ = nullptr; // owned
|
||||||
int width_ = 1280;
|
int width_ = 1280;
|
||||||
int height_ = 800;
|
int height_ = 800;
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -283,12 +283,11 @@ QtInputHandler::ProcessKeyEvent(const QKeyEvent &e)
|
|||||||
const bool ctrl_like = (mods & Qt::ControlModifier);
|
const bool ctrl_like = (mods & Qt::ControlModifier);
|
||||||
|
|
||||||
// 1) Universal argument digits (when active), consume digits without enqueuing commands
|
// 1) Universal argument digits (when active), consume digits without enqueuing commands
|
||||||
if (ed_ &&ed_
|
if (ed_ && ed_
|
||||||
|
|
||||||
->
|
->
|
||||||
UArg() != 0
|
UArg() != 0
|
||||||
)
|
) {
|
||||||
{
|
|
||||||
if (!(mods & (Qt::ControlModifier | Qt::AltModifier | Qt::MetaModifier))) {
|
if (!(mods & (Qt::ControlModifier | Qt::AltModifier | Qt::MetaModifier))) {
|
||||||
if (e.key() >= Qt::Key_0 && e.key() <= Qt::Key_9) {
|
if (e.key() >= Qt::Key_0 && e.key() <= Qt::Key_9) {
|
||||||
int d = e.key() - Qt::Key_0;
|
int d = e.key() - Qt::Key_0;
|
||||||
@@ -379,10 +378,9 @@ QtInputHandler::ProcessKeyEvent(const QKeyEvent &e)
|
|||||||
// ESC/meta chords: on macOS, do NOT treat Meta as ESC; only Alt (Option) should trigger.
|
// ESC/meta chords: on macOS, do NOT treat Meta as ESC; only Alt (Option) should trigger.
|
||||||
#if defined(__APPLE__)
|
#if defined(__APPLE__)
|
||||||
if (esc_meta_ || (mods & Qt::AltModifier)) {
|
if (esc_meta_ || (mods & Qt::AltModifier)) {
|
||||||
|
|
||||||
|
|
||||||
#else
|
#else
|
||||||
if (esc_meta_ || (mods & (Qt::AltModifier | Qt::MetaModifier))) {
|
if (esc_meta_ || (mods & (Qt::AltModifier | Qt::MetaModifier))) {
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
int ascii_key = 0;
|
int ascii_key = 0;
|
||||||
if (e.key() == Qt::Key_Backspace) {
|
if (e.key() == Qt::Key_Backspace) {
|
||||||
@@ -535,4 +533,4 @@ QtInputHandler::Poll(MappedInput &out)
|
|||||||
out = q_.front();
|
out = q_.front();
|
||||||
q_.pop();
|
q_.pop();
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -37,4 +37,4 @@ private:
|
|||||||
bool esc_meta_ = false; // ESC-prefix for next key
|
bool esc_meta_ = false; // ESC-prefix for next key
|
||||||
bool suppress_text_input_once_ = false; // reserved (Qt sends text in keyPressEvent)
|
bool suppress_text_input_once_ = false; // reserved (Qt sends text in keyPressEvent)
|
||||||
Editor *ed_ = nullptr;
|
Editor *ed_ = nullptr;
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -73,4 +73,4 @@ QtRenderer::Draw(Editor &ed)
|
|||||||
}
|
}
|
||||||
// Request a repaint
|
// Request a repaint
|
||||||
widget_->update();
|
widget_->update();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -24,4 +24,4 @@ public:
|
|||||||
|
|
||||||
private:
|
private:
|
||||||
QWidget *widget_ = nullptr; // not owned
|
QWidget *widget_ = nullptr; // not owned
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -10,4 +10,4 @@ public:
|
|||||||
virtual ~Renderer() = default;
|
virtual ~Renderer() = default;
|
||||||
|
|
||||||
virtual void Draw(Editor &ed) = 0;
|
virtual void Draw(Editor &ed) = 0;
|
||||||
};
|
};
|
||||||
|
|||||||
2
Swap.cc
2
Swap.cc
@@ -1292,4 +1292,4 @@ SwapManager::ReplayFile(Buffer &buf, const std::string &swap_path, std::string &
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} // namespace kte
|
} // namespace kte
|
||||||
|
|||||||
2
Swap.h
2
Swap.h
@@ -223,4 +223,4 @@ private:
|
|||||||
std::atomic<bool> running_{false};
|
std::atomic<bool> running_{false};
|
||||||
std::thread worker_;
|
std::thread worker_;
|
||||||
};
|
};
|
||||||
} // namespace kte
|
} // namespace kte
|
||||||
|
|||||||
@@ -16,4 +16,4 @@ public:
|
|||||||
|
|
||||||
virtual void OnDelete(int row, int col, std::size_t len) = 0;
|
virtual void OnDelete(int row, int col, std::size_t len) = 0;
|
||||||
};
|
};
|
||||||
} // namespace kte
|
} // namespace kte
|
||||||
|
|||||||
@@ -126,4 +126,4 @@ TerminalFrontend::Shutdown()
|
|||||||
have_old_sigint_ = false;
|
have_old_sigint_ = false;
|
||||||
}
|
}
|
||||||
endwin();
|
endwin();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -38,4 +38,4 @@ private:
|
|||||||
// Saved SIGINT handler to restore on shutdown
|
// Saved SIGINT handler to restore on shutdown
|
||||||
bool have_old_sigint_ = false;
|
bool have_old_sigint_ = false;
|
||||||
struct sigaction old_sigint_{};
|
struct sigaction old_sigint_{};
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -329,4 +329,4 @@ TerminalInputHandler::Poll(MappedInput &out)
|
|||||||
{
|
{
|
||||||
out = {};
|
out = {};
|
||||||
return decode_(out) && out.hasCommand;
|
return decode_(out) && out.hasCommand;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -34,4 +34,4 @@ private:
|
|||||||
bool mouse_selecting_ = false;
|
bool mouse_selecting_ = false;
|
||||||
|
|
||||||
Editor *ed_ = nullptr; // attached editor for uarg handling
|
Editor *ed_ = nullptr; // attached editor for uarg handling
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -615,4 +615,4 @@ TerminalRenderer::Draw(Editor &ed)
|
|||||||
}
|
}
|
||||||
|
|
||||||
refresh();
|
refresh();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -12,4 +12,4 @@ public:
|
|||||||
~TerminalRenderer() override;
|
~TerminalRenderer() override;
|
||||||
|
|
||||||
void Draw(Editor &ed) override;
|
void Draw(Editor &ed) override;
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -35,4 +35,4 @@ TestFrontend::Step(Editor &ed, bool &running)
|
|||||||
|
|
||||||
|
|
||||||
void
|
void
|
||||||
TestFrontend::Shutdown() {}
|
TestFrontend::Shutdown() {}
|
||||||
|
|||||||
@@ -34,4 +34,4 @@ public:
|
|||||||
private:
|
private:
|
||||||
TestInputHandler input_{};
|
TestInputHandler input_{};
|
||||||
TestRenderer renderer_{};
|
TestRenderer renderer_{};
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -27,4 +27,4 @@ public:
|
|||||||
|
|
||||||
private:
|
private:
|
||||||
std::queue<MappedInput> queue_;
|
std::queue<MappedInput> queue_;
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -29,4 +29,4 @@ public:
|
|||||||
|
|
||||||
private:
|
private:
|
||||||
std::size_t draw_count_ = 0;
|
std::size_t draw_count_ = 0;
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -20,4 +20,4 @@ struct UndoNode {
|
|||||||
UndoNode *parent = nullptr; // previous state; null means pre-first-edit
|
UndoNode *parent = nullptr; // previous state; null means pre-first-edit
|
||||||
UndoNode *child = nullptr; // next in current timeline
|
UndoNode *child = nullptr; // next in current timeline
|
||||||
UndoNode *next = nullptr; // redo branch
|
UndoNode *next = nullptr; // redo branch
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -60,4 +60,4 @@ private:
|
|||||||
std::size_t block_size_;
|
std::size_t block_size_;
|
||||||
std::vector<std::unique_ptr<UndoNode[]> > blocks_;
|
std::vector<std::unique_ptr<UndoNode[]> > blocks_;
|
||||||
std::stack<UndoNode *> available_;
|
std::stack<UndoNode *> available_;
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -452,4 +452,4 @@ UndoSystem::debug_log(const char *op) const
|
|||||||
#else
|
#else
|
||||||
(void) op;
|
(void) op;
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -77,4 +77,4 @@ private:
|
|||||||
|
|
||||||
Buffer *buf_;
|
Buffer *buf_;
|
||||||
UndoTree &tree_;
|
UndoTree &tree_;
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -7,4 +7,4 @@ struct UndoTree {
|
|||||||
UndoNode *current = nullptr; // current state of buffer
|
UndoNode *current = nullptr; // current state of buffer
|
||||||
UndoNode *saved = nullptr; // points to node matching last save (for dirty flag)
|
UndoNode *saved = nullptr; // points to node matching last save (for dirty flag)
|
||||||
UndoNode *pending = nullptr; // in-progress batch (detached)
|
UndoNode *pending = nullptr; // in-progress batch (detached)
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -11884,4 +11884,4 @@ static const unsigned int DefaultFontRegularCompressedData[72616 / 4] =
|
|||||||
0x0070a96e,
|
0x0070a96e,
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -5586,4 +5586,4 @@ static const unsigned int DefaultFontBoldCompressedData[32380 / 4] =
|
|||||||
0x0e01060e, 0xff01b82a, 0x8d04b085,
|
0x0e01060e, 0xff01b82a, 0x8d04b085,
|
||||||
0x440002b1, 0x066405b3, 0x00444400, 0x01000000, 0x00000000, 0xfacafa05, 0x00004aa6,
|
0x440002b1, 0x066405b3, 0x00444400, 0x01000000, 0x00000000, 0xfacafa05, 0x00004aa6,
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -5918,4 +5918,4 @@ static const unsigned int DefaultFontRegularCompressedData[34064 / 4] =
|
|||||||
0x20080082, 0x01060eb3, 0x01b82a0e,
|
0x20080082, 0x01060eb3, 0x01b82a0e,
|
||||||
0x04b085ff, 0x0002b18d, 0x6405b344, 0x44440006, 0x00000000, 0x00000001, 0xccfa0500, 0x0030ee4f,
|
0x04b085ff, 0x0002b18d, 0x6405b344, 0x44440006, 0x00000000, 0x00000001, 0xccfa0500, 0x0030ee4f,
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -2851,4 +2851,4 @@ static const unsigned int DefaultFontRegularCompressedData[68288 / 4] =
|
|||||||
0x820a2003, 0x421e20c3, 0x18821057,
|
0x820a2003, 0x421e20c3, 0x18821057,
|
||||||
0x21830284, 0xdeda0024, 0x0d83c5d7, 0xa48ad12b, 0x0000001e, 0xa48ad100, 0x62fa051e, 0x00a176d4,
|
0x21830284, 0xdeda0024, 0x0d83c5d7, 0xa48ad12b, 0x0000001e, 0xa48ad100, 0x62fa051e, 0x00a176d4,
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -37,4 +37,4 @@ Font::Load(const float size) const
|
|||||||
|
|
||||||
io.Fonts->Build();
|
io.Fonts->Build();
|
||||||
}
|
}
|
||||||
} // namespace kte::Fonts
|
} // namespace kte::Fonts
|
||||||
|
|||||||
@@ -119,4 +119,4 @@ private:
|
|||||||
|
|
||||||
|
|
||||||
void InstallDefaultFonts();
|
void InstallDefaultFonts();
|
||||||
}
|
}
|
||||||
|
|||||||
25743
fonts/Go.h
25743
fonts/Go.h
File diff suppressed because it is too large
Load Diff
@@ -13671,4 +13671,4 @@ static const unsigned int DefaultFontItalicCompressedData[84884 / 4] =
|
|||||||
0x4f1aea4f, 0x0d2022dc, 0x211fdc4f,
|
0x4f1aea4f, 0x0d2022dc, 0x211fdc4f,
|
||||||
0x164f2804, 0x8b952711, 0x236f6f19, 0xfa050081, 0x0bda00e5,
|
0x164f2804, 0x8b952711, 0x236f6f19, 0xfa050081, 0x0bda00e5,
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -6231,4 +6231,4 @@ static const unsigned int DefaultFontRegularCompressedData[149388 / 4] =
|
|||||||
0x86382043, 0x870f8383, 0x022e2463,
|
0x86382043, 0x870f8383, 0x022e2463,
|
||||||
0x05480066, 0x599623fa, 0x00000043,
|
0x05480066, 0x599623fa, 0x00000043,
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -5632,4 +5632,4 @@ static const unsigned int DefaultFontRegularCompressedData[66932 / 4] =
|
|||||||
0xc6221786, 0x1788a203, 0x86008524,
|
0xc6221786, 0x1788a203, 0x86008524,
|
||||||
0x2f88e200, 0x1788a520, 0xf6ffb424, 0xfa05fa00, 0xc234b8e9,
|
0x2f88e200, 0x1788a520, 0xf6ffb424, 0xfa05fa00, 0xc234b8e9,
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -5737,4 +5737,4 @@ static const unsigned int DefaultFontBoldCompressedData[68920 / 4] =
|
|||||||
0x86910006, 0x03c32217, 0x241788b7, 0x00ce0085, 0x202f88e4, 0x261788b5, 0x00ebffb4, 0x050000fe, 0x877646fa,
|
0x86910006, 0x03c32217, 0x241788b7, 0x00ce0085, 0x202f88e4, 0x261788b5, 0x00ebffb4, 0x050000fe, 0x877646fa,
|
||||||
0x000000de,
|
0x000000de,
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|||||||
22065
fonts/Triplicate.h
22065
fonts/Triplicate.h
File diff suppressed because it is too large
Load Diff
9
main.cc
9
main.cc
@@ -195,12 +195,11 @@ main(int argc, char *argv[])
|
|||||||
} else if (req_term) {
|
} else if (req_term) {
|
||||||
use_gui = false;
|
use_gui = false;
|
||||||
} else {
|
} else {
|
||||||
|
// Default depends on build target: kge defaults to GUI, kte to terminal
|
||||||
// Default depends on build target: kge defaults to GUI, kte to terminal
|
|
||||||
#if defined(KTE_DEFAULT_GUI)
|
#if defined(KTE_DEFAULT_GUI)
|
||||||
use_gui = true;
|
use_gui = true;
|
||||||
#else
|
#else
|
||||||
use_gui = false;
|
use_gui = false;
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
@@ -302,4 +301,4 @@ main(int argc, char *argv[])
|
|||||||
fe->Shutdown();
|
fe->Shutdown();
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -143,7 +143,7 @@ CppHighlighter::HighlightLineStateful(const Buffer &buf,
|
|||||||
bool closed = false;
|
bool closed = false;
|
||||||
while (j + 1 <= n) {
|
while (j + 1 <= n) {
|
||||||
if (j + 1 < n && s[j] == '*' && s[j + 1] == '/') {
|
if (j + 1 < n && s[j] == '*' && s[j + 1] == '/') {
|
||||||
j += 2;
|
j += 2;
|
||||||
closed = true;
|
closed = true;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
@@ -276,4 +276,4 @@ CppHighlighter::HighlightLineStateful(const Buffer &buf,
|
|||||||
|
|
||||||
return state;
|
return state;
|
||||||
}
|
}
|
||||||
} // namespace kte
|
} // namespace kte
|
||||||
|
|||||||
@@ -32,4 +32,4 @@ private:
|
|||||||
|
|
||||||
static bool is_ident_char(char c);
|
static bool is_ident_char(char c);
|
||||||
};
|
};
|
||||||
} // namespace kte
|
} // namespace kte
|
||||||
|
|||||||
@@ -156,4 +156,4 @@ ErlangHighlighter::HighlightLine(const Buffer &buf, int row, std::vector<Highlig
|
|||||||
++i;
|
++i;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} // namespace kte
|
} // namespace kte
|
||||||
|
|||||||
@@ -14,4 +14,4 @@ public:
|
|||||||
private:
|
private:
|
||||||
std::unordered_set<std::string> kws_;
|
std::unordered_set<std::string> kws_;
|
||||||
};
|
};
|
||||||
} // namespace kte
|
} // namespace kte
|
||||||
|
|||||||
@@ -118,4 +118,4 @@ ForthHighlighter::HighlightLine(const Buffer &buf, int row, std::vector<Highligh
|
|||||||
++i;
|
++i;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} // namespace kte
|
} // namespace kte
|
||||||
|
|||||||
@@ -14,4 +14,4 @@ public:
|
|||||||
private:
|
private:
|
||||||
std::unordered_set<std::string> kws_;
|
std::unordered_set<std::string> kws_;
|
||||||
};
|
};
|
||||||
} // namespace kte
|
} // namespace kte
|
||||||
|
|||||||
@@ -75,7 +75,7 @@ GoHighlighter::HighlightLine(const Buffer &buf, int row, std::vector<HighlightSp
|
|||||||
bool closed = false;
|
bool closed = false;
|
||||||
while (j + 1 <= n) {
|
while (j + 1 <= n) {
|
||||||
if (j + 1 < n && s[j] == '*' && s[j + 1] == '/') {
|
if (j + 1 < n && s[j] == '*' && s[j + 1] == '/') {
|
||||||
j += 2;
|
j += 2;
|
||||||
closed = true;
|
closed = true;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
@@ -154,4 +154,4 @@ GoHighlighter::HighlightLine(const Buffer &buf, int row, std::vector<HighlightSp
|
|||||||
++i;
|
++i;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} // namespace kte
|
} // namespace kte
|
||||||
|
|||||||
@@ -15,4 +15,4 @@ private:
|
|||||||
std::unordered_set<std::string> kws_;
|
std::unordered_set<std::string> kws_;
|
||||||
std::unordered_set<std::string> types_;
|
std::unordered_set<std::string> types_;
|
||||||
};
|
};
|
||||||
} // namespace kte
|
} // namespace kte
|
||||||
|
|||||||
@@ -221,4 +221,4 @@ HighlighterEngine::PrefetchViewport(const Buffer &buf, int first_row, int row_co
|
|||||||
ensure_worker_started();
|
ensure_worker_started();
|
||||||
cv_.notify_one();
|
cv_.notify_one();
|
||||||
}
|
}
|
||||||
} // namespace kte
|
} // namespace kte
|
||||||
|
|||||||
@@ -87,4 +87,4 @@ private:
|
|||||||
|
|
||||||
void worker_loop() const;
|
void worker_loop() const;
|
||||||
};
|
};
|
||||||
} // namespace kte
|
} // namespace kte
|
||||||
|
|||||||
@@ -244,4 +244,4 @@ HighlighterRegistry::RegisterTreeSitter(std::string_view filetype,
|
|||||||
}, /*override_existing=*/true);
|
}, /*override_existing=*/true);
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
} // namespace kte
|
} // namespace kte
|
||||||
|
|||||||
@@ -44,4 +44,4 @@ public:
|
|||||||
const TSLanguage * (*get_language)());
|
const TSLanguage * (*get_language)());
|
||||||
#endif
|
#endif
|
||||||
};
|
};
|
||||||
} // namespace kte
|
} // namespace kte
|
||||||
|
|||||||
@@ -87,4 +87,4 @@ JSONHighlighter::HighlightLine(const Buffer &buf, int row, std::vector<Highlight
|
|||||||
++i;
|
++i;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} // namespace kte
|
} // namespace kte
|
||||||
|
|||||||
@@ -9,4 +9,4 @@ class JSONHighlighter final : public LanguageHighlighter {
|
|||||||
public:
|
public:
|
||||||
void HighlightLine(const Buffer &buf, int row, std::vector<HighlightSpan> &out) const override;
|
void HighlightLine(const Buffer &buf, int row, std::vector<HighlightSpan> &out) const override;
|
||||||
};
|
};
|
||||||
} // namespace kte
|
} // namespace kte
|
||||||
|
|||||||
@@ -48,4 +48,4 @@ public:
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
} // namespace kte
|
} // namespace kte
|
||||||
|
|||||||
@@ -104,4 +104,4 @@ LispHighlighter::HighlightLine(const Buffer &buf, int row, std::vector<Highlight
|
|||||||
++i;
|
++i;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} // namespace kte
|
} // namespace kte
|
||||||
|
|||||||
@@ -14,4 +14,4 @@ public:
|
|||||||
private:
|
private:
|
||||||
std::unordered_set<std::string> kws_;
|
std::unordered_set<std::string> kws_;
|
||||||
};
|
};
|
||||||
} // namespace kte
|
} // namespace kte
|
||||||
|
|||||||
@@ -129,4 +129,4 @@ MarkdownHighlighter::HighlightLineStateful(const Buffer &buf, int row, const Lin
|
|||||||
}
|
}
|
||||||
return state;
|
return state;
|
||||||
}
|
}
|
||||||
} // namespace kte
|
} // namespace kte
|
||||||
|
|||||||
@@ -11,4 +11,4 @@ public:
|
|||||||
LineState HighlightLineStateful(const Buffer &buf, int row, const LineState &prev,
|
LineState HighlightLineStateful(const Buffer &buf, int row, const LineState &prev,
|
||||||
std::vector<HighlightSpan> &out) const override;
|
std::vector<HighlightSpan> &out) const override;
|
||||||
};
|
};
|
||||||
} // namespace kte
|
} // namespace kte
|
||||||
|
|||||||
@@ -14,4 +14,4 @@ NullHighlighter::HighlightLine(const Buffer &buf, int row, std::vector<Highlight
|
|||||||
return;
|
return;
|
||||||
out.push_back({0, n, TokenKind::Default});
|
out.push_back({0, n, TokenKind::Default});
|
||||||
}
|
}
|
||||||
} // namespace kte
|
} // namespace kte
|
||||||
|
|||||||
@@ -8,4 +8,4 @@ class NullHighlighter final : public LanguageHighlighter {
|
|||||||
public:
|
public:
|
||||||
void HighlightLine(const Buffer &buf, int row, std::vector<HighlightSpan> &out) const override;
|
void HighlightLine(const Buffer &buf, int row, std::vector<HighlightSpan> &out) const override;
|
||||||
};
|
};
|
||||||
} // namespace kte
|
} // namespace kte
|
||||||
|
|||||||
@@ -169,4 +169,4 @@ PythonHighlighter::HighlightLineStateful(const Buffer &buf, int row, const LineS
|
|||||||
}
|
}
|
||||||
return state;
|
return state;
|
||||||
}
|
}
|
||||||
} // namespace kte
|
} // namespace kte
|
||||||
|
|||||||
@@ -17,4 +17,4 @@ public:
|
|||||||
private:
|
private:
|
||||||
std::unordered_set<std::string> kws_;
|
std::unordered_set<std::string> kws_;
|
||||||
};
|
};
|
||||||
} // namespace kte
|
} // namespace kte
|
||||||
|
|||||||
@@ -72,7 +72,7 @@ RustHighlighter::HighlightLine(const Buffer &buf, int row, std::vector<Highlight
|
|||||||
bool closed = false;
|
bool closed = false;
|
||||||
while (j + 1 <= n) {
|
while (j + 1 <= n) {
|
||||||
if (j + 1 < n && s[j] == '*' && s[j + 1] == '/') {
|
if (j + 1 < n && s[j] == '*' && s[j + 1] == '/') {
|
||||||
j += 2;
|
j += 2;
|
||||||
closed = true;
|
closed = true;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
@@ -142,4 +142,4 @@ RustHighlighter::HighlightLine(const Buffer &buf, int row, std::vector<Highlight
|
|||||||
++i;
|
++i;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} // namespace kte
|
} // namespace kte
|
||||||
|
|||||||
@@ -15,4 +15,4 @@ private:
|
|||||||
std::unordered_set<std::string> kws_;
|
std::unordered_set<std::string> kws_;
|
||||||
std::unordered_set<std::string> types_;
|
std::unordered_set<std::string> types_;
|
||||||
};
|
};
|
||||||
} // namespace kte
|
} // namespace kte
|
||||||
|
|||||||
@@ -102,4 +102,4 @@ ShellHighlighter::HighlightLine(const Buffer &buf, int row, std::vector<Highligh
|
|||||||
++i;
|
++i;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} // namespace kte
|
} // namespace kte
|
||||||
|
|||||||
@@ -8,4 +8,4 @@ class ShellHighlighter final : public LanguageHighlighter {
|
|||||||
public:
|
public:
|
||||||
void HighlightLine(const Buffer &buf, int row, std::vector<HighlightSpan> &out) const override;
|
void HighlightLine(const Buffer &buf, int row, std::vector<HighlightSpan> &out) const override;
|
||||||
};
|
};
|
||||||
} // namespace kte
|
} // namespace kte
|
||||||
|
|||||||
@@ -75,7 +75,7 @@ SqlHighlighter::HighlightLine(const Buffer &buf, int row, std::vector<HighlightS
|
|||||||
bool closed = false;
|
bool closed = false;
|
||||||
while (j + 1 <= n) {
|
while (j + 1 <= n) {
|
||||||
if (j + 1 < n && s[j] == '*' && s[j + 1] == '/') {
|
if (j + 1 < n && s[j] == '*' && s[j + 1] == '/') {
|
||||||
j += 2;
|
j += 2;
|
||||||
closed = true;
|
closed = true;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
@@ -153,4 +153,4 @@ SqlHighlighter::HighlightLine(const Buffer &buf, int row, std::vector<HighlightS
|
|||||||
++i;
|
++i;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} // namespace kte
|
} // namespace kte
|
||||||
|
|||||||
@@ -15,4 +15,4 @@ private:
|
|||||||
std::unordered_set<std::string> kws_;
|
std::unordered_set<std::string> kws_;
|
||||||
std::unordered_set<std::string> types_;
|
std::unordered_set<std::string> types_;
|
||||||
};
|
};
|
||||||
} // namespace kte
|
} // namespace kte
|
||||||
|
|||||||
@@ -44,8 +44,8 @@ CreateTreeSitterHighlighter(const char *filetype,
|
|||||||
const void * (*get_lang)())
|
const void * (*get_lang)())
|
||||||
{
|
{
|
||||||
const auto *lang = reinterpret_cast<const TSLanguage *>(get_lang ? get_lang() : nullptr);
|
const auto *lang = reinterpret_cast<const TSLanguage *>(get_lang ? get_lang() : nullptr);
|
||||||
return std::make_unique < TreeSitterHighlighter > (lang, filetype ? std::string(filetype) : std::string());
|
return std::make_unique<TreeSitterHighlighter>(lang, filetype ? std::string(filetype) : std::string());
|
||||||
}
|
}
|
||||||
} // namespace kte
|
} // namespace kte
|
||||||
|
|
||||||
#endif // KTE_ENABLE_TREESITTER
|
#endif // KTE_ENABLE_TREESITTER
|
||||||
|
|||||||
@@ -45,4 +45,4 @@ std::unique_ptr<LanguageHighlighter> CreateTreeSitterHighlighter(const char *fil
|
|||||||
const void * (*get_lang)());
|
const void * (*get_lang)());
|
||||||
} // namespace kte
|
} // namespace kte
|
||||||
|
|
||||||
#endif // KTE_ENABLE_TREESITTER
|
#endif // KTE_ENABLE_TREESITTER
|
||||||
|
|||||||
62
tests/Test.h
62
tests/Test.h
@@ -8,49 +8,61 @@
|
|||||||
#include <sstream>
|
#include <sstream>
|
||||||
|
|
||||||
namespace ktet {
|
namespace ktet {
|
||||||
|
|
||||||
struct TestCase {
|
struct TestCase {
|
||||||
std::string name;
|
std::string name;
|
||||||
std::function<void()> fn;
|
std::function<void()> fn;
|
||||||
};
|
};
|
||||||
|
|
||||||
inline std::vector<TestCase>& registry() {
|
|
||||||
static std::vector<TestCase> r;
|
inline std::vector<TestCase> &
|
||||||
return r;
|
registry()
|
||||||
|
{
|
||||||
|
static std::vector<TestCase> r;
|
||||||
|
return r;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
struct Registrar {
|
struct Registrar {
|
||||||
Registrar(const char* name, std::function<void()> fn) {
|
Registrar(const char *name, std::function<void()> fn)
|
||||||
registry().push_back(TestCase{std::string(name), std::move(fn)});
|
{
|
||||||
}
|
registry().push_back(TestCase{std::string(name), std::move(fn)});
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
// Assertions
|
// Assertions
|
||||||
struct AssertionFailure {
|
struct AssertionFailure {
|
||||||
std::string msg;
|
std::string msg;
|
||||||
};
|
};
|
||||||
|
|
||||||
inline void expect(bool cond, const char* expr, const char* file, int line) {
|
|
||||||
if (!cond) {
|
inline void
|
||||||
std::cerr << file << ":" << line << ": EXPECT failed: " << expr << "\n";
|
expect(bool cond, const char *expr, const char *file, int line)
|
||||||
}
|
{
|
||||||
|
if (!cond) {
|
||||||
|
std::cerr << file << ":" << line << ": EXPECT failed: " << expr << "\n";
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
inline void assert_true(bool cond, const char* expr, const char* file, int line) {
|
|
||||||
if (!cond) {
|
inline void
|
||||||
throw AssertionFailure{std::string(file) + ":" + std::to_string(line) + ": ASSERT failed: " + expr};
|
assert_true(bool cond, const char *expr, const char *file, int line)
|
||||||
}
|
{
|
||||||
|
if (!cond) {
|
||||||
|
throw AssertionFailure{std::string(file) + ":" + std::to_string(line) + ": ASSERT failed: " + expr};
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
template<typename A, typename B>
|
template<typename A, typename B>
|
||||||
inline void assert_eq_impl(const A& a, const B& b, const char* ea, const char* eb, const char* file, int line) {
|
inline void
|
||||||
if (!(a == b)) {
|
assert_eq_impl(const A &a, const B &b, const char *ea, const char *eb, const char *file, int line)
|
||||||
std::ostringstream oss;
|
{
|
||||||
oss << file << ":" << line << ": ASSERT_EQ failed: " << ea << " == " << eb;
|
if (!(a == b)) {
|
||||||
throw AssertionFailure{oss.str()};
|
std::ostringstream oss;
|
||||||
}
|
oss << file << ":" << line << ": ASSERT_EQ failed: " << ea << " == " << eb;
|
||||||
|
throw AssertionFailure{oss.str()};
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
} // namespace ktet
|
} // namespace ktet
|
||||||
|
|
||||||
#define TEST(name) \
|
#define TEST(name) \
|
||||||
|
|||||||
@@ -135,4 +135,4 @@ public:
|
|||||||
private:
|
private:
|
||||||
Editor editor_;
|
Editor editor_;
|
||||||
};
|
};
|
||||||
} // namespace ktet
|
} // namespace ktet
|
||||||
|
|||||||
@@ -2,32 +2,35 @@
|
|||||||
#include <iostream>
|
#include <iostream>
|
||||||
#include <chrono>
|
#include <chrono>
|
||||||
|
|
||||||
int main() {
|
|
||||||
using namespace std::chrono;
|
int
|
||||||
auto ® = ktet::registry();
|
main()
|
||||||
std::cout << "kte unit tests: " << reg.size() << " test(s)\n";
|
{
|
||||||
int failed = 0;
|
using namespace std::chrono;
|
||||||
auto t0 = steady_clock::now();
|
auto ® = ktet::registry();
|
||||||
for (const auto &tc : reg) {
|
std::cout << "kte unit tests: " << reg.size() << " test(s)\n";
|
||||||
auto ts = steady_clock::now();
|
int failed = 0;
|
||||||
try {
|
auto t0 = steady_clock::now();
|
||||||
tc.fn();
|
for (const auto &tc: reg) {
|
||||||
auto te = steady_clock::now();
|
auto ts = steady_clock::now();
|
||||||
auto ms = duration_cast<milliseconds>(te - ts).count();
|
try {
|
||||||
std::cout << "[ OK ] " << tc.name << " (" << ms << " ms)\n";
|
tc.fn();
|
||||||
} catch (const ktet::AssertionFailure &e) {
|
auto te = steady_clock::now();
|
||||||
++failed;
|
auto ms = duration_cast<milliseconds>(te - ts).count();
|
||||||
std::cerr << "[FAIL] " << tc.name << " -> " << e.msg << "\n";
|
std::cout << "[ OK ] " << tc.name << " (" << ms << " ms)\n";
|
||||||
} catch (const std::exception &e) {
|
} catch (const ktet::AssertionFailure &e) {
|
||||||
++failed;
|
++failed;
|
||||||
std::cerr << "[EXCP] " << tc.name << " -> " << e.what() << "\n";
|
std::cerr << "[FAIL] " << tc.name << " -> " << e.msg << "\n";
|
||||||
} catch (...) {
|
} catch (const std::exception &e) {
|
||||||
++failed;
|
++failed;
|
||||||
std::cerr << "[EXCP] " << tc.name << " -> unknown exception\n";
|
std::cerr << "[EXCP] " << tc.name << " -> " << e.what() << "\n";
|
||||||
}
|
} catch (...) {
|
||||||
}
|
++failed;
|
||||||
auto t1 = steady_clock::now();
|
std::cerr << "[EXCP] " << tc.name << " -> unknown exception\n";
|
||||||
auto total_ms = duration_cast<milliseconds>(t1 - t0).count();
|
}
|
||||||
std::cout << "Done in " << total_ms << " ms. Failures: " << failed << "\n";
|
}
|
||||||
return failed == 0 ? 0 : 1;
|
auto t1 = steady_clock::now();
|
||||||
|
auto total_ms = duration_cast<milliseconds>(t1 - t0).count();
|
||||||
|
std::cout << "Done in " << total_ms << " ms. Failures: " << failed << "\n";
|
||||||
|
return failed == 0 ? 0 : 1;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -4,76 +4,85 @@
|
|||||||
#include <string>
|
#include <string>
|
||||||
#include "Buffer.h"
|
#include "Buffer.h"
|
||||||
|
|
||||||
static std::string read_all(const std::string &path) {
|
|
||||||
std::ifstream in(path, std::ios::binary);
|
static std::string
|
||||||
return std::string((std::istreambuf_iterator<char>(in)), std::istreambuf_iterator<char>());
|
read_all(const std::string &path)
|
||||||
|
{
|
||||||
|
std::ifstream in(path, std::ios::binary);
|
||||||
|
return std::string((std::istreambuf_iterator<char>(in)), std::istreambuf_iterator<char>());
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST(Buffer_SaveAs_and_Save_new_file) {
|
|
||||||
const std::string path = "./.kte_ut_buffer_io_1.tmp";
|
|
||||||
std::remove(path.c_str());
|
|
||||||
|
|
||||||
Buffer b;
|
TEST(Buffer_SaveAs_and_Save_new_file)
|
||||||
// insert two lines
|
{
|
||||||
b.insert_text(0, 0, std::string("Hello, world!\n"));
|
const std::string path = "./.kte_ut_buffer_io_1.tmp";
|
||||||
b.insert_text(1, 0, std::string("Second line\n"));
|
std::remove(path.c_str());
|
||||||
|
|
||||||
std::string err;
|
Buffer b;
|
||||||
ASSERT_TRUE(b.SaveAs(path, err));
|
// insert two lines
|
||||||
ASSERT_EQ(err.empty(), true);
|
b.insert_text(0, 0, std::string("Hello, world!\n"));
|
||||||
|
b.insert_text(1, 0, std::string("Second line\n"));
|
||||||
|
|
||||||
// append another line then Save()
|
std::string err;
|
||||||
b.insert_text(2, 0, std::string("Third\n"));
|
ASSERT_TRUE(b.SaveAs(path, err));
|
||||||
b.SetDirty(true);
|
ASSERT_EQ(err.empty(), true);
|
||||||
ASSERT_TRUE(b.Save(err));
|
|
||||||
ASSERT_EQ(err.empty(), true);
|
|
||||||
|
|
||||||
std::string got = read_all(path);
|
// append another line then Save()
|
||||||
ASSERT_EQ(got, std::string("Hello, world!\nSecond line\nThird\n"));
|
b.insert_text(2, 0, std::string("Third\n"));
|
||||||
|
b.SetDirty(true);
|
||||||
|
ASSERT_TRUE(b.Save(err));
|
||||||
|
ASSERT_EQ(err.empty(), true);
|
||||||
|
|
||||||
std::remove(path.c_str());
|
std::string got = read_all(path);
|
||||||
|
ASSERT_EQ(got, std::string("Hello, world!\nSecond line\nThird\n"));
|
||||||
|
|
||||||
|
std::remove(path.c_str());
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST(Buffer_Save_after_Open_existing) {
|
|
||||||
const std::string path = "./.kte_ut_buffer_io_2.tmp";
|
|
||||||
std::remove(path.c_str());
|
|
||||||
{
|
|
||||||
std::ofstream out(path, std::ios::binary);
|
|
||||||
out << "abc\n123\n";
|
|
||||||
}
|
|
||||||
|
|
||||||
Buffer b;
|
TEST(Buffer_Save_after_Open_existing)
|
||||||
std::string err;
|
{
|
||||||
ASSERT_TRUE(b.OpenFromFile(path, err));
|
const std::string path = "./.kte_ut_buffer_io_2.tmp";
|
||||||
ASSERT_EQ(err.empty(), true);
|
std::remove(path.c_str());
|
||||||
|
{
|
||||||
|
std::ofstream out(path, std::ios::binary);
|
||||||
|
out << "abc\n123\n";
|
||||||
|
}
|
||||||
|
|
||||||
b.insert_text(2, 0, std::string("tail\n"));
|
Buffer b;
|
||||||
b.SetDirty(true);
|
std::string err;
|
||||||
ASSERT_TRUE(b.Save(err));
|
ASSERT_TRUE(b.OpenFromFile(path, err));
|
||||||
ASSERT_EQ(err.empty(), true);
|
ASSERT_EQ(err.empty(), true);
|
||||||
|
|
||||||
std::string got = read_all(path);
|
b.insert_text(2, 0, std::string("tail\n"));
|
||||||
ASSERT_EQ(got, std::string("abc\n123\ntail\n"));
|
b.SetDirty(true);
|
||||||
std::remove(path.c_str());
|
ASSERT_TRUE(b.Save(err));
|
||||||
|
ASSERT_EQ(err.empty(), true);
|
||||||
|
|
||||||
|
std::string got = read_all(path);
|
||||||
|
ASSERT_EQ(got, std::string("abc\n123\ntail\n"));
|
||||||
|
std::remove(path.c_str());
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST(Buffer_Open_nonexistent_then_SaveAs) {
|
|
||||||
const std::string path = "./.kte_ut_buffer_io_3.tmp";
|
|
||||||
std::remove(path.c_str());
|
|
||||||
|
|
||||||
Buffer b;
|
TEST(Buffer_Open_nonexistent_then_SaveAs)
|
||||||
std::string err;
|
{
|
||||||
ASSERT_TRUE(b.OpenFromFile(path, err));
|
const std::string path = "./.kte_ut_buffer_io_3.tmp";
|
||||||
ASSERT_EQ(err.empty(), true);
|
std::remove(path.c_str());
|
||||||
ASSERT_EQ(b.IsFileBacked(), false);
|
|
||||||
|
|
||||||
b.insert_text(0, 0, std::string("hello, world"));
|
Buffer b;
|
||||||
b.insert_text(0, 12, std::string("\n"));
|
std::string err;
|
||||||
b.SetDirty(true);
|
ASSERT_TRUE(b.OpenFromFile(path, err));
|
||||||
ASSERT_TRUE(b.SaveAs(path, err));
|
ASSERT_EQ(err.empty(), true);
|
||||||
ASSERT_EQ(err.empty(), true);
|
ASSERT_EQ(b.IsFileBacked(), false);
|
||||||
|
|
||||||
std::string got = read_all(path);
|
b.insert_text(0, 0, std::string("hello, world"));
|
||||||
ASSERT_EQ(got, std::string("hello, world\n"));
|
b.insert_text(0, 12, std::string("\n"));
|
||||||
std::remove(path.c_str());
|
b.SetDirty(true);
|
||||||
|
ASSERT_TRUE(b.SaveAs(path, err));
|
||||||
|
ASSERT_EQ(err.empty(), true);
|
||||||
|
|
||||||
|
std::string got = read_all(path);
|
||||||
|
ASSERT_EQ(got, std::string("hello, world\n"));
|
||||||
|
std::remove(path.c_str());
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -82,7 +82,7 @@ check_buffer_matches_model(const Buffer &b, const std::string &model)
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
TEST (Buffer_RowsCache_MultiLineEdits_StayConsistent)
|
TEST(Buffer_RowsCache_MultiLineEdits_StayConsistent)
|
||||||
{
|
{
|
||||||
Buffer b;
|
Buffer b;
|
||||||
std::string model;
|
std::string model;
|
||||||
@@ -139,4 +139,4 @@ TEST (Buffer_RowsCache_MultiLineEdits_StayConsistent)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
check_buffer_matches_model(b, model);
|
check_buffer_matches_model(b, model);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -5,7 +5,7 @@
|
|||||||
using ktet::TestHarness;
|
using ktet::TestHarness;
|
||||||
|
|
||||||
|
|
||||||
TEST (CommandSemantics_KillToEOL_KillChain_And_Yank)
|
TEST(CommandSemantics_KillToEOL_KillChain_And_Yank)
|
||||||
{
|
{
|
||||||
TestHarness h;
|
TestHarness h;
|
||||||
Editor &ed = h.EditorRef();
|
Editor &ed = h.EditorRef();
|
||||||
@@ -34,7 +34,7 @@ TEST (CommandSemantics_KillToEOL_KillChain_And_Yank)
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
TEST (CommandSemantics_ToggleMark_JumpToMark)
|
TEST(CommandSemantics_ToggleMark_JumpToMark)
|
||||||
{
|
{
|
||||||
TestHarness h;
|
TestHarness h;
|
||||||
Buffer &b = h.Buf();
|
Buffer &b = h.Buf();
|
||||||
@@ -59,7 +59,7 @@ TEST (CommandSemantics_ToggleMark_JumpToMark)
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
TEST (CommandSemantics_CtrlGRefresh_ClearsMark_WhenNothingElseToCancel)
|
TEST(CommandSemantics_CtrlGRefresh_ClearsMark_WhenNothingElseToCancel)
|
||||||
{
|
{
|
||||||
TestHarness h;
|
TestHarness h;
|
||||||
Buffer &b = h.Buf();
|
Buffer &b = h.Buf();
|
||||||
@@ -78,7 +78,7 @@ TEST (CommandSemantics_CtrlGRefresh_ClearsMark_WhenNothingElseToCancel)
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
TEST (CommandSemantics_CopyRegion_And_KillRegion)
|
TEST(CommandSemantics_CopyRegion_And_KillRegion)
|
||||||
{
|
{
|
||||||
TestHarness h;
|
TestHarness h;
|
||||||
Editor &ed = h.EditorRef();
|
Editor &ed = h.EditorRef();
|
||||||
@@ -107,4 +107,4 @@ TEST (CommandSemantics_CopyRegion_And_KillRegion)
|
|||||||
ASSERT_EQ(ed.KillRingHead(), std::string("world"));
|
ASSERT_EQ(ed.KillRingHead(), std::string("world"));
|
||||||
ASSERT_EQ(b.MarkSet(), false);
|
ASSERT_EQ(b.MarkSet(), false);
|
||||||
ASSERT_EQ(h.Text(), std::string("hello "));
|
ASSERT_EQ(h.Text(), std::string("hello "));
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -3,10 +3,10 @@
|
|||||||
#include "tests/TestHarness.h"
|
#include "tests/TestHarness.h"
|
||||||
|
|
||||||
|
|
||||||
TEST (DailyDriverHarness_Smoke_CanCreateBufferAndInsertText)
|
TEST(DailyDriverHarness_Smoke_CanCreateBufferAndInsertText)
|
||||||
{
|
{
|
||||||
ktet::TestHarness h;
|
ktet::TestHarness h;
|
||||||
|
|
||||||
ASSERT_TRUE(h.InsertText("hello"));
|
ASSERT_TRUE(h.InsertText("hello"));
|
||||||
ASSERT_EQ(h.Line(0), std::string("hello"));
|
ASSERT_EQ(h.Line(0), std::string("hello"));
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -40,7 +40,7 @@ buffer_bytes_via_views(const Buffer &b)
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
TEST (DailyWorkflow_OpenEditSave_Transcript)
|
TEST(DailyWorkflow_OpenEditSave_Transcript)
|
||||||
{
|
{
|
||||||
ktet::InstallDefaultCommandsOnce();
|
ktet::InstallDefaultCommandsOnce();
|
||||||
|
|
||||||
@@ -77,7 +77,7 @@ TEST (DailyWorkflow_OpenEditSave_Transcript)
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
TEST (DailyWorkflow_MultiBufferSwitchClose_Transcript)
|
TEST(DailyWorkflow_MultiBufferSwitchClose_Transcript)
|
||||||
{
|
{
|
||||||
ktet::InstallDefaultCommandsOnce();
|
ktet::InstallDefaultCommandsOnce();
|
||||||
|
|
||||||
@@ -123,7 +123,7 @@ TEST (DailyWorkflow_MultiBufferSwitchClose_Transcript)
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
TEST (DailyWorkflow_CrashRecovery_SwapReplay_Transcript)
|
TEST(DailyWorkflow_CrashRecovery_SwapReplay_Transcript)
|
||||||
{
|
{
|
||||||
ktet::InstallDefaultCommandsOnce();
|
ktet::InstallDefaultCommandsOnce();
|
||||||
|
|
||||||
@@ -167,4 +167,4 @@ TEST (DailyWorkflow_CrashRecovery_SwapReplay_Transcript)
|
|||||||
ed.Swap()->Detach(buf);
|
ed.Swap()->Detach(buf);
|
||||||
std::remove(path.c_str());
|
std::remove(path.c_str());
|
||||||
std::remove(swap_path.c_str());
|
std::remove(swap_path.c_str());
|
||||||
}
|
}
|
||||||
|
|||||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user