main.cpp was entirely TUI-specific (constructed Tui, parsed argv, drove
BootDispatch/DumpOutput/Run directly). Introduce a shared frontends layer so a
second frontend can reuse the whole launch flow:
- src/frontends/frontend.hpp — abstract Frontend interface (BootDispatch,
DumpCommandsMd, DumpOutput, Run), header-only, no GUI toolkit, no core dep.
- src/frontends/frontend_main.{hpp,cpp} — frontend_main(argc, argv, Frontend&):
all the argv parsing (--source/--restore/--batch/--commands-md/--help) and
the boot → batch/run flow, driving any frontend through the interface.
- Tui now implements Frontend (the four methods already matched; just marked
override).
- The TUI main.cpp shrinks to: construct Tui, call frontend_main. A second
frontend's main() is identical with its own Frontend type.
Build: a small GUI-toolkit-free static lib essim_frontend (frontend_main.cpp)
is added at the top level when a frontend is selected, and the essim exe links
it. ESSIM_FRONTEND=none still builds core+tests only (no essim_frontend, no
FTXUI). Binary stays ./build/essim.
Behaviour unchanged across --batch/--commands-md/--help/exit codes; only the
usage text is genericised ("the TUI" → "the interface", "console screen" →
"console") now that the launcher is shared.
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
31 lines
1.1 KiB
C++
31 lines
1.1 KiB
C++
#ifndef _FRONTEND_HPP_
|
|
#define _FRONTEND_HPP_
|
|
|
|
#include <iosfwd>
|
|
#include <string>
|
|
|
|
// Abstract entry-point interface every frontend (TUI, GUI, …) implements, so
|
|
// one shared launcher (frontend_main) can drive any of them: parse argv, run
|
|
// boot commands, optionally dump output (batch / docs) and enter the event
|
|
// loop. Lives in the frontends layer — essim_core never depends on it.
|
|
class Frontend {
|
|
public:
|
|
virtual ~Frontend() = default;
|
|
|
|
// Dispatch one command synchronously, exactly as if the user typed it
|
|
// (e.g. "restore foo.essim" or "source bring-up.essim"), before the event
|
|
// loop starts — used to seed the system at boot.
|
|
virtual void BootDispatch(const std::string &raw) = 0;
|
|
|
|
// Write the command registry as Markdown (used for doc generation).
|
|
virtual void DumpCommandsMd(std::ostream &out) const = 0;
|
|
|
|
// Write the accumulated console output (batch mode: no event loop).
|
|
virtual void DumpOutput(std::ostream &out) const = 0;
|
|
|
|
// Enter the interactive event loop.
|
|
virtual void Run() = 0;
|
|
};
|
|
|
|
#endif // _FRONTEND_HPP_
|