1
- #include " ftxui/component/captured_mouse.hpp" // for ftxui
2
- #include " ftxui/component/component.hpp" // for Menu
3
- #include " ftxui/component/component_options.hpp" // for MenuOption
4
- #include " ftxui/component/screen_interactive.hpp" // for ScreenInteractive
5
-
6
- #include < memory>
7
- #include < string>
8
- #include < string_view>
9
- #include < variant>
10
-
11
- #include < fmt/core.h>
12
- #include < mp-units/format.h>
13
-
14
- #include < boost/asio.hpp>
15
- #include < boost/program_options.hpp>
16
- #include < ftxui/component/component.hpp>
17
1
#include < iostream>
18
-
19
- #include < sdbusplus/asio/connection.hpp>
20
- #include < sdbusplus/asio/property.hpp>
21
- #include < sdbusplus/bus/match.hpp>
22
-
23
- #include < tfc/dbus/match_rules.hpp>
24
- #include < tfc/dbus/sd_bus.hpp>
25
-
26
- #include < tfc/ipc.hpp>
27
2
#include < tfc/progbase.hpp>
3
+ #include " dbus_screen_manager.hpp"
28
4
29
- namespace asio = boost::asio;
30
- namespace po = boost::program_options;
31
-
32
- using variant_t = std::variant<bool , int64_t , uint64_t , double , std::string, std::vector<std::string>>;
33
-
34
- auto left_menu (const std::vector<std::string>* entries, int * selected, const ftxui::Component& right_menu)
35
- -> ftxui::Component {
36
- auto option = ftxui::MenuOption::Vertical ();
37
-
38
- option.on_enter = [selected, right_menu] { right_menu->TakeFocus (); };
39
-
40
- return ftxui::Menu (entries, selected, option);
41
- };
42
-
43
- auto right_menu (const std::vector<std::string>* entries, int * selected) -> ftxui::Component {
44
- const auto option = ftxui::MenuOption::Vertical ();
45
- // fill remaining horizontal space
46
- return ftxui::Menu (entries, selected, option);
47
- };
48
-
49
- // GET DEMM DBUS DATA
50
- auto match_callback (sdbusplus::message_t & msg) -> void {
51
- // std::cout << msg.get_member() << std::endl;
52
- // std::cout << msg.get_signature() << std::endl;
53
- // std::cout << msg.get_sender() << std::endl;
54
- // std::cout << msg.get_interface() << std::endl;
55
- // std::cout << msg.get_path() << std::endl;
56
- if (msg.get_member () && std::string (msg.get_member ()) == " PropertiesChanged" ) {
57
- std::tuple<std::string, std::vector<std::pair<std::string, std::variant<bool , uint64_t >>>, std::vector<std::string>>
58
- container{};
59
- if (sdbusplus::utility::read_into_tuple (container, msg)) {
60
- std::string const & interface = std::get<0 >(container);
61
- std::visit ([&interface](auto & value) { std::cout << interface << " : " << value << std::endl; },
62
- std::get<1 >(container)[0 ].second );
63
- }
64
- }
65
- }
66
-
67
- auto main (int argc, char ** argv) -> int {
5
+ int main (int argc, char ** argv) {
68
6
auto description{ tfc::base::default_description () };
69
7
70
8
std::string signal{};
@@ -79,79 +17,12 @@ auto main(int argc, char** argv) -> int {
79
17
" list-signals" , po::bool_switch (&list_signals), " List all available IPC signals" )(
80
18
" list-slots" , po::bool_switch (&list_slots), " List all available IPC slots" );
81
19
tfc::base::init (argc, argv, description);
82
-
83
- asio::io_context ctx{};
84
- std::shared_ptr<sdbusplus::asio::connection> connection =
85
- std::make_shared<sdbusplus::asio::connection>(ctx, tfc::dbus::sd_bus_open_system_mon ());
86
- // Attach callback
87
- auto match = std::make_unique<sdbusplus::bus::match::match>(*connection, " " , match_callback);
88
- // Become monitor method
89
- auto mc = connection->new_method_call (" org.freedesktop.DBus" , " /org/freedesktop/DBus" , " org.freedesktop.DBus.Monitoring" ,
90
- " BecomeMonitor" );
91
- mc.append <std::vector<std::string>, uint32_t >({ " path=/com/skaginn3x/Signals" }, 0 );
92
- auto reply = connection->call (mc);
93
- if (reply.is_method_error ()) {
94
- if (reply.get_error () != nullptr )
95
- throw std::runtime_error (reply.get_error ()->message );
96
- throw std::runtime_error (" Unknown error" );
20
+ try {
21
+ DBusScreenManager sm;
22
+ sm.Run ();
23
+ } catch (const std::exception& e) {
24
+ std::cerr << " Error: " << e.what () << std::endl;
25
+ return 1 ;
97
26
}
98
- // auto ucontainer = connection->new_method_call("org.freedesktop.DBus", "/org/freedesktop/DBus",
99
- // "org.freedesktop.DBus.Monitoring",
100
- // "BecomeMonitor");
101
- // ucontainer.append<std::tuple<std::string, std::vector<std::pair<std::string, std::variant<bool>>>,
102
- // std::vector<std::string>>>(
103
- // {"test",std::vector<std::pair<std::string, std::variant<bool>>>{ std::pair<std::string, std::variant<bool>>{ "test",
104
- // true } }, std::vector<std::string>{ "test" }}
105
- // );
106
- // try{
107
- // connection->call(ucontainer);
108
- // }catch (sdbusplus::exception::SdBusError& e){
109
- // std::cout << ucontainer.get_signature() << " IS THIS THE REAL LIFE" << std::endl;
110
- // }
111
- ctx.run ();
112
- auto screen = ftxui::ScreenInteractive::TerminalOutput ();
113
-
114
- std::vector<std::string> left_menu_entries = {
115
- " 0%" , " 10%" , " 20%" , " 30%" , " 40%" , " 50%" , " 60%" , " 70%" , " 80%" , " 90%" ,
116
- };
117
- std::vector<std::string> right_menu_entries = {
118
- " 0%" , " 1%" , " 2%" , " 3%" , " 4%" , " 5%" , " 6%" , " 7%" , " 8%" , " 9%" , " 10%" ,
119
- };
120
-
121
- auto menu_option = ftxui::MenuOption ();
122
- menu_option.on_enter = screen.ExitLoopClosure ();
123
-
124
- int left_menu_selected = 0 ;
125
- int right_menu_selected = 0 ;
126
-
127
- std::vector<std::string> services = { " hi" };
128
- ftxui::Component right_menuz = right_menu (&right_menu_entries, &right_menu_selected);
129
- ftxui::Component left_menuz = left_menu (&services, &left_menu_selected, right_menuz);
130
-
131
- ftxui::Component container = ftxui::Container::Horizontal ({ left_menuz, right_menuz });
132
-
133
- auto renderer = Renderer (container, [&] {
134
- return ftxui::vbox ({
135
- // -------- Top panel --------------
136
- ftxui::hbox ({
137
- // -------- Left Menu --------------
138
- ftxui::vbox ({
139
- ftxui::hcenter (ftxui::bold (ftxui::text (" Percentage by 10%" ))),
140
- ftxui::separator (),
141
- left_menuz->Render (),
142
- }),
143
- ftxui::separator (),
144
- // -------- Right Menu --------------
145
- ftxui::vbox ({
146
- ftxui::hcenter (ftxui::bold (ftxui::text (" Percentage by 1%" ))),
147
- ftxui::separator (),
148
- right_menuz->Render (),
149
- }) | ftxui::flex,
150
- ftxui::separator (),
151
- }),
152
- }) |
153
- ftxui::border | ftxui::flex;
154
- });
155
-
156
- screen.Loop (renderer);
157
- };
27
+ return 0 ;
28
+ }
0 commit comments