UI restructuring:
- Dashboard (`screen_dashboard.cpp`, `screen_idx = 6`) is the new home
screen at boot. Reads Overview / Health / Analysis / Modules from
the current System every frame; per-module rows list parts grouped
by `connector_type` and a Power/Gnd inference summary (yellow when
any name-Power signal is refuted). Scrollable via PgUp/PgDn/Home/End.
Letter shortcuts: `c`=console, `s`=search, `p`=plug (alias of
connect), `t`=set-type, `e`=explore, `n`=net, `a`=analyze, `q`=quit.
- Global Ctrl-P palette (`screen_palette.cpp`) — fuzzy-finds over
registered commands + module / signal names. Activation runs the
bare command or jumps to the matching screen with state seeded.
- Unified analyze screen (`screen_analyze.cpp`, `screen_idx = 7`):
tabbed layout (`Issues / Groups / Types`), Tab or ←→ to switch
tabs, ↑/↓ to navigate the focused list. Replaces the previous
shell-bouncing `[v]erify` shortcut — `verify` content is now in
the Issues tab. Types tab attaches the decision rationale to each
signal row (fan-out / voltage / hard floor).
- Context help panel: `RenderHelpPanel(title, entries)` in
`tui_helpers.{hpp,cpp}` rendered on the right of every screen.
- Console (former "log") rename: screen 0 is `[c]onsole` in the UI
and "console" in its help-panel title. The underlying screen and
the shell prompt are unchanged.
- Esc from any non-home screen returns to the dashboard. The
dashboard itself swallows Esc; quit via `q` / the `quit` command.
`quit` now calls `screen_ptr->Exit()` directly so it works from
any screen including via the palette.
Signal type inference:
- `Signal::type` defaults to `Other` — auto-inference no longer
happens at construction.
- `infer_signal_types(System*)` is called at the end of every load.
Three rules: GndShield from name alone; Power requires name match
+ a hard fan-out floor (< 3 pins = always Other, regardless of
name or voltage) + at least one positive structural signal
(fan-out ≥ 4 OR voltage pattern in the name like `3V3`, `5V`).
- Thresholds exposed in `analysis.hpp` (`POWER_FANOUT_HARD_FLOOR`,
`POWER_FANOUT_CONFIRM_MIN`, `has_voltage_pattern`) so the analyze
screen can render the same rationale without duplicating logic.
- `set-signal-type` still wins; save/restore round-trips the type.
Analysis groups & anomalies:
- New `GroupKind::DiffBus` — ≥ 2 diff pairs sharing the same
outer-stem with consecutive integer indices are aggregated into a
single bus (`MDI[0..3]_P/N`). `MDI0` and `PCIE_TX_0` index forms
both accepted. Solo pairs under a bus-able stem fall back to
`DiffPair`.
- New `AnomalyKind::DiffBusGap` for missing lanes.
Documentation:
- `DESIGN.md`: dedicated "Categorization rules (normative)" section
consolidating signal type, NC origin, signal groups, anomalies,
component kind, and connector wiring rules with exact thresholds
and decision order.
- `doc/user/analysis.md` (new): user-facing version of the same
rules in plain language. Linked from `doc/user/index.md`.
Tests: +6 new cases (62 total). Adjusted `test_persist.cpp` to set
the signal type explicitly in the fixture (no more auto-inference).
Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
216 lines
7.3 KiB
C++
216 lines
7.3 KiB
C++
#ifndef _TUI_HPP_
|
|
#define _TUI_HPP_
|
|
|
|
#include <atomic>
|
|
#include <deque>
|
|
#include <functional>
|
|
#include <iosfwd>
|
|
#include <map>
|
|
#include <memory>
|
|
#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;
|
|
Completion completion = Completion::None;
|
|
};
|
|
|
|
struct CommandSpec {
|
|
struct Param {
|
|
std::string name;
|
|
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;
|
|
bool interactive = false; ///< opens a full-screen mode when called bare
|
|
};
|
|
|
|
// ---- 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;
|
|
int scroll_offset; ///< Lines scrolled up from the tail; 0 = follow newest output.
|
|
bool quit;
|
|
bool in_source;
|
|
|
|
std::unique_ptr<System> sys;
|
|
std::deque<Prompt> pending;
|
|
std::map<std::string, CommandSpec> commands;
|
|
std::map<std::string, std::string> vars; ///< $var-style substitution table.
|
|
|
|
// ---- Screen orchestration ----
|
|
int screen_idx;
|
|
|
|
// ---- Search screen state ----
|
|
std::vector<std::string> search_modules;
|
|
std::vector<std::string> search_types;
|
|
int search_module_idx;
|
|
int search_type_idx;
|
|
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;
|
|
std::vector<std::string> explore_detail_sig; ///< parallel: signal name per detail line (empty = no signal)
|
|
int explore_detail_idx;
|
|
std::string explore_header;
|
|
int explore_focus_idx;
|
|
|
|
// ---- Source-file loading (event-driven, one line per tick) ----
|
|
std::atomic<bool> loading; ///< true while a script is being processed; read by tick thread.
|
|
std::atomic<bool> tick_in_flight; ///< main thread acks each tick by clearing this; ticker waits.
|
|
std::string loading_filename;
|
|
std::vector<std::string> loading_lines;
|
|
size_t loading_idx;
|
|
int loading_executed;
|
|
int loading_lineno;
|
|
bool loading_prev_in_source;
|
|
ftxui::ScreenInteractive *screen_ptr; ///< set in Run() so Source() can post events.
|
|
|
|
// ---- Net screen state ----
|
|
std::vector<std::string> net_modules;
|
|
int net_module_idx;
|
|
std::string net_sig_filter;
|
|
std::vector<std::string> net_sigs; ///< rebuilt every frame from filter
|
|
int net_sig_idx;
|
|
int net_focus_idx;
|
|
|
|
// ---- Dashboard scroll state (0 = top; grows as the user scrolls down) ----
|
|
int dashboard_scroll_offset = 0;
|
|
|
|
// ---- Analyze screen state (unified verify + analyze) ----
|
|
int analyze_focus_idx = 0; ///< 0=issues 1=groups 2=types
|
|
std::vector<std::string> analyze_issues;
|
|
std::vector<std::string> analyze_groups;
|
|
std::vector<std::string> analyze_types;
|
|
int analyze_issue_idx = 0;
|
|
int analyze_group_idx = 0;
|
|
int analyze_type_idx = 0;
|
|
|
|
// ---- Command palette (global, fuzzy-find over commands + objects) ----
|
|
bool palette_open = false;
|
|
std::string palette_query;
|
|
int palette_idx = 0;
|
|
// Rebuilt every frame from <query, sys>: label shown to the user.
|
|
std::vector<std::string> palette_labels;
|
|
// Parallel kind/payload for each label. kind: 'c'=command, 'm'=module,
|
|
// 's'=signal. payload: command name / module name / "module\tsignal".
|
|
std::vector<std::pair<char, std::string>> palette_items;
|
|
|
|
// ---- Signal-type popup (shared between net + explore screens) ----
|
|
bool sigtype_dialog_open = false;
|
|
std::string sigtype_dialog_mod;
|
|
std::string sigtype_dialog_sig;
|
|
std::vector<std::string> sigtype_dialog_entries; ///< ["power","gnd","other"]
|
|
int sigtype_dialog_choice = 0;
|
|
|
|
// ---- 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();
|
|
void DumpCommandsMd(std::ostream &out) const;
|
|
|
|
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 LoadHistory();
|
|
void AppendHistory(const std::string &cmd);
|
|
void Source(const std::string &filename);
|
|
void ProcessNextSourceLine();
|
|
std::string ExpandVars(const std::string &s) const;
|
|
|
|
// Completion (completion.cpp)
|
|
void CompleteCommand(size_t start = 0);
|
|
void CompletePath(size_t start = 0);
|
|
void CompleteInline();
|
|
|
|
// Open the signal-type popup for <mod>/<sig> (no-op if names don't resolve).
|
|
void OpenSignalTypeDialog(const std::string &mod_name,
|
|
const std::string &sig_name);
|
|
// Apply the selected type to the targeted signal, record a
|
|
// `set-signal-type` line (deduping consecutive edits of the same signal),
|
|
// and close the popup.
|
|
void ApplySignalTypeChoice();
|
|
|
|
// 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();
|
|
ftxui::Component BuildNetScreen();
|
|
ftxui::Component BuildDashboardScreen();
|
|
ftxui::Component BuildAnalyzeScreen();
|
|
ftxui::Component BuildSignalTypeModal();
|
|
ftxui::Component BuildPaletteModal();
|
|
// Open palette (resets query/index, builds initial list).
|
|
void OpenPalette();
|
|
// Execute the currently-highlighted palette entry.
|
|
void ActivatePaletteEntry();
|
|
};
|
|
|
|
#endif // _TUI_HPP_
|