This commit is contained in:
parent
f246138083
commit
00e5347d55
2 changed files with 79 additions and 23 deletions
|
|
@ -8,7 +8,7 @@ on:
|
||||||
|
|
||||||
jobs:
|
jobs:
|
||||||
build:
|
build:
|
||||||
runs-on: [docker]
|
runs-on: [host-amd]
|
||||||
env:
|
env:
|
||||||
BRANCH: ${{ github.ref_name }}
|
BRANCH: ${{ github.ref_name }}
|
||||||
COMMIT: ${{ github.sha }}
|
COMMIT: ${{ github.sha }}
|
||||||
|
|
|
||||||
100
main.cpp
100
main.cpp
|
|
@ -9,6 +9,7 @@
|
||||||
#include <memory>
|
#include <memory>
|
||||||
#include <sstream>
|
#include <sstream>
|
||||||
#include <string>
|
#include <string>
|
||||||
|
#include <thread>
|
||||||
#include <utility>
|
#include <utility>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
|
|
||||||
|
|
@ -358,6 +359,7 @@ private:
|
||||||
"Spin Up MySQL Container",
|
"Spin Up MySQL Container",
|
||||||
"Get Container IP Address",
|
"Get Container IP Address",
|
||||||
"Create Dockerfile & Build Image from Bash Script",
|
"Create Dockerfile & Build Image from Bash Script",
|
||||||
|
"About Tux-Dock",
|
||||||
"Exit",
|
"Exit",
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
@ -419,6 +421,7 @@ private:
|
||||||
void ActionSpinUpMySQL();
|
void ActionSpinUpMySQL();
|
||||||
void ActionShowContainerIP();
|
void ActionShowContainerIP();
|
||||||
void ActionCreateDockerfile();
|
void ActionCreateDockerfile();
|
||||||
|
void ActionAbout();
|
||||||
void PromptPortCountAndRun(const std::shared_ptr<RunContainerContext>& context);
|
void PromptPortCountAndRun(const std::shared_ptr<RunContainerContext>& context);
|
||||||
void PromptNextPort(const std::shared_ptr<RunContainerContext>& context, int index);
|
void PromptNextPort(const std::shared_ptr<RunContainerContext>& context, int index);
|
||||||
|
|
||||||
|
|
@ -426,6 +429,8 @@ private:
|
||||||
std::function<void(const std::string& id, const std::string& name)> callback);
|
std::function<void(const std::string& id, const std::string& name)> callback);
|
||||||
void PromptImageSelection(const std::string& title,
|
void PromptImageSelection(const std::string& title,
|
||||||
std::function<void(const std::string& id, const std::string& tag)> callback);
|
std::function<void(const std::string& id, const std::string& tag)> callback);
|
||||||
|
void RunDeferredStatusAction(const std::string& wait_message,
|
||||||
|
std::function<std::string()> action);
|
||||||
static void ClearTerminal();
|
static void ClearTerminal();
|
||||||
void RunWithRestoredIO(const std::function<void()>& action,
|
void RunWithRestoredIO(const std::function<void()>& action,
|
||||||
bool clear_before = false,
|
bool clear_before = false,
|
||||||
|
|
@ -684,6 +689,28 @@ void TuxDockApp::RunWithRestoredIO(const std::function<void()>& action,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void TuxDockApp::RunDeferredStatusAction(const std::string& wait_message,
|
||||||
|
std::function<std::string()> action) {
|
||||||
|
SetStatus(wait_message);
|
||||||
|
|
||||||
|
if (screen_ == nullptr) {
|
||||||
|
SetStatus(action());
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
ftxui::ScreenInteractive* active_screen = screen_;
|
||||||
|
active_screen->PostEvent(ftxui::Event::Custom);
|
||||||
|
|
||||||
|
std::thread([this, active_screen, action = std::move(action)]() mutable {
|
||||||
|
const std::string final_message = action();
|
||||||
|
if (ftxui::ScreenInteractive::Active() != active_screen) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
active_screen->Post([this, final_message] { SetStatus(final_message); });
|
||||||
|
active_screen->PostEvent(ftxui::Event::Custom);
|
||||||
|
}).detach();
|
||||||
|
}
|
||||||
|
|
||||||
void TuxDockApp::ActionPullImage() {
|
void TuxDockApp::ActionPullImage() {
|
||||||
const std::vector<std::string> quick_images = {
|
const std::vector<std::string> quick_images = {
|
||||||
"debian:stable",
|
"debian:stable",
|
||||||
|
|
@ -710,12 +737,12 @@ void TuxDockApp::ActionPullImage() {
|
||||||
}
|
}
|
||||||
|
|
||||||
if (selected < static_cast<int>(quick_images.size())) {
|
if (selected < static_cast<int>(quick_images.size())) {
|
||||||
std::string message;
|
const std::string image = quick_images[static_cast<std::size_t>(selected)];
|
||||||
SetStatus("Pulling image...");
|
RunDeferredStatusAction("Please wait, pulling image...", [this, image] {
|
||||||
RunWithRestoredIO([this, &message, &quick_images, selected] {
|
std::string message;
|
||||||
docker_.pullImage(quick_images[static_cast<std::size_t>(selected)], message);
|
docker_.pullImage(image, message);
|
||||||
|
return message;
|
||||||
});
|
});
|
||||||
SetStatus(message);
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -731,10 +758,11 @@ void TuxDockApp::ActionPullImage() {
|
||||||
ActionPullImage();
|
ActionPullImage();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
std::string message;
|
RunDeferredStatusAction("Please wait, pulling image...", [this, image] {
|
||||||
SetStatus("Pulling image...");
|
std::string message;
|
||||||
RunWithRestoredIO([this, &message, &image] { docker_.pullImage(image, message); });
|
docker_.pullImage(image, message);
|
||||||
SetStatus(message);
|
return message;
|
||||||
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
@ -889,20 +917,22 @@ void TuxDockApp::ActionDeleteImage() {
|
||||||
SetStatus("Image deletion cancelled.");
|
SetStatus("Image deletion cancelled.");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
std::string message;
|
RunDeferredStatusAction("Please wait, deleting image...", [this, id] {
|
||||||
SetStatus("Deleting image...");
|
std::string message;
|
||||||
RunWithRestoredIO([this, &id, &message] { docker_.deleteImage(id, message); });
|
docker_.deleteImage(id, message);
|
||||||
SetStatus(message);
|
return message;
|
||||||
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
void TuxDockApp::ActionStopContainer() {
|
void TuxDockApp::ActionStopContainer() {
|
||||||
PromptContainerSelection("Stop Container", [this](const std::string& id, const std::string&) {
|
PromptContainerSelection("Stop Container", [this](const std::string& id, const std::string&) {
|
||||||
std::string message;
|
RunDeferredStatusAction("Please wait, stopping container...", [this, id] {
|
||||||
SetStatus("Stopping container...");
|
std::string message;
|
||||||
RunWithRestoredIO([this, &id, &message] { docker_.stopContainer(id, message); });
|
docker_.stopContainer(id, message);
|
||||||
SetStatus(message);
|
return message;
|
||||||
|
});
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -915,10 +945,11 @@ void TuxDockApp::ActionRemoveContainer() {
|
||||||
SetStatus("Container removal cancelled.");
|
SetStatus("Container removal cancelled.");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
std::string message;
|
RunDeferredStatusAction("Please wait, removing container...", [this, id] {
|
||||||
SetStatus("Removing container...");
|
std::string message;
|
||||||
RunWithRestoredIO([this, &id, &message] { docker_.removeContainer(id, message); });
|
docker_.removeContainer(id, message);
|
||||||
SetStatus(message);
|
return message;
|
||||||
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
@ -1082,6 +1113,15 @@ void TuxDockApp::ActionCreateDockerfile() {
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void TuxDockApp::ActionAbout() {
|
||||||
|
SetStatus("Tux-Dock 022526-dev\n"
|
||||||
|
"Created by markmental\n\n"
|
||||||
|
"GitHub:\n"
|
||||||
|
"https://github.com/MARKMENTAL/tuxdock\n\n"
|
||||||
|
"Forgejo:\n"
|
||||||
|
"https://mentalnet.xyz/forgejo/markmental/tuxdock");
|
||||||
|
}
|
||||||
|
|
||||||
void TuxDockApp::ExecuteSelectedAction() {
|
void TuxDockApp::ExecuteSelectedAction() {
|
||||||
switch (menu_selected_) {
|
switch (menu_selected_) {
|
||||||
case 0:
|
case 0:
|
||||||
|
|
@ -1127,6 +1167,9 @@ void TuxDockApp::ExecuteSelectedAction() {
|
||||||
ActionCreateDockerfile();
|
ActionCreateDockerfile();
|
||||||
break;
|
break;
|
||||||
case 14:
|
case 14:
|
||||||
|
ActionAbout();
|
||||||
|
break;
|
||||||
|
case 15:
|
||||||
SetStatus("Exiting Tux-Dock.");
|
SetStatus("Exiting Tux-Dock.");
|
||||||
if (screen_ != nullptr) {
|
if (screen_ != nullptr) {
|
||||||
screen_->ExitLoopClosure()();
|
screen_->ExitLoopClosure()();
|
||||||
|
|
@ -1220,13 +1263,26 @@ ftxui::Element TuxDockApp::RenderModal() const {
|
||||||
ftxui::Element TuxDockApp::Render() const {
|
ftxui::Element TuxDockApp::Render() const {
|
||||||
using namespace ftxui;
|
using namespace ftxui;
|
||||||
|
|
||||||
|
Elements status_lines;
|
||||||
|
{
|
||||||
|
std::stringstream ss(status_);
|
||||||
|
std::string line;
|
||||||
|
while (std::getline(ss, line)) {
|
||||||
|
status_lines.push_back(line.empty() ? text(" ") : text(line));
|
||||||
|
}
|
||||||
|
if (status_lines.empty()) {
|
||||||
|
status_lines.push_back(text(" "));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
auto actions_panel = window(text("Actions"),
|
auto actions_panel = window(text("Actions"),
|
||||||
vbox(ftxui::Elements{menu_component_->Render() | frame | vscroll_indicator,
|
vbox(ftxui::Elements{menu_component_->Render() | frame | vscroll_indicator,
|
||||||
separator(),
|
separator(),
|
||||||
text("Up/Down: navigate Enter: select") | dim})) |
|
text("Up/Down: navigate Enter: select") | dim})) |
|
||||||
size(WIDTH, GREATER_THAN, 48) | flex;
|
size(WIDTH, GREATER_THAN, 48) | flex;
|
||||||
|
|
||||||
auto status_panel = window(text("Status"), vbox(ftxui::Elements{paragraph(status_) | yflex, separator(),
|
auto status_panel = window(text("Status"), vbox(ftxui::Elements{vbox(std::move(status_lines)) | yflex | frame | vscroll_indicator,
|
||||||
|
separator(),
|
||||||
text("High-level updates only") | dim})) |
|
text("High-level updates only") | dim})) |
|
||||||
size(WIDTH, GREATER_THAN, 48) | flex;
|
size(WIDTH, GREATER_THAN, 48) | flex;
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue