Refactor: extract export commands; co-locate sigtype popup logic.

Two focused, behaviour-preserving moves:

1. `OpenSignalTypeDialog` + `ApplySignalTypeChoice` moved from
   `shell.cpp` to `screen_sigtype_modal.cpp` so the popup owns all of
   its logic instead of having its open/apply functions live in the
   shell file.

2. The `export` command extracted from `commands.cpp` to a new
   `commands_export.cpp` under a `Tui::RegisterExportCommands()`
   member. `RegisterCommands()` calls it at the end. File-local
   helpers (`csv_quote`, `pin_side`) move alongside in an anonymous
   namespace.

Establishes the pattern for future per-group splits: declare a
`Register<X>Commands()` member, define it in its own file, call it
from the orchestrator. Other groups stay in `commands.cpp` for now —
nothing else has grown large enough to warrant the split.

Sizes: shell.cpp 497 → 448, commands.cpp 846 → 675 (+ 191 for the
new commands_export.cpp). DESIGN.md updated.

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
This commit is contained in:
2026-05-16 12:18:58 +02:00
parent 7d307dad57
commit 67de4dcaf3
6 changed files with 261 additions and 225 deletions

View File

@@ -31,55 +31,6 @@ void Tui::BootDispatch(const std::string &raw) {
screen_idx = 4;
}
void Tui::OpenSignalTypeDialog(const std::string &mod_name,
const std::string &sig_name) {
if (!sys) return;
Signal *sig = nullptr;
try {
Module *m = sys->modules()->get(mod_name);
sig = m->signals->get(sig_name);
} catch (const std::exception &) { return; }
sigtype_dialog_mod = mod_name;
sigtype_dialog_sig = sig_name;
switch (sig->type) {
case SignalType::Power: sigtype_dialog_choice = 0; break;
case SignalType::GndShield: sigtype_dialog_choice = 1; break;
default: sigtype_dialog_choice = 2; break;
}
sigtype_dialog_open = true;
}
void Tui::ApplySignalTypeChoice() {
sigtype_dialog_open = false;
if (!sys) return;
SignalType t;
switch (sigtype_dialog_choice) {
case 0: t = SignalType::Power; break;
case 1: t = SignalType::GndShield; break;
default: t = SignalType::Other; break;
}
Signal *sig = nullptr;
try {
Module *m = sys->modules()->get(sigtype_dialog_mod);
sig = m->signals->get(sigtype_dialog_sig);
} catch (const std::exception &) { return; }
if (sig->type == t) return; // no-op, no record
sig->type = t;
if (in_source) return;
// Dedup: if the immediately previous recorded line targets the same
// signal, replace it so a sequence of toggles collapses to one line.
std::string line = "set-signal-type " + sigtype_dialog_mod + " "
+ sigtype_dialog_sig + " " + signal_type_name(t);
std::string prefix = "set-signal-type " + sigtype_dialog_mod + " "
+ sigtype_dialog_sig + " ";
if (!recorded.empty() && recorded.back().rfind(prefix, 0) == 0)
recorded.back() = std::move(line);
else
recorded.push_back(std::move(line));
}
void Tui::Print(const std::string &line) {
output.push_back(line);
scroll_offset = 0; // any new line snaps the view back to the tail