Refactor Init method across all frontends to include argc and argv for improved argument handling consistency.

This commit is contained in:
2026-01-12 10:35:24 -08:00
parent 6eb240a0c4
commit 8634eb78f0
10 changed files with 21 additions and 17 deletions

View File

@@ -12,7 +12,7 @@ public:
virtual ~Frontend() = default;
// Initialize the frontend (create window/terminal, etc.)
virtual bool Init(Editor &ed) = 0;
virtual bool Init(int &argc, char **argv, Editor &ed) = 0;
// Execute one iteration (poll input, dispatch, draw). Set running=false to exit.
virtual void Step(Editor &ed, bool &running) = 0;

View File

@@ -30,8 +30,10 @@
static auto kGlslVersion = "#version 150"; // GL 3.2 core (macOS compatible)
bool
GUIFrontend::Init(Editor &ed)
GUIFrontend::Init(int &argc, char **argv, Editor &ed)
{
(void) argc;
(void) argv;
// Attach editor to input handler for editor-owned features (e.g., universal argument)
input_.Attach(&ed);
// editor dimensions will be initialized during the first Step() frame

View File

@@ -17,7 +17,7 @@ public:
~GUIFrontend() override = default;
bool Init(Editor &ed) override;
bool Init(int &argc, char **argv, Editor &ed) override;
void Step(Editor &ed, bool &running) override;

View File

@@ -658,11 +658,9 @@ private:
} // namespace
bool
GUIFrontend::Init(Editor &ed)
GUIFrontend::Init(int &argc, char **argv, Editor &ed)
{
int argc = 0;
char **argv = nullptr;
app_ = new QApplication(argc, argv);
app_ = new QApplication(argc, argv);
window_ = new MainWindow(input_);
window_->show();

View File

@@ -18,7 +18,7 @@ public:
~GUIFrontend() override = default;
bool Init(Editor &ed) override;
bool Init(int &argc, char **argv, Editor &ed) override;
void Step(Editor &ed, bool &running) override;

View File

@@ -8,8 +8,10 @@
bool
TerminalFrontend::Init(Editor &ed)
TerminalFrontend::Init(int &argc, char **argv, Editor &ed)
{
(void) argc;
(void) argv;
// Ensure Control keys reach the app: disable XON/XOFF and dsusp/susp bindings (e.g., ^S/^Q, ^Y on macOS)
{
struct termios tio{};
@@ -121,4 +123,4 @@ TerminalFrontend::Shutdown()
have_old_sigint_ = false;
}
endwin();
}
}

View File

@@ -21,7 +21,7 @@ public:
// Adjust if your terminal needs a different threshold.
static constexpr int kEscDelayMs = 50;
bool Init(Editor &ed) override;
bool Init(int &argc, char **argv, Editor &ed) override;
void Step(Editor &ed, bool &running) override;

View File

@@ -4,8 +4,10 @@
bool
TestFrontend::Init(Editor &ed)
TestFrontend::Init(int &argc, char **argv, Editor &ed)
{
(void) argc;
(void) argv;
ed.SetDimensions(24, 80);
return true;
}
@@ -30,4 +32,4 @@ TestFrontend::Step(Editor &ed, bool &running)
void
TestFrontend::Shutdown() {}
TestFrontend::Shutdown() {}

View File

@@ -13,7 +13,7 @@ public:
~TestFrontend() override = default;
bool Init(Editor &ed) override;
bool Init(int &argc, char **argv, Editor &ed) override;
void Step(Editor &ed, bool &running) override;

View File

@@ -112,7 +112,7 @@ RunStressHighlighter(unsigned seconds)
int
main(int argc, const char *argv[])
main(int argc, char *argv[])
{
std::setlocale(LC_ALL, "");
@@ -136,7 +136,7 @@ main(int argc, const char *argv[])
int opt;
int long_index = 0;
unsigned stress_seconds = 0;
while ((opt = getopt_long(argc, const_cast<char *const *>(argv), "gthV", long_opts, &long_index)) != -1) {
while ((opt = getopt_long(argc, argv, "gthV", long_opts, &long_index)) != -1) {
switch (opt) {
case 'g':
req_gui = true;
@@ -303,7 +303,7 @@ main(int argc, const char *argv[])
}
#endif
if (!fe->Init(editor)) {
if (!fe->Init(argc, argv, editor)) {
std::cerr << "kte: failed to initialize frontend" << std::endl;
return 1;
}