ODS import, persistence, scripting, connector types + VPX transforms.

- ODS importer (libzip + pugixml): each sheet → Part, rows → Pin/Signal.
- save / restore commands: tab-delimited snapshot of modules, parts,
  signals, connections + pin_map. `restore` replaces the System.
- source / script-save: replay a file of commands; record canonical
  commands since last `new` for replay later. Interactive screens
  refused during source. `explore` marked non-scriptable.
- TUI screen_explore: 4 columns (modules, type, children, detail) with
  filters on children and detail; detail is a Menu so arrows scroll
  long pin lists.
- Connector types & transforms: each Part carries a `connector_type`
  string. `set-type` validates the part's pin layout against the type
  (cols set check). `connect` strict pair: rejects when lookup falls
  back to identity unless types are both empty AND pin sets match.
- VPX 3U transforms: 3 registered pairs (vpx-3u-bkp-pN ↔ vpx-3u-payload-pN,
  N=0/1/2) with row-pattern correspondence tables ported from the user's
  Python reference.
- Code split for maintainability: src/tui/{shell,completion,commands,
  screen_main,screen_search,screen_connect,screen_settype,screen_explore,
  tui_helpers}.cpp.
- Bug fixes: Module::add(Part*) override sets part->prnt (was always
  null, breaking save's W lines). Defensive guards in explore against
  empty Menu lists. Renderer wrapped in try/catch so domain throws
  surface as on-screen errors instead of SIGABRT.

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
This commit is contained in:
2026-05-08 19:58:51 +02:00
parent 3395469810
commit f3920964f0
31 changed files with 2369 additions and 467 deletions

View File

@@ -8,36 +8,50 @@
#include <string>
#include <vector>
#include <ftxui/component/component.hpp>
#include <ftxui/component/screen_interactive.hpp>
class System;
class Tui {
enum class Completion { None, Path, Command };
struct Prompt {
std::string question;
std::function<void(const std::string &)> on_answer;
bool path_completion = false;
Completion completion = Completion::None;
};
struct CommandSpec {
struct Param {
std::string name;
bool path_completion = false;
Completion completion = Completion::None;
};
std::vector<Param> params;
std::function<void(const std::vector<std::string> &)> action;
bool prompt_for_missing = true;
std::string description;
bool scriptable = true;
};
// ---- Shell state ----
std::vector<std::string> history;
std::vector<std::string> recorded; // commands since the last 'new', for script-save
std::vector<std::string> output;
std::string input;
int cursor_pos;
int history_idx;
bool quit;
bool in_source;
std::unique_ptr<System> sys;
std::deque<Prompt> pending;
std::map<std::string, CommandSpec> commands;
// ---- Screen orchestration ----
int screen_idx;
// ---- Search screen state ----
std::vector<std::string> search_modules;
std::vector<std::string> search_types;
int search_module_idx;
@@ -45,31 +59,84 @@ class Tui {
int search_focus_idx;
std::string search_query;
// ---- Connect screen state ----
std::vector<std::string> connect_modules;
int connect_m1_idx;
int connect_m2_idx;
std::string connect_p1_filter;
std::string connect_p2_filter;
std::vector<std::string> connect_p1_list;
std::vector<std::string> connect_p2_list;
int connect_p1_idx;
int connect_p2_idx;
int connect_focus_idx;
// ---- Explore screen state ----
std::vector<std::string> explore_modules;
int explore_module_idx;
std::vector<std::string> explore_types;
int explore_type_idx;
std::vector<std::string> explore_children;
int explore_child_idx;
std::string explore_child_filter;
std::string explore_detail_filter;
std::vector<std::string> explore_detail;
int explore_detail_idx;
std::string explore_header;
int explore_focus_idx;
// ---- Set-type screen state ----
std::vector<std::string> settype_modules;
int settype_m_idx;
std::string settype_p_filter;
std::vector<std::string> settype_p_list;
int settype_p_idx;
std::string settype_type;
std::string settype_status;
int settype_focus_idx;
public:
Tui();
~Tui();
void Run();
private:
// Lifecycle (commands.cpp)
void RegisterCommands();
// Shell (shell.cpp)
void Print(const std::string &line);
void Submit();
void Dispatch(const std::string &raw);
void Finalize(const std::string &name,
const CommandSpec &spec,
const std::vector<std::string> &args);
void HistoryUp();
void HistoryDown();
void CancelPending();
void Print(const std::string &line);
void CompleteCommand();
void CompletePath();
void LoadHistory();
void AppendHistory(const std::string &cmd);
void Source(const std::string &filename);
static std::vector<std::string> Tokenize(const std::string &s);
// Completion (completion.cpp)
void CompleteCommand(size_t start = 0);
void CompletePath(size_t start = 0);
void CompleteInline();
// Filtered part list rebuild (used by connect & set-type screens)
void RefreshFilteredPartList(const std::vector<std::string> &modules,
int m_idx,
const std::string &filter,
std::vector<std::string> &out,
int &sel_idx);
// Screen builders (screen_*.cpp)
ftxui::Component BuildMainScreen(ftxui::ScreenInteractive &screen);
ftxui::Component BuildSearchScreen();
ftxui::Component BuildConnectScreen();
ftxui::Component BuildSettypeScreen();
ftxui::Component BuildExploreScreen();
};
#endif // _TUI_HPP_