mirror of
https://github.com/ArthurSonzogni/FTXUI.git
synced 2025-05-07 18:41:12 +08:00
Update example package_manager.
This commit is contained in:
parent
961e3dcb50
commit
6bf7acbd54
@ -21,24 +21,23 @@ int main(int argc, const char *argv[])
|
|||||||
};
|
};
|
||||||
|
|
||||||
std::list<Task> remaining_tasks = {
|
std::list<Task> remaining_tasks = {
|
||||||
{L"contact server " , 10 , 0 , 6*25} ,
|
{L"contact server ", 10, 0, 6 * 25},
|
||||||
{L"download index.html " , 10 , 0 , 9*25} ,
|
{L"download index.html ", 10, 0, 9 * 25},
|
||||||
{L"download script.js " , 1 , 0 , 3*25} ,
|
{L"download script.js ", 1, 0, 3 * 25},
|
||||||
{L"download style.js " , 1 , 0 , 4*25} ,
|
{L"download style.js ", 1, 0, 4 * 25},
|
||||||
{L"download image.png " , 1 , 0 , 5*25} ,
|
{L"download image.png ", 1, 0, 5 * 25},
|
||||||
{L"download big_1.png " , 1 , 0 , 30*25} ,
|
{L"download big_1.png ", 1, 0, 30 * 25},
|
||||||
{L"download icon_1.png " , 1 , 0 , 7*25} ,
|
{L"download icon_1.png ", 1, 0, 7 * 25},
|
||||||
{L"download icon_2.png " , 1 , 0 , 8*25} ,
|
{L"download icon_2.png ", 1, 0, 8 * 25},
|
||||||
{L"download big_2.png " , 1 , 0 , 30*25} ,
|
{L"download big_2.png ", 1, 0, 30 * 25},
|
||||||
{L"download small_1.png " , 1 , 0 , 10*25} ,
|
{L"download small_1.png ", 1, 0, 10 * 25},
|
||||||
{L"download small_2.png " , 1 , 0 , 11*25} ,
|
{L"download small_2.png ", 1, 0, 11 * 25},
|
||||||
{L"download small_3.png " , 1 , 0 , 12*25} ,
|
{L"download small_3.png ", 1, 0, 12 * 25},
|
||||||
};
|
};
|
||||||
|
|
||||||
std::list<Task> displayed_task;
|
std::list<Task> displayed_task;
|
||||||
|
|
||||||
int remaining_threads = 12;
|
int remaining_threads = 12;
|
||||||
std::string reset_position;
|
|
||||||
|
|
||||||
int nb_queued = remaining_tasks.size();
|
int nb_queued = remaining_tasks.size();
|
||||||
int nb_active = 0;
|
int nb_active = 0;
|
||||||
@ -51,11 +50,9 @@ int main(int argc, const char *argv[])
|
|||||||
return text(t);
|
return text(t);
|
||||||
};
|
};
|
||||||
|
|
||||||
for(;;) {
|
auto renderTask = [&](const Task& task) {
|
||||||
std::vector<Element> entries;
|
|
||||||
for(auto& task : displayed_task) {
|
|
||||||
auto style = (task.downloaded == task.size) ? dim : bold;
|
auto style = (task.downloaded == task.size) ? dim : bold;
|
||||||
entries.push_back(
|
return
|
||||||
hbox(
|
hbox(
|
||||||
text(task.name) | style,
|
text(task.name) | style,
|
||||||
separator(),
|
separator(),
|
||||||
@ -64,41 +61,38 @@ int main(int argc, const char *argv[])
|
|||||||
to_text(task.size),
|
to_text(task.size),
|
||||||
separator(),
|
separator(),
|
||||||
gauge(task.downloaded / float(task.size))
|
gauge(task.downloaded / float(task.size))
|
||||||
)
|
|
||||||
);
|
);
|
||||||
}
|
};
|
||||||
|
|
||||||
auto document =
|
auto renderSummary = [&]() {
|
||||||
vbox(
|
return
|
||||||
window(text(L" Task "),
|
|
||||||
vbox(std::move(entries))
|
|
||||||
),
|
|
||||||
hbox(
|
|
||||||
window(text(L" Summary "),
|
window(text(L" Summary "),
|
||||||
vbox(
|
vbox(
|
||||||
hbox(text(L"- done: "), to_text(nb_done) | bold) | color(Color::Green),
|
hbox(text(L"- done: "), to_text(nb_done) | bold) | color(Color::Green),
|
||||||
hbox(text(L"- active: "), to_text(nb_active) | bold ) | color(Color::RedLight),
|
hbox(text(L"- active: "), to_text(nb_active) | bold ) | color(Color::RedLight),
|
||||||
hbox(text(L"- queue: "), to_text(nb_queued) | bold) | color(Color::Red)
|
hbox(text(L"- queue: "), to_text(nb_queued) | bold) | color(Color::Red)
|
||||||
)
|
)
|
||||||
)
|
|
||||||
)
|
|
||||||
);
|
);
|
||||||
|
};
|
||||||
|
|
||||||
// Draw.
|
auto render = [&](){
|
||||||
//if (step != 0) screen.Clear();
|
std::vector<Element> entries;
|
||||||
auto screen = ftxui::Screen::TerminalOutput(document);
|
for(auto& task : displayed_task)
|
||||||
Render(screen, document.get());
|
entries.push_back(renderTask(task));
|
||||||
std::cout << reset_position << screen.ToString() << std::flush;
|
|
||||||
reset_position = screen.ResetPosition();
|
|
||||||
|
|
||||||
// Simulate time.
|
return
|
||||||
using namespace std::chrono_literals;
|
vbox(
|
||||||
std::this_thread::sleep_for(0.01s);
|
// List of tasks.
|
||||||
|
window(text(L" Task "),
|
||||||
|
vbox(std::move(entries))
|
||||||
|
),
|
||||||
|
|
||||||
if (nb_active + nb_queued == 0)
|
// Summary.
|
||||||
break;
|
hbox(renderSummary(), filler())
|
||||||
|
);
|
||||||
|
};
|
||||||
|
|
||||||
// Update the model.
|
auto updateModel = [&](){
|
||||||
for(auto& task : displayed_task) {
|
for(auto& task : displayed_task) {
|
||||||
if (task.downloaded != task.size) {
|
if (task.downloaded != task.size) {
|
||||||
task.downloaded++;
|
task.downloaded++;
|
||||||
@ -118,6 +112,28 @@ int main(int argc, const char *argv[])
|
|||||||
nb_queued--;
|
nb_queued--;
|
||||||
nb_active++;
|
nb_active++;
|
||||||
}
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
std::string reset_position;
|
||||||
|
for(;;) {
|
||||||
|
|
||||||
|
// Draw.
|
||||||
|
auto document = render();
|
||||||
|
auto screen = ftxui::Screen::TerminalOutput(document);
|
||||||
|
Render(screen, document.get());
|
||||||
|
std::cout << reset_position << screen.ToString() << std::flush;
|
||||||
|
reset_position = screen.ResetPosition();
|
||||||
|
|
||||||
|
// Simulate time.
|
||||||
|
using namespace std::chrono_literals;
|
||||||
|
std::this_thread::sleep_for(0.01s);
|
||||||
|
|
||||||
|
// Exit
|
||||||
|
if (nb_active + nb_queued == 0)
|
||||||
|
break;
|
||||||
|
|
||||||
|
// Update the model for the next frame.
|
||||||
|
updateModel();
|
||||||
}
|
}
|
||||||
std::cout << std::endl;
|
std::cout << std::endl;
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user