Radix Relay
Hybrid mesh communications with Signal Protocol encryption
Loading...
Searching...
No Matches
tui_sink.hpp
Go to the documentation of this file.
1#pragma once
2
4#include <core/events.hpp>
5#include <memory>
7#include <spdlog/sinks/base_sink.h>
8#include <string>
9
10namespace radix_relay::cli_utils {
11
19template<typename Mutex> class tui_sink final : public spdlog::sinks::base_sink<Mutex>
20{
21public:
28 : display_queue_(std::move(queue))
29 {}
30
31protected:
37 auto sink_it_(const spdlog::details::log_msg &msg) -> void override
38 {
39 spdlog::memory_buf_t formatted;
40 spdlog::sinks::base_sink<Mutex>::formatter_->format(msg, formatted);
41 std::string message(formatted.data(), formatted.size());
42
43 if (not message.empty() and message.back() == '\n') { message.pop_back(); }
44
45 if (display_queue_) {
46 display_queue_->push(core::events::display_message{ .message = message,
47 .contact_rdx = std::nullopt,
48 .timestamp = platform::current_timestamp_ms(),
50 }
51 }
52
56 auto flush_() -> void override {}
57
58private:
59 std::shared_ptr<async::async_queue<core::events::display_filter_input_t>> display_queue_;
60};
61
64
65}// namespace radix_relay::cli_utils
Thread-safe asynchronous queue for message passing between coroutines.
Custom spdlog sink that routes log messages to a display queue.
Definition tui_sink.hpp:20
tui_sink(std::shared_ptr< async::async_queue< core::events::display_filter_input_t > > queue)
Constructs a TUI sink with the given display queue.
Definition tui_sink.hpp:27
auto sink_it_(const spdlog::details::log_msg &msg) -> void override
Formats and queues a log message.
Definition tui_sink.hpp:37
auto flush_() -> void override
Flushes pending log messages (no-op for queue-based sink).
Definition tui_sink.hpp:56
auto current_timestamp_ms() -> std::uint64_t
Gets current timestamp in milliseconds since Unix epoch.
Request to display a message to the user.
Definition events.hpp:375
std::string message
Message content to display.
Definition events.hpp:385