1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
|
#include <string>
#include <memory>
#include <vector>
#include "ftxui/component/captured_mouse.hpp" // for ftxui
#include "ftxui/component/component.hpp" // for Input, Renderer, Vertical
#include "ftxui/component/component_base.hpp" // for ComponentBase
#include "ftxui/component/component_options.hpp" // for InputOption
#include "ftxui/component/screen_interactive.hpp" // for Component, ScreenInteractive
#include "ftxui/dom/elements.hpp" // for text, hbox, separator, Element, operator|, vbox, border
#include "ftxui/util/ref.hpp" // for Ref
#include "tui.hpp"
using namespace std;
bool Tui::renderSearchBar(string& searchTerm, int& searchingFor) {
auto screen = ftxui::ScreenInteractive::Fullscreen();
ftxui::InputOption option;
option.on_enter = screen.ExitLoopClosure();
ftxui::Component inputSearchTerm = ftxui::Input(&searchTerm, "SMTH", &option);
vector<string> searchingForOptions = { "Videos", "Channels", "Playlists" };
ftxui::Component selectSearchFor = ftxui::Toggle(&searchingForOptions, &searchingFor);
string cancelLabel = "Cancel";
ftxui::Component cancelButton = ftxui::Button(&cancelLabel, cancelAndExit(screen));
string searchLabel = "Search";
ftxui::Component searchButton = ftxui::Button(&searchLabel, screen.ExitLoopClosure());
ftxui::Component component = ftxui::Container::Vertical({
inputSearchTerm,
selectSearchFor,
cancelButton,
searchButton
});
auto renderer = ftxui::Renderer(component, [&] {
return ftxui::vbox({
ftxui::text(" YTCCP "),
ftxui::separator(),
ftxui::hbox(ftxui::text(" Search Term: "), inputSearchTerm->Render()),
ftxui::separator(),
ftxui::hbox(ftxui::text(" Search For: "), selectSearchFor->Render()),
ftxui::separator(),
ftxui::hbox({
cancelButton->Render() |
ftxui::size(ftxui::WIDTH, ftxui::LESS_THAN, 20),
ftxui::filler(),
searchButton->Render() |
ftxui::size(ftxui::WIDTH, ftxui::LESS_THAN, 20),
}),
}) | ftxui::border;
});
cancel = false;
screen.Loop(renderer);
return true;
}
bool Tui::isCancelled() {
return cancel;
}
ftxui::Closure Tui::cancelAndExit(ftxui::ScreenInteractive& screen) {
cancel = true;
return screen.ExitLoopClosure();
}
|