|
|
|
|
@ -3,7 +3,10 @@
|
|
|
|
|
#include "fgc/DumpParser.h"
|
|
|
|
|
#include "fgc/HelpText.h"
|
|
|
|
|
#include "fgc/Logger.h"
|
|
|
|
|
#include "fgc/ui/Scroll.h"
|
|
|
|
|
|
|
|
|
|
#include <algorithm>
|
|
|
|
|
#include <array>
|
|
|
|
|
#include <chrono>
|
|
|
|
|
#include <cstdio>
|
|
|
|
|
#include <map>
|
|
|
|
|
@ -14,6 +17,9 @@
|
|
|
|
|
#include <ftxui/component/event.hpp>
|
|
|
|
|
#include <ftxui/component/screen_interactive.hpp>
|
|
|
|
|
#include <ftxui/dom/elements.hpp>
|
|
|
|
|
#include <ftxui/dom/node.hpp>
|
|
|
|
|
#include <ftxui/dom/requirement.hpp>
|
|
|
|
|
#include <ftxui/screen/box.hpp>
|
|
|
|
|
#include <ftxui/screen/color.hpp>
|
|
|
|
|
|
|
|
|
|
namespace fgc {
|
|
|
|
|
@ -39,6 +45,88 @@ Element panel(const std::string& title, Color title_color, Element body) {
|
|
|
|
|
return window(text(" " + title + " ") | bold | color(title_color), std::move(body)) | flex;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// ---- Scrollable panes -------------------------------------------------------
|
|
|
|
|
//
|
|
|
|
|
// `yframe` clips its child to the available box and scrolls to reveal whichever
|
|
|
|
|
// element carries the "selected box". Nothing sets one by default, so a bare
|
|
|
|
|
// `vbox(rows) | yframe` renders the TOP of the content and silently drops the
|
|
|
|
|
// rest - which is what used to make long waypoint lists and register dumps
|
|
|
|
|
// unreachable.
|
|
|
|
|
//
|
|
|
|
|
// The anchor has to be applied DIRECTLY to the frame's child: focusPosition
|
|
|
|
|
// leaves requirement_.selection at NORMAL, and vbox/hbox only propagate a
|
|
|
|
|
// child's selected box when its selection is strictly greater than their own
|
|
|
|
|
// (which starts at NORMAL). Only focus(), which sets FOCUSED, would survive
|
|
|
|
|
// being buried inside a row - and it is unusable here because the rows have
|
|
|
|
|
// wildly different heights (a 3-line axis row, a 1-line separator, the whole
|
|
|
|
|
// scan grid as one ~20-line element), so a per-row cursor would scroll by 1, 3
|
|
|
|
|
// or 40 lines a keypress.
|
|
|
|
|
// Capture a child's REQUESTED height. reflect() cannot do this: its Render
|
|
|
|
|
// intersects the box with the screen stencil, so inside a frame it hands back
|
|
|
|
|
// the visible height, and content/view would always compare equal.
|
|
|
|
|
Decorator reflectHeight(int& out) {
|
|
|
|
|
class Impl : public Node {
|
|
|
|
|
public:
|
|
|
|
|
Impl(Element child, int& out) : Node(unpack(std::move(child))), out_(out) {}
|
|
|
|
|
void ComputeRequirement() override {
|
|
|
|
|
Node::ComputeRequirement();
|
|
|
|
|
requirement_ = children_[0]->requirement();
|
|
|
|
|
out_ = requirement_.min_y;
|
|
|
|
|
}
|
|
|
|
|
void SetBox(Box box) override {
|
|
|
|
|
Node::SetBox(box);
|
|
|
|
|
children_[0]->SetBox(box);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private:
|
|
|
|
|
int& out_;
|
|
|
|
|
};
|
|
|
|
|
return [&out](Element child) { return std::make_shared<Impl>(std::move(child), out); };
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
struct ScrollState {
|
|
|
|
|
int top = 0; // first body LINE we want visible
|
|
|
|
|
bool follow = false; // log only: pin to the newest line instead
|
|
|
|
|
|
|
|
|
|
// Measured by the previous frame: the body's full requested height, and the
|
|
|
|
|
// visible height of the pane it is framed into.
|
|
|
|
|
int content_h = 0;
|
|
|
|
|
Box view{};
|
|
|
|
|
|
|
|
|
|
int contentH() const { return content_h; }
|
|
|
|
|
int viewH() const { return view.y_max - view.y_min + 1; }
|
|
|
|
|
bool scrollable() const { return scrollMax(contentH(), viewH()) > 0; }
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
// Frame `body` so line `st.top` sits at the top of the pane.
|
|
|
|
|
//
|
|
|
|
|
// Frame::SetBox CENTRES the viewport on the anchor (dy = selected.y_min -
|
|
|
|
|
// view/2 + focused/2, then clamped), so the anchor is pushed half a screen down
|
|
|
|
|
// to cancel that and land on `top` exactly.
|
|
|
|
|
Element scrollableBody(Element body, ScrollState& st) {
|
|
|
|
|
st.top = scrollClamp(st.top, st.contentH(), st.viewH());
|
|
|
|
|
Decorator anchor = st.follow
|
|
|
|
|
? focusPositionRelative(0.f, 1.f)
|
|
|
|
|
: focusPosition(0, st.top + st.viewH() / 2);
|
|
|
|
|
return std::move(body) | reflectHeight(st.content_h) | anchor | vscroll_indicator | yframe |
|
|
|
|
|
reflect(st.view);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Overlay window title. The scroll keys are advertised only while there is
|
|
|
|
|
// something off-screen, so the hint doubles as the "there is more below" cue on
|
|
|
|
|
// a pane that happens to fit.
|
|
|
|
|
Element overlayTitle(const std::string& name, const std::string& keys, const ScrollState& st,
|
|
|
|
|
Color c = Color::Cyan, bool arrows_scroll = true) {
|
|
|
|
|
std::string hint = keys;
|
|
|
|
|
if (st.scrollable())
|
|
|
|
|
hint += arrows_scroll ? " \xE2\x86\x91\xE2\x86\x93/PgUp/PgDn:scroll" : " PgUp/PgDn:scroll";
|
|
|
|
|
return text(" " + name + " (" + hint + ") ") | bold | color(c);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Element cameraDetailTitle(const ScrollState& st) {
|
|
|
|
|
return overlayTitle("CAMERA SYSTEM", "c/Esc:close", st);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// "key" + label pair for the nano-style bottom bar.
|
|
|
|
|
Element keyHint(const std::string& key, const std::string& label) {
|
|
|
|
|
return hbox({text(" " + key + " ") | inverted, text(" " + label + " ")});
|
|
|
|
|
@ -141,7 +229,7 @@ Element cameraPanel(const CaptureView& c) {
|
|
|
|
|
// Expanded camera view ('c'): the full camera system — identity, live sensor
|
|
|
|
|
// telemetry, imaging config, acquisition health, encoding/output — with the
|
|
|
|
|
// auto-sweep scan grid below. The whole body scrolls (yframe) if it overflows.
|
|
|
|
|
Element cameraDetailPanel(const CaptureView& c) {
|
|
|
|
|
Element cameraDetailPanel(const CaptureView& c, ScrollState& st) {
|
|
|
|
|
auto num = [](double v, int dec) {
|
|
|
|
|
char b[32];
|
|
|
|
|
std::snprintf(b, sizeof(b), "%.*f", dec, v);
|
|
|
|
|
@ -259,17 +347,23 @@ Element cameraDetailPanel(const CaptureView& c) {
|
|
|
|
|
rows.push_back(hbox({text("reason ") | dim, text(c.scan_error) | color(Color::Red)}));
|
|
|
|
|
rows.push_back(text("Check [Scan] grid_file in the loaded config (see the startup "
|
|
|
|
|
"'Loaded config:' log line).") | dim);
|
|
|
|
|
return window(text(" CAMERA SYSTEM (c/Esc:close) ") | bold | color(Color::Cyan),
|
|
|
|
|
vbox(std::move(rows)) | yframe);
|
|
|
|
|
return window(cameraDetailTitle(st),
|
|
|
|
|
scrollableBody(vbox(std::move(rows)), st));
|
|
|
|
|
}
|
|
|
|
|
if (c.scan_grid.empty()) {
|
|
|
|
|
rows.push_back(text("(no scan grid defined — auto-sweep disabled)") | dim);
|
|
|
|
|
return window(text(" CAMERA SYSTEM (c/Esc:close) ") | bold | color(Color::Cyan),
|
|
|
|
|
vbox(std::move(rows)) | yframe);
|
|
|
|
|
return window(cameraDetailTitle(st),
|
|
|
|
|
scrollableBody(vbox(std::move(rows)), st));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// " # | yaw / pitch", current row inverted. Pitch column dropped on 1-axis.
|
|
|
|
|
constexpr size_t kRows = 18; // rows per column before wrapping
|
|
|
|
|
// Cap the COLUMN count rather than the row count: past the cap the grid grows
|
|
|
|
|
// downward, where the pane's vertical scrolling can reach it. Wrapping at a
|
|
|
|
|
// fixed 18 rows grew it rightwards instead, off the edge of a screen that
|
|
|
|
|
// yframe does not clip and no key can pan.
|
|
|
|
|
constexpr size_t kMaxCols = 3; // ~66 columns wide: fits an 80-column terminal
|
|
|
|
|
constexpr size_t kMinRows = 18; // short grids keep the original compact look
|
|
|
|
|
const size_t kRows = gridRowsPerColumn(c.scan_grid.size(), kMaxCols, kMinRows);
|
|
|
|
|
std::vector<Element> cols;
|
|
|
|
|
std::vector<Element> col;
|
|
|
|
|
auto flushColumn = [&] {
|
|
|
|
|
@ -295,8 +389,7 @@ Element cameraDetailPanel(const CaptureView& c) {
|
|
|
|
|
rows.push_back(hbox({text(" # ") | dim,
|
|
|
|
|
text(c.scan_pitch ? "yaw / pitch" : "yaw") | dim}));
|
|
|
|
|
rows.push_back(hbox(std::move(cols)));
|
|
|
|
|
return window(text(" CAMERA SYSTEM (c/Esc:close) ") | bold | color(Color::Cyan),
|
|
|
|
|
vbox(std::move(rows)) | yframe);
|
|
|
|
|
return window(cameraDetailTitle(st), scrollableBody(vbox(std::move(rows)), st));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Element connPanel(const ConnView& v) {
|
|
|
|
|
@ -313,7 +406,7 @@ Element connPanel(const ConnView& v) {
|
|
|
|
|
}));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Element logPanel(const std::vector<LogLine>& lines) {
|
|
|
|
|
Element logPanel(const std::vector<LogLine>& lines, ScrollState& st) {
|
|
|
|
|
std::vector<Element> rows;
|
|
|
|
|
for (const auto& l : lines) {
|
|
|
|
|
Color c = Color::Default;
|
|
|
|
|
@ -327,8 +420,15 @@ Element logPanel(const std::vector<LogLine>& lines) {
|
|
|
|
|
rows.push_back(text(l.text) | color(c));
|
|
|
|
|
}
|
|
|
|
|
if (rows.empty()) rows.push_back(text("(no log output yet)") | dim);
|
|
|
|
|
return window(text(" LOG ") | bold | color(Color::GrayLight),
|
|
|
|
|
vbox(std::move(rows)) | focusPositionRelative(0, 1) | yframe);
|
|
|
|
|
// Frozen scrollback withholds new lines, which is invisible without a cue.
|
|
|
|
|
Element label = text(" LOG ") | bold | color(Color::GrayLight);
|
|
|
|
|
Element title = label;
|
|
|
|
|
if (!st.follow)
|
|
|
|
|
title = hbox({label, text("scrollback ") | color(Color::Yellow) | bold,
|
|
|
|
|
text("(End:follow) ") | dim});
|
|
|
|
|
else if (st.scrollable())
|
|
|
|
|
title = hbox({label, text("(PgUp:scrollback) ") | dim});
|
|
|
|
|
return window(title, scrollableBody(vbox(std::move(rows)), st));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Compact strip below the log: the running special op (live) + the last
|
|
|
|
|
@ -360,7 +460,7 @@ Element activityPanel(const ActivityView& a) {
|
|
|
|
|
// Inline help pane (toggled with '?'). Lists every command section; the
|
|
|
|
|
// `sel`-th section is expanded to show each entry's detail. The Diagnostics
|
|
|
|
|
// section additionally renders the last captured firmware DUMP block.
|
|
|
|
|
Element helpPanel(int sel, const DumpView& dump) {
|
|
|
|
|
Element helpPanel(int sel, const DumpView& dump, ScrollState& st) {
|
|
|
|
|
const auto& cat = helpCatalog();
|
|
|
|
|
std::vector<Element> rows;
|
|
|
|
|
for (int i = 0; i < static_cast<int>(cat.size()); ++i) {
|
|
|
|
|
@ -395,8 +495,9 @@ Element helpPanel(int sel, const DumpView& dump) {
|
|
|
|
|
}
|
|
|
|
|
rows.push_back(text(""));
|
|
|
|
|
}
|
|
|
|
|
return window(text(" HELP (?:close Up/Down:section) ") | bold | color(Color::Cyan),
|
|
|
|
|
vbox(std::move(rows)) | yframe);
|
|
|
|
|
return window(overlayTitle("HELP", "?:close Up/Down:section", st, Color::Cyan,
|
|
|
|
|
/*arrows_scroll=*/false),
|
|
|
|
|
scrollableBody(vbox(std::move(rows)), st));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Aligned "label: value" row for the detail view.
|
|
|
|
|
@ -489,7 +590,7 @@ Element axisDumpDetail(const DumpAxis& ax) {
|
|
|
|
|
// (incl. RAMP_STAT, the last one) is visible without scrolling.
|
|
|
|
|
Element axisColumn(const std::string& title, const AxisView& live, const DumpData& d,
|
|
|
|
|
char letter, bool calib_has, const CalibAxisView& cal,
|
|
|
|
|
const DiagAxisView* diag) {
|
|
|
|
|
const DiagAxisView* diag, ScrollState& st) {
|
|
|
|
|
auto fmt = [](const char* f, double v) {
|
|
|
|
|
char b[32];
|
|
|
|
|
std::snprintf(b, sizeof(b), f, v);
|
|
|
|
|
@ -546,13 +647,15 @@ Element axisColumn(const std::string& title, const AxisView& live, const DumpDat
|
|
|
|
|
col.push_back(text(calib_has ? "fit failed" : "uncalibrated this session") | dim);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return panel(title, Color::Cyan, vbox(std::move(col)) | yframe);
|
|
|
|
|
// Each axis keeps its own frame so the YAW/PITCH titles stay put; framing the
|
|
|
|
|
// whole hbox instead would scroll the titles away with the content.
|
|
|
|
|
return panel(title, Color::Cyan, scrollableBody(vbox(std::move(col)), st));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Full-screen gimbal view (toggled with 'g'): one column per axis, each with
|
|
|
|
|
// live telemetry above its decoded firmware register dump + last calibration.
|
|
|
|
|
Element gimbalDetailPanel(const GimbalView& g, const DumpView& dump, const CalibResultView& calib,
|
|
|
|
|
const DiagResultView& diag) {
|
|
|
|
|
const DiagResultView& diag, std::array<ScrollState, 2>& st) {
|
|
|
|
|
DumpData d = parseDump(dump.text);
|
|
|
|
|
auto diagFor = [&](char axis) -> const DiagAxisView* {
|
|
|
|
|
for (const auto& a : diag.axes)
|
|
|
|
|
@ -580,11 +683,12 @@ Element gimbalDetailPanel(const GimbalView& g, const DumpView& dump, const Calib
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
std::vector<Element> cols;
|
|
|
|
|
cols.push_back(axisColumn("YAW", g.yaw, d, 'Y', calib.has, calib.yaw, diagFor('Y')));
|
|
|
|
|
cols.push_back(axisColumn("YAW", g.yaw, d, 'Y', calib.has, calib.yaw, diagFor('Y'), st[0]));
|
|
|
|
|
if (g.pitch_present)
|
|
|
|
|
cols.push_back(axisColumn("PITCH", g.pitch, d, 'P', calib.has, calib.pitch, diagFor('P')));
|
|
|
|
|
cols.push_back(
|
|
|
|
|
axisColumn("PITCH", g.pitch, d, 'P', calib.has, calib.pitch, diagFor('P'), st[1]));
|
|
|
|
|
|
|
|
|
|
return window(text(" GIMBAL (g/Esc:close d:refresh dump) ") | bold | color(Color::Cyan),
|
|
|
|
|
return window(overlayTitle("GIMBAL", "g/Esc:close d:refresh dump", st[0]),
|
|
|
|
|
vbox({header, separator(), hbox(std::move(cols)) | flex}));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@ -592,7 +696,7 @@ Element gimbalDetailPanel(const GimbalView& g, const DumpView& dump, const Calib
|
|
|
|
|
// then the ambient sensor. The two devices get their own headed sections, and
|
|
|
|
|
// each temperature is labelled with its provenance ("internal" vs "ambient"),
|
|
|
|
|
// so the reading the main window shows is never confused with the MTi's.
|
|
|
|
|
Element sensorsDetailPanel(const ImuView& v, const EnvView& e) {
|
|
|
|
|
Element sensorsDetailPanel(const ImuView& v, const EnvView& e, ScrollState& st) {
|
|
|
|
|
// Fixed-width, right-aligned to 2 decimals. The constant width keeps the sign
|
|
|
|
|
// column and decimal point from jumping as values cross zero or change digit
|
|
|
|
|
// count, so the readout stays steady instead of flickering. The width is kept
|
|
|
|
|
@ -741,11 +845,11 @@ Element sensorsDetailPanel(const ImuView& v, const EnvView& e) {
|
|
|
|
|
? (text(" " + env_name + " live ") | color(Color::Green) | bold)
|
|
|
|
|
: (text(" " + env_name + " no reading ") | color(Color::Red) |
|
|
|
|
|
bold));
|
|
|
|
|
// yframe so a long body (MTi channels + config + ambient) stays reachable on a
|
|
|
|
|
// short terminal instead of being silently cut off, as the camera view does.
|
|
|
|
|
return window(text(" SENSORS (i/Esc:close r:refresh config) ") | bold | color(Color::Magenta),
|
|
|
|
|
// Scrolled so a long body (MTi channels + config + ambient) stays reachable on
|
|
|
|
|
// a short terminal instead of being silently cut off.
|
|
|
|
|
return window(overlayTitle("SENSORS", "i/Esc:close r:refresh config", st, Color::Magenta),
|
|
|
|
|
vbox({hbox({imu_status, text(" "), env_status, filler()}), separator(),
|
|
|
|
|
vbox(std::move(body)) | yframe | flex}));
|
|
|
|
|
scrollableBody(vbox(std::move(body)), st) | flex}));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
} // namespace
|
|
|
|
|
@ -777,7 +881,10 @@ void TuiUi::stop() {
|
|
|
|
|
void TuiUi::pushLog(LogLevel level, const std::string& line) {
|
|
|
|
|
std::lock_guard<std::mutex> lock(log_mutex_);
|
|
|
|
|
log_.push_back({level, line});
|
|
|
|
|
while (log_.size() > kLogCap) log_.pop_front();
|
|
|
|
|
while (log_.size() > kLogCap) {
|
|
|
|
|
log_.pop_front();
|
|
|
|
|
++log_dropped_;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void TuiUi::refreshLoop() {
|
|
|
|
|
@ -807,13 +914,30 @@ void TuiUi::uiLoop() {
|
|
|
|
|
bool gimbal_dump_requested = false; // auto-pull a dump the first time
|
|
|
|
|
bool calib_prompt = false; // a yes/no calib-save question is showing
|
|
|
|
|
|
|
|
|
|
// Per-pane scroll positions. UI-thread-only view state (the renderer lambda
|
|
|
|
|
// and CatchEvent below both run on this thread), so unlike screen_/paused_
|
|
|
|
|
// these need no synchronisation and stay locals rather than TuiUi members.
|
|
|
|
|
ScrollState cam_scroll, sensors_scroll, help_scroll, log_scroll;
|
|
|
|
|
std::array<ScrollState, 2> gimbal_scroll{}; // YAW, PITCH
|
|
|
|
|
log_scroll.follow = true; // the log tracks the tail until told otherwise
|
|
|
|
|
size_t log_dropped_at_freeze = 0; // buffer evictions when scrollback was entered
|
|
|
|
|
|
|
|
|
|
auto input = Input(&cmd_buffer, "type a command, Enter to run, Esc to cancel");
|
|
|
|
|
|
|
|
|
|
auto renderer = Renderer(input, [&] {
|
|
|
|
|
UiSnapshot s = snapshot_ ? snapshot_() : UiSnapshot{};
|
|
|
|
|
size_t log_dropped_now = 0;
|
|
|
|
|
{
|
|
|
|
|
std::lock_guard<std::mutex> lock(log_mutex_);
|
|
|
|
|
s.log.assign(log_.begin(), log_.end());
|
|
|
|
|
log_dropped_now = log_dropped_;
|
|
|
|
|
}
|
|
|
|
|
// Evicting from the front of the ring buffer slides every line up under a
|
|
|
|
|
// frozen viewport, so a busy log would drag the view the operator parked.
|
|
|
|
|
// Absorb the shift; the clamp in scrollableBody handles running off the top.
|
|
|
|
|
if (!log_scroll.follow && log_dropped_now != log_dropped_at_freeze) {
|
|
|
|
|
log_scroll.top -= static_cast<int>(log_dropped_now - log_dropped_at_freeze);
|
|
|
|
|
log_dropped_at_freeze = log_dropped_now;
|
|
|
|
|
}
|
|
|
|
|
calib_prompt = !s.activity.prompt.empty();
|
|
|
|
|
gimbal_overlay_open_.store(overlay == Overlay::Gimbal); // refreshLoop polls a dump while open
|
|
|
|
|
@ -833,9 +957,20 @@ void TuiUi::uiLoop() {
|
|
|
|
|
Element top = hbox({gimbalPanel(s.gimbal), sensorsPanel(s.sensors)});
|
|
|
|
|
Element middle = hbox({cameraPanel(s.capture), connPanel(s.conn)});
|
|
|
|
|
|
|
|
|
|
const char* kArrowsV = "\xE2\x86\x91\xE2\x86\x93";
|
|
|
|
|
Element bottom;
|
|
|
|
|
if (command_mode) {
|
|
|
|
|
bottom = hbox({text(" : ") | inverted, input->Render() | flex}) | border;
|
|
|
|
|
} else if (overlay != Overlay::None) {
|
|
|
|
|
// The nudge arrows are inert while an overlay owns the body, so the bar
|
|
|
|
|
// advertises what the keys actually do here instead.
|
|
|
|
|
bottom = hbox({
|
|
|
|
|
(overlay == Overlay::Help ? keyHint(kArrowsV, "Section")
|
|
|
|
|
: keyHint(kArrowsV, "Scroll")),
|
|
|
|
|
keyHint("PgUp/Dn", "Page"), keyHint("Home/End", "Ends"),
|
|
|
|
|
keyHint("p", "Pause"), keyHint(":", "Cmd"), filler(),
|
|
|
|
|
keyHint("Esc", "Close"), keyHint("q", "Quit"),
|
|
|
|
|
});
|
|
|
|
|
} else {
|
|
|
|
|
bottom = hbox({
|
|
|
|
|
keyHint("s", "Start"), keyHint("x", "Stop"), keyHint("h", "Home"),
|
|
|
|
|
@ -851,20 +986,22 @@ void TuiUi::uiLoop() {
|
|
|
|
|
// gimbal register dump overflows the small log-sized area and clips.
|
|
|
|
|
switch (overlay) {
|
|
|
|
|
case Overlay::Help:
|
|
|
|
|
return vbox({header, separator(), helpPanel(help_sel, s.dump) | flex, bottom});
|
|
|
|
|
return vbox({header, separator(), helpPanel(help_sel, s.dump, help_scroll) | flex, bottom});
|
|
|
|
|
case Overlay::Gimbal:
|
|
|
|
|
return vbox({header, separator(),
|
|
|
|
|
gimbalDetailPanel(s.gimbal, s.dump, s.calib, s.diag) | flex, bottom});
|
|
|
|
|
gimbalDetailPanel(s.gimbal, s.dump, s.calib, s.diag, gimbal_scroll) |
|
|
|
|
|
flex,
|
|
|
|
|
bottom});
|
|
|
|
|
case Overlay::Sensors:
|
|
|
|
|
return vbox({header, separator(),
|
|
|
|
|
sensorsDetailPanel(s.imu, s.env) | flex, bottom});
|
|
|
|
|
sensorsDetailPanel(s.imu, s.env, sensors_scroll) | flex, bottom});
|
|
|
|
|
case Overlay::Cameras:
|
|
|
|
|
return vbox({header, separator(), cameraDetailPanel(s.capture) | flex, bottom});
|
|
|
|
|
return vbox({header, separator(), cameraDetailPanel(s.capture, cam_scroll) | flex, bottom});
|
|
|
|
|
default: {
|
|
|
|
|
// Activity strip sits between the log and the key bar; shown only
|
|
|
|
|
// once a special op has run or is running, else it costs no space.
|
|
|
|
|
std::vector<Element> col = {header, separator(), top, middle,
|
|
|
|
|
logPanel(s.log) | flex};
|
|
|
|
|
logPanel(s.log, log_scroll) | flex};
|
|
|
|
|
if (s.activity.active || s.activity.has_result || !s.activity.prompt.empty())
|
|
|
|
|
col.push_back(activityPanel(s.activity));
|
|
|
|
|
col.push_back(bottom);
|
|
|
|
|
@ -873,6 +1010,24 @@ void TuiUi::uiLoop() {
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
// Apply a scroll key to one pane. `arrows` is false where Up/Down already mean
|
|
|
|
|
// something else (help section nav; gimbal nudge on the dashboard), leaving
|
|
|
|
|
// PgUp/PgDn/Home/End as the only scroll keys there.
|
|
|
|
|
auto scrollKeys = [](ScrollState& st, const Event& e, bool arrows) {
|
|
|
|
|
const int ch = st.contentH(), vh = st.viewH();
|
|
|
|
|
if (arrows && (e == Event::ArrowDown)) { st.top = scrollBy(st.top, 1, ch, vh); return true; }
|
|
|
|
|
if (arrows && (e == Event::ArrowUp)) { st.top = scrollBy(st.top, -1, ch, vh); return true; }
|
|
|
|
|
if (e == Event::PageDown) { st.top = scrollPage(st.top, 1, ch, vh); return true; }
|
|
|
|
|
if (e == Event::PageUp) { st.top = scrollPage(st.top, -1, ch, vh); return true; }
|
|
|
|
|
if (e == Event::Home) { st.top = 0; return true; }
|
|
|
|
|
if (e == Event::End) { st.top = scrollMax(ch, vh); return true; }
|
|
|
|
|
if (arrows && e.is_character()) {
|
|
|
|
|
if (e.character() == "j") { st.top = scrollBy(st.top, 1, ch, vh); return true; }
|
|
|
|
|
if (e.character() == "k") { st.top = scrollBy(st.top, -1, ch, vh); return true; }
|
|
|
|
|
}
|
|
|
|
|
return false;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
auto root = CatchEvent(renderer, [&](Event e) {
|
|
|
|
|
if (command_mode) {
|
|
|
|
|
if (e == Event::Return) {
|
|
|
|
|
@ -890,14 +1045,61 @@ void TuiUi::uiLoop() {
|
|
|
|
|
}
|
|
|
|
|
const int n = static_cast<int>(helpCatalog().size());
|
|
|
|
|
if (overlay == Overlay::Help) { // help pane navigation
|
|
|
|
|
if (e == Event::ArrowDown) { help_sel = (help_sel + 1) % n; return true; }
|
|
|
|
|
if (e == Event::ArrowUp) { help_sel = (help_sel - 1 + n) % n; return true; }
|
|
|
|
|
// Selecting a different section replaces the body wholesale, so the
|
|
|
|
|
// old scroll position would be meaningless - start at the top.
|
|
|
|
|
if (e == Event::ArrowDown) { help_sel = (help_sel + 1) % n; help_scroll = {}; return true; }
|
|
|
|
|
if (e == Event::ArrowUp) { help_sel = (help_sel - 1 + n) % n; help_scroll = {}; return true; }
|
|
|
|
|
}
|
|
|
|
|
// Scroll the overlay that owns the body. Arrows are free here except in
|
|
|
|
|
// Help, where the two cases above already claimed them for section nav.
|
|
|
|
|
if (overlay != Overlay::None) {
|
|
|
|
|
const bool arrows = (overlay != Overlay::Help);
|
|
|
|
|
switch (overlay) {
|
|
|
|
|
case Overlay::Cameras:
|
|
|
|
|
if (scrollKeys(cam_scroll, e, arrows)) return true;
|
|
|
|
|
break;
|
|
|
|
|
case Overlay::Sensors:
|
|
|
|
|
if (scrollKeys(sensors_scroll, e, arrows)) return true;
|
|
|
|
|
break;
|
|
|
|
|
case Overlay::Help:
|
|
|
|
|
if (scrollKeys(help_scroll, e, arrows)) return true;
|
|
|
|
|
break;
|
|
|
|
|
case Overlay::Gimbal: {
|
|
|
|
|
// Both axis columns move together: they are read side by side,
|
|
|
|
|
// and each clamps against its own measured height.
|
|
|
|
|
const bool a = scrollKeys(gimbal_scroll[0], e, arrows);
|
|
|
|
|
const bool b = scrollKeys(gimbal_scroll[1], e, arrows);
|
|
|
|
|
if (a || b) return true;
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
case Overlay::None: break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
if (overlay != Overlay::None && e == Event::Escape) { overlay = Overlay::None; return true; }
|
|
|
|
|
// Esc with no overlay open cancels a running procedure (test/calib/homing).
|
|
|
|
|
if (overlay == Overlay::None && e == Event::Escape && sink_) {
|
|
|
|
|
if (snapshot_ && snapshot_().activity.cancelable) { sink_("cancel"); return true; }
|
|
|
|
|
}
|
|
|
|
|
// Log scrollback. The arrows belong to the gimbal here, so this is
|
|
|
|
|
// PgUp/PgDn/Home/End only; End resumes following the tail.
|
|
|
|
|
if (overlay == Overlay::None) {
|
|
|
|
|
if (e == Event::End) {
|
|
|
|
|
log_scroll.follow = true;
|
|
|
|
|
log_scroll.top = scrollMax(log_scroll.contentH(), log_scroll.viewH());
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
if (e == Event::PageUp || e == Event::PageDown || e == Event::Home) {
|
|
|
|
|
if (log_scroll.follow) {
|
|
|
|
|
// Entering scrollback: freeze where the tail currently sits, and
|
|
|
|
|
// start tracking evictions from this point.
|
|
|
|
|
log_scroll.follow = false;
|
|
|
|
|
log_scroll.top = scrollMax(log_scroll.contentH(), log_scroll.viewH());
|
|
|
|
|
std::lock_guard<std::mutex> lock(log_mutex_);
|
|
|
|
|
log_dropped_at_freeze = log_dropped_;
|
|
|
|
|
}
|
|
|
|
|
return scrollKeys(log_scroll, e, /*arrows=*/false);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
// Arrow keys nudge the gimbal in steps (only when no overlay is open):
|
|
|
|
|
// Left/Right = yaw -/+5%, Up/Down = pitch -/+10% of travel.
|
|
|
|
|
if (overlay == Overlay::None && sink_) {
|
|
|
|
|
@ -915,6 +1117,7 @@ void TuiUi::uiLoop() {
|
|
|
|
|
}
|
|
|
|
|
if (c == "?") {
|
|
|
|
|
overlay = (overlay == Overlay::Help) ? Overlay::None : Overlay::Help;
|
|
|
|
|
if (overlay == Overlay::Help) help_scroll = {};
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
if (c == "g") {
|
|
|
|
|
@ -922,6 +1125,7 @@ void TuiUi::uiLoop() {
|
|
|
|
|
overlay = Overlay::None;
|
|
|
|
|
} else {
|
|
|
|
|
overlay = Overlay::Gimbal;
|
|
|
|
|
gimbal_scroll = {};
|
|
|
|
|
if (!gimbal_dump_requested) { // auto-pull a dump the first time
|
|
|
|
|
if (sink_) sink_("gimbal dump");
|
|
|
|
|
gimbal_dump_requested = true;
|
|
|
|
|
@ -935,10 +1139,12 @@ void TuiUi::uiLoop() {
|
|
|
|
|
}
|
|
|
|
|
if (c == "i") {
|
|
|
|
|
overlay = (overlay == Overlay::Sensors) ? Overlay::None : Overlay::Sensors;
|
|
|
|
|
if (overlay == Overlay::Sensors) sensors_scroll = {};
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
if (c == "c") {
|
|
|
|
|
overlay = (overlay == Overlay::Cameras) ? Overlay::None : Overlay::Cameras;
|
|
|
|
|
if (overlay == Overlay::Cameras) cam_scroll = {};
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
if (c == "p") { // freeze/unfreeze the live refresh so text can be selected
|
|
|
|
|
@ -946,8 +1152,8 @@ void TuiUi::uiLoop() {
|
|
|
|
|
return true; // this keypress redraws once so the indicator updates
|
|
|
|
|
}
|
|
|
|
|
if (overlay == Overlay::Help) { // vim-style section nav while help is open
|
|
|
|
|
if (c == "j") { help_sel = (help_sel + 1) % n; return true; }
|
|
|
|
|
if (c == "k") { help_sel = (help_sel - 1 + n) % n; return true; }
|
|
|
|
|
if (c == "j") { help_sel = (help_sel + 1) % n; help_scroll = {}; return true; }
|
|
|
|
|
if (c == "k") { help_sel = (help_sel - 1 + n) % n; help_scroll = {}; return true; }
|
|
|
|
|
}
|
|
|
|
|
if (c == "q") { if (sink_) sink_("exit"); return true; }
|
|
|
|
|
if (c == "s") { if (sink_) sink_("start"); return true; }
|
|
|
|
|
|