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; virtual ~Frontend() = default;
// Initialize the frontend (create window/terminal, etc.) // 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. // Execute one iteration (poll input, dispatch, draw). Set running=false to exit.
virtual void Step(Editor &ed, bool &running) = 0; 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) static auto kGlslVersion = "#version 150"; // GL 3.2 core (macOS compatible)
bool 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) // Attach editor to input handler for editor-owned features (e.g., universal argument)
input_.Attach(&ed); input_.Attach(&ed);
// editor dimensions will be initialized during the first Step() frame // editor dimensions will be initialized during the first Step() frame

View File

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

View File

@@ -658,10 +658,8 @@ private:
} // namespace } // namespace
bool 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_ = new MainWindow(input_);

View File

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

View File

@@ -8,8 +8,10 @@
bool 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) // Ensure Control keys reach the app: disable XON/XOFF and dsusp/susp bindings (e.g., ^S/^Q, ^Y on macOS)
{ {
struct termios tio{}; struct termios tio{};

View File

@@ -21,7 +21,7 @@ public:
// Adjust if your terminal needs a different threshold. // Adjust if your terminal needs a different threshold.
static constexpr int kEscDelayMs = 50; 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; void Step(Editor &ed, bool &running) override;

View File

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

View File

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

View File

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