summaryrefslogtreecommitdiff
path: root/cli/component.hpp
blob: c419020f1db23b4c606a4de6ea4189938e2624de (plain)
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
75
76
#pragma once

#include <ftxui/component/event.hpp>
#include <ftxui/component/component_base.hpp>
#include <ftxui/component/component.hpp>

#include "katja/repository.hpp"
#include "katja/database.hpp"

namespace katja
{
    class PageBase : public ftxui::ComponentBase
    {
    public:
        virtual void Load() = 0;
    };

    using Page = std::shared_ptr<PageBase>;
    using Pages = std::vector<Page>;

    class ScreenContainer final : public ftxui::ComponentBase
    {
        int menu_selected{ 0 };
        ftxui::Component menu;
        ftxui::Component content;
        std::vector<std::string> menu_entries;
        Pages menu_pages;
        std::function<void()> on_enter;

    public:
        ScreenContainer(std::vector<std::pair<std::string, Page>> pages, std::function<void()> on_enter);

        ftxui::Element OnRender() override;
        bool OnEvent(ftxui::Event event) override;
    };

    ftxui::Component Screen(std::vector<std::pair<std::string, Page>> pages, std::function<void()> on_enter);

    class WelcomePage final : public PageBase
    {
    public:
        void Load() override;
        ftxui::Element OnRender() override;
    };

    class UpdatesPage final : public PageBase
    {
        std::vector<package_identifier> updatable;
        std::shared_ptr<struct repository> repository;
        package_database database;

    public:
        UpdatesPage(std::shared_ptr<struct repository> repository, package_database database);

        void Load() override;
        ftxui::Element OnRender() override;
    };

    class SearchPage final : public PageBase
    {
        std::string needle;
        ftxui::Component search_input;
        ftxui::Component type_input;
        std::shared_ptr<struct repository> repository;
        std::string architecture;
        std::vector<package_identifier> search_results;
        int search_type{ 0 };

    public:
        SearchPage(std::shared_ptr<struct repository> repository, const std::string& architecture);

        void Load() override;
        ftxui::Element OnRender() override;
        bool OnEvent(ftxui::Event event) override;
    };
}