mirror of
https://github.com/CachyOS/New-Cli-Installer.git
synced 2025-01-23 14:32:22 +08:00
attempt for wrapped process log
This commit is contained in:
parent
83dbb33062
commit
00e43ff34e
@ -113,6 +113,13 @@ executable(
|
||||
include_directories: [include_directories('src')],
|
||||
install: false)
|
||||
|
||||
executable(
|
||||
'test-process-tailing',
|
||||
files('src/config.cpp', 'src/widgets.cpp', 'src/tui.cpp', 'src/utils.cpp', 'src/test_proccess_tailing.cpp'),
|
||||
dependencies: [fmt, spdlog, ftxui, cpr, glibmm],
|
||||
include_directories: [include_directories('src')],
|
||||
install: false)
|
||||
|
||||
summary(
|
||||
{
|
||||
'Build type': get_option('buildtype'),
|
||||
|
@ -1,8 +1,8 @@
|
||||
#include "config.hpp"
|
||||
#include "definitions.hpp"
|
||||
#include "definitions.hpp" // for error_inter
|
||||
|
||||
#include <filesystem>
|
||||
#include <memory>
|
||||
#include <filesystem> // for exists
|
||||
#include <memory> // for unique_ptr, make_unique, operator==
|
||||
|
||||
static std::unique_ptr<Config> s_config = nullptr;
|
||||
|
||||
|
@ -1,11 +1,12 @@
|
||||
#ifndef CONFIG_HPP
|
||||
#define CONFIG_HPP
|
||||
|
||||
#include <string>
|
||||
#include <string_view>
|
||||
#include <unordered_map>
|
||||
#include <variant>
|
||||
#include <vector>
|
||||
#include <cstdint> // for int32_t
|
||||
#include <string> // for string
|
||||
#include <string_view> // for string_view, hash
|
||||
#include <unordered_map> // for unordered_map
|
||||
#include <variant> // for variant
|
||||
#include <vector> // for vector
|
||||
|
||||
class Config final {
|
||||
public:
|
||||
|
17
src/main.cpp
17
src/main.cpp
@ -1,15 +1,16 @@
|
||||
#include "config.hpp"
|
||||
#include "definitions.hpp"
|
||||
#include "screen_service.hpp"
|
||||
#include "tui.hpp"
|
||||
#include "utils.hpp"
|
||||
#include "config.hpp" // for Config
|
||||
#include "definitions.hpp" // for error_inter
|
||||
#include "tui.hpp" // for init
|
||||
#include "utils.hpp" // for exec, check_root, clear_sc...
|
||||
|
||||
#include <chrono> // for seconds
|
||||
#include <regex> // for regex_search, match_results<>::_Base_type
|
||||
#include <regex> // for regex_search, match_result...
|
||||
#include <thread> // for sleep_for
|
||||
|
||||
#include <spdlog/async.h>
|
||||
#include <spdlog/sinks/basic_file_sink.h>
|
||||
#include <spdlog/async.h> // for create_async
|
||||
#include <spdlog/common.h> // for debug
|
||||
#include <spdlog/sinks/basic_file_sink.h> // for basic_file_sink_mt
|
||||
#include <spdlog/spdlog.h> // for set_default_logger, set_level
|
||||
|
||||
int main() {
|
||||
const auto& tty = utils::exec("tty");
|
||||
|
@ -2,11 +2,11 @@
|
||||
#ifndef SCREEN_SERVICE_HPP
|
||||
#define SCREEN_SERVICE_HPP
|
||||
|
||||
#include "view.hpp"
|
||||
//#include "view.hpp"
|
||||
|
||||
/* clang-format off */
|
||||
#include <memory>
|
||||
#include <ftxui/component/screen_interactive.hpp>
|
||||
//#include <memory>
|
||||
#include <ftxui/component/screen_interactive.hpp> // for ScreenInteractive
|
||||
/* clang-format on */
|
||||
|
||||
namespace tui {
|
||||
|
95
src/test_proccess_tailing.cpp
Normal file
95
src/test_proccess_tailing.cpp
Normal file
@ -0,0 +1,95 @@
|
||||
#include <cstdio>
|
||||
#include <thread>
|
||||
|
||||
#include <chrono> // for operator""s, chrono_literals
|
||||
#include <ftxui/component/component.hpp> // for Renderer, Button
|
||||
#include <ftxui/component/component_options.hpp> // for ButtonOption, Inpu...
|
||||
#include <ftxui/component/screen_interactive.hpp> // for ScreenInteractive
|
||||
#include <ftxui/dom/elements.hpp> // for operator|, text, Element, hbox, bold, color, filler, separator, vbox, window, gauge, Fit, size, dim, EQUAL, WIDTH
|
||||
#include <ftxui/screen/screen.hpp> // for Full, Screen
|
||||
#include <iostream> // for cout, endl, ostream
|
||||
#include <list> // for list, operator!=, _List_iterator, _List_iterator<>::_Self
|
||||
#include <memory> // for allocator, shared_ptr, allocator_traits<>::value_type
|
||||
#include <string> // for string, operator<<, to_string
|
||||
#include <thread> // for sleep_for
|
||||
#include <utility> // for move
|
||||
#include <vector> // for vector
|
||||
|
||||
#include <ftxui/component/captured_mouse.hpp>
|
||||
#include <ftxui/component/event.hpp>
|
||||
#include <ftxui/dom/node.hpp> // for Render
|
||||
#include <ftxui/screen/box.hpp> // for ftxui
|
||||
#include <ftxui/screen/color.hpp> // for Color, Color::Green, Color::Red, Color::RedLight
|
||||
|
||||
#include "subprocess.h"
|
||||
#include "utils.hpp"
|
||||
#include "widgets.hpp"
|
||||
|
||||
static bool running{true};
|
||||
static std::string process_log{};
|
||||
|
||||
using namespace std::chrono_literals;
|
||||
|
||||
void execute() {
|
||||
const char* const commandLine[] = {"/sbin/tail", "-f", "/tmp/smth.log", nullptr};
|
||||
struct subprocess_s process;
|
||||
int ret = -1;
|
||||
static char data[1048576 + 1] = {0};
|
||||
unsigned index = 0;
|
||||
unsigned bytes_read = 0;
|
||||
|
||||
if ((ret = subprocess_create(commandLine, subprocess_option_enable_async | subprocess_option_combined_stdout_stderr, &process)) != 0) {
|
||||
std::perror("creation failed");
|
||||
std::cerr << "creation failed with: " << ret << '\n';
|
||||
running = false;
|
||||
return;
|
||||
}
|
||||
|
||||
do {
|
||||
bytes_read = subprocess_read_stdout(&process, data + index,
|
||||
sizeof(data) - 1 - index);
|
||||
|
||||
index += bytes_read;
|
||||
|
||||
process_log = data;
|
||||
} while (bytes_read != 0);
|
||||
|
||||
subprocess_join(&process, &ret);
|
||||
subprocess_destroy(&process);
|
||||
}
|
||||
|
||||
void execute_thread() {
|
||||
while (running) {
|
||||
execute();
|
||||
|
||||
std::this_thread::sleep_for(2s);
|
||||
}
|
||||
}
|
||||
|
||||
int main() {
|
||||
using namespace ftxui;
|
||||
std::jthread t(execute_thread);
|
||||
|
||||
auto screen = ScreenInteractive::Fullscreen();
|
||||
|
||||
std::jthread refresh_ui([&] {
|
||||
while (running) {
|
||||
std::this_thread::sleep_for(0.05s);
|
||||
screen.PostEvent(Event::Custom);
|
||||
}
|
||||
});
|
||||
|
||||
auto button_option = ButtonOption();
|
||||
button_option.border = false;
|
||||
auto button_back = Button("Back", screen.ExitLoopClosure(), &button_option);
|
||||
auto container = Container::Horizontal({button_back});
|
||||
|
||||
auto renderer = Renderer(container, [&] {
|
||||
return tui::detail::centered_widget(container, "New CLI Installer", tui::detail::multiline_text(utils::make_multiline(process_log)) | vscroll_indicator | yframe | flex);
|
||||
});
|
||||
|
||||
screen.Loop(renderer);
|
||||
running = false;
|
||||
t.join();
|
||||
refresh_ui.join();
|
||||
}
|
@ -1,14 +1,22 @@
|
||||
#include "widgets.hpp"
|
||||
#include "config.hpp"
|
||||
#include "utils.hpp"
|
||||
#include "utils.hpp" // for make_multiline
|
||||
|
||||
/* clang-format off */
|
||||
#include <algorithm> // for transform
|
||||
#include <string> // for basic_string
|
||||
#include <ftxui/component/component.hpp> // for Renderer, Button
|
||||
#include <ftxui/component/component_options.hpp> // for ButtonOption
|
||||
#include <ftxui/component/screen_interactive.hpp> // for Component, ScreenI...
|
||||
/* clang-format on */
|
||||
#include <algorithm> // for transform
|
||||
#include <cstddef> // for size_t
|
||||
#include <iterator> // for back_insert_iterator
|
||||
#include <memory> // for shared_ptr, __shar...
|
||||
#include <string> // for string, allocator
|
||||
#include <utility> // for move
|
||||
|
||||
#include <ftxui/component/captured_mouse.hpp> // for ftxui
|
||||
#include <ftxui/component/component.hpp> // for Renderer, Vertical
|
||||
#include <ftxui/component/component_base.hpp> // for ComponentBase, Com...
|
||||
#include <ftxui/component/component_options.hpp> // for ButtonOption, Inpu...
|
||||
#include <ftxui/component/screen_interactive.hpp> // for ScreenInteractive
|
||||
#include <ftxui/dom/elements.hpp> // for operator|, Element
|
||||
#include <ftxui/dom/node.hpp> // for Render
|
||||
#include <ftxui/screen/screen.hpp> // for Full, Screen
|
||||
#include <ftxui/util/ref.hpp> // for Ref
|
||||
|
||||
using namespace ftxui;
|
||||
|
||||
|
@ -1,12 +1,19 @@
|
||||
#ifndef WIDGETS_HPP
|
||||
#define WIDGETS_HPP
|
||||
|
||||
#include <array> // for array
|
||||
#include <cstdint> // for int32_t
|
||||
#include <functional> // for function
|
||||
#include <string> // for string
|
||||
#include <string_view> // for string_view
|
||||
#include <vector> // for vector
|
||||
|
||||
#include <ftxui/component/component_base.hpp> // for Components
|
||||
#include <ftxui/component/screen_interactive.hpp> // for Component
|
||||
#include <ftxui/dom/elements.hpp> // for size, GREATER_THAN
|
||||
|
||||
/* clang-format off */
|
||||
#include <string_view> // for string_view
|
||||
#include <ftxui/component/component_base.hpp> // for Component
|
||||
#include <ftxui/component/component_options.hpp> // for ButtonOption
|
||||
#include <ftxui/dom/elements.hpp> // for Element, operator|, size
|
||||
#include <ftxui/component/screen_interactive.hpp>
|
||||
namespace ftxui { struct ButtonOption; }
|
||||
/* clang-format on */
|
||||
|
||||
namespace tui {
|
||||
|
Loading…
Reference in New Issue
Block a user