#include "frontends/tui/tui.hpp" #include "core/app/export.hpp" #include "core/domain/connect.hpp" #include "core/domain/system.hpp" #include #include // 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 &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 (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, }; }