tui: port framework core (style, theme, input, VT screen, compositor, panel, widgets, app, demo); demo frame byte-identical to tai.py
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -0,0 +1,44 @@
|
||||
// tui_shot: headless frames of the demo scene from the C++ port, to diff against python.
|
||||
// tui_shot [rows cols] plain text, same as tai.py --demo-shot
|
||||
// tui_shot frame [rows cols] the raw bytes of the first frame (TuiApp.frame_bytes)
|
||||
// tui_shot cells [rows cols] one line per cell: y x codepoint sgr (compose, no diff)
|
||||
#include "TuiDemo.h"
|
||||
#include <cstdio>
|
||||
#include <cstdlib>
|
||||
#include <iostream>
|
||||
#include <string>
|
||||
using namespace detz::tui;
|
||||
|
||||
int main(int argc, char** argv) {
|
||||
std::string mode = "text";
|
||||
int arg = 1;
|
||||
if (argc > 1 && (std::string(argv[1]) == "frame" || std::string(argv[1]) == "cells")) {
|
||||
mode = argv[1];
|
||||
arg = 2;
|
||||
}
|
||||
int rows = argc > arg ? std::atoi(argv[arg]) : 30;
|
||||
int cols = argc > arg + 1 ? std::atoi(argv[arg + 1]) : 100;
|
||||
if (mode == "text") return TuiDemo::demo_shot(std::cout, rows, cols);
|
||||
TuiApp app;
|
||||
app.rows = rows;
|
||||
app.cols = cols;
|
||||
auto built = TuiDemo::build(app, false);
|
||||
app.mount(built.first);
|
||||
app.close_panel(built.first->find("welcome"));
|
||||
built.second->shell->screen.feed("$ echo hello\r\nhello\r\n$ ");
|
||||
built.second->stream->screen.feed("stream tick 1\r\nstream tick 2\r\nstream tick 3\r\n");
|
||||
if (mode == "frame") {
|
||||
std::string bytes = app.frame_bytes();
|
||||
std::fwrite(bytes.data(), 1, bytes.size(), stdout);
|
||||
return 0;
|
||||
}
|
||||
app.render_text(); // forces layout
|
||||
TuiCellRows frame = app.compositor.compose(app.root.get(), rows, cols);
|
||||
for (size_t y = 0; y < frame.size(); y++) {
|
||||
for (size_t x = 0; x < frame[y].size(); x++) {
|
||||
std::printf("%zu %zu %u %s\n", y, x, static_cast<unsigned>(frame[y][x].ch),
|
||||
app.compositor.sgr(frame[y][x].key).substr(1).c_str());
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
Reference in New Issue
Block a user