build: split core/ from frontends/; prepare for multiple GUI/TUI targets
Reorganise the tree into business vs frontend as separate directories:
src/core/{domain,imports,app} (was system/, imports/, app/)
src/frontends/tui/ (was tui/ + main.cpp)
tests/tui/ (the FTXUI-coupled helper test)
All cross-dir #include paths rewritten; same-dir includes untouched.
CMake: essim_core is the frontend-agnostic business library — links libzip,
pugixml and bsdl, NO GUI toolkit. Each frontend is a self-contained
src/frontends/<name>/ (own CMakeLists, toolkit, main.cpp) that links
essim_core, selected with -DESSIM_FRONTEND=<name> (default tui; 'none' = core +
tests only, no toolkit fetched). FTXUI moved into the tui frontend. Tests are
split: essim_tests links essim_core (no FTXUI), essim_tui_tests links essim_tui.
Verified: default tui build green (ctest 2/2); ESSIM_FRONTEND=none builds the
core + tests with FTXUI never fetched and no `essim` binary.
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
70
src/frontends/tui/commands_export.cpp
Normal file
70
src/frontends/tui/commands_export.cpp
Normal file
@@ -0,0 +1,70 @@
|
||||
#include "frontends/tui/tui.hpp"
|
||||
|
||||
#include "core/app/export.hpp"
|
||||
#include "core/domain/connect.hpp"
|
||||
#include "core/domain/system.hpp"
|
||||
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
// Thin UI wrapper around app::export_connections — this file only resolves
|
||||
// arguments / the file dialog and renders the result. All the actual export
|
||||
// (CSV / ODS building, file writing) lives in src/app/export.cpp.
|
||||
void Tui::RegisterExportCommands() {
|
||||
commands["export"] = {
|
||||
{{"kind [connections]", Completion::None},
|
||||
{"filename (.csv)", Completion::Path}},
|
||||
[this](const std::vector<std::string> &args) {
|
||||
if (!sys) { Print("no system: run 'new' first."); return; }
|
||||
|
||||
if (args.empty()) {
|
||||
// Bare → the generic file dialog. The CSV/ODS filter rewrites
|
||||
// the extension; the action below dispatches on it.
|
||||
OpenFileDialog(
|
||||
"Export — connections",
|
||||
"export.connections",
|
||||
"connections.csv",
|
||||
{{"CSV", ".csv"}, {"ODS", ".ods"}},
|
||||
[this](const std::string &path) {
|
||||
Dispatch("export connections " + path);
|
||||
});
|
||||
return;
|
||||
}
|
||||
if (args.size() != 2) {
|
||||
Print("usage: export <kind> <file> (or no args for the dialog)");
|
||||
return;
|
||||
}
|
||||
const std::string &kind = args[0];
|
||||
const std::string &path = args[1];
|
||||
|
||||
if (kind != "connections") {
|
||||
ShowError("export: unknown kind '" + kind + "'\n"
|
||||
"Known kinds: connections");
|
||||
return;
|
||||
}
|
||||
|
||||
app::ExportFormat fmt;
|
||||
if (!app::export_format_from_path(path, fmt)) {
|
||||
ShowError("export: unknown extension — accepted: .csv, .ods");
|
||||
return;
|
||||
}
|
||||
|
||||
app::ExportResult r = app::export_connections(sys.get(), path, fmt);
|
||||
if (!r.ok) {
|
||||
ShowError("export failed:\n" + r.error);
|
||||
return;
|
||||
}
|
||||
|
||||
const bool ods = (fmt == app::ExportFormat::Ods);
|
||||
std::string msg = ods ? "export connections (.ods): "
|
||||
: "export connections (.csv): ";
|
||||
if (ods) msg += std::to_string(r.sheets) + " sheet(s), ";
|
||||
Print(msg + std::to_string(r.rows) + " wire(s) → " + path);
|
||||
},
|
||||
/*prompt_for_missing=*/ false,
|
||||
"export structured data to CSV / ODS (kinds: connections; "
|
||||
"bare form opens the file-picker dialog)",
|
||||
/*scriptable=*/ true,
|
||||
/*interactive=*/ true,
|
||||
};
|
||||
}
|
||||
Reference in New Issue
Block a user