|
|
|
// Copyright 2020 Arthur Sonzogni. All rights reserved.
|
|
|
|
// Use of this source code is governed by the MIT license that can be found in
|
|
|
|
// the LICENSE file.
|
|
|
|
#include <chrono> // for operator""s, chrono_literals
|
|
|
|
#include <ftxui/screen/screen.hpp> // for Full, Screen
|
|
|
|
#include <iostream> // for cout, ostream
|
|
|
|
#include <memory> // for allocator, shared_ptr
|
|
|
|
#include <string> // for string, operator<<
|
|
|
|
#include <thread> // for sleep_for
|
|
|
|
|
|
|
|
#include <ftxui/dom/elements.hpp> // for hflow, paragraph, separator, hbox, vbox, filler, operator|, border, Element
|
|
|
|
#include <ftxui/dom/node.hpp> // for Render
|
|
|
|
#include <ftxui/screen/box.hpp> // for ftxui
|
|
|
|
#include <ftxui/component/component.hpp>
|
|
|
|
|
|
|
|
using namespace std::chrono_literals;
|
|
|
|
|
|
|
|
std::array<std::string, 6> tiles = {
|
|
|
|
"##########",
|
|
|
|
"# #",
|
|
|
|
"# #",
|
|
|
|
"# |",
|
|
|
|
"# #",
|
|
|
|
"##########",
|
|
|
|
};
|
|
|
|
|
|
|
|
int main() {
|
|
|
|
using namespace ftxui;
|
|
|
|
std::string reset_position;
|
|
|
|
|
|
|
|
auto c = Canvas(100, 100);
|
|
|
|
|
|
|
|
// A triangle following the mouse, using braille characters.
|
|
|
|
auto map = Renderer([&] {
|
|
|
|
for(size_t i = 0; i < tiles.size(); ++i) {
|
|
|
|
c.DrawText(50, 50+i*4, tiles[i]);
|
|
|
|
}
|
|
|
|
|
|
|
|
for(size_t i = 0; i < tiles[0].size() - 2; i++) {
|
|
|
|
for(size_t j = 0; j < tiles.size() - 2; j++) {
|
|
|
|
c.DrawText(52+i*2, 54+j*4, ".", Color::Yellow);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
c.DrawText(50+3*4, 50+3*4, "@", Color::Blue);
|
|
|
|
|
|
|
|
return canvas(c);
|
|
|
|
});
|
|
|
|
|
|
|
|
while (true) {
|
|
|
|
auto document = hbox({
|
|
|
|
hflow(
|
|
|
|
vbox(
|
|
|
|
gauge(0.5) | border,
|
|
|
|
text("STATUS") | border
|
|
|
|
) | xflex_grow
|
|
|
|
),
|
|
|
|
separator(),
|
|
|
|
hflow(map->Render()),
|
|
|
|
}) | border;
|
|
|
|
|
|
|
|
auto screen = Screen::Create(Dimension::Full());
|
|
|
|
Render(screen, document);
|
|
|
|
|
|
|
|
std::cout << reset_position;
|
|
|
|
screen.Print();
|
|
|
|
reset_position = screen.ResetPosition();
|
|
|
|
|
|
|
|
std::this_thread::sleep_for(0.01s);
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|