Branch data Line data Source code
1 : : // Copyright 2026 HPActor Contributors
2 : : // Licensed under the Apache License, Version 2.0
3 : : #pragma once
4 : :
5 : : #include <cstdint>
6 : : #include <functional>
7 : : #include <string>
8 : :
9 : : namespace hpactor {
10 : : namespace cli {
11 : :
12 : : class OutputFormatter;
13 : :
14 : : class Pager {
15 : : public:
16 : : enum class Action { Next, Previous, Quit, Search, Goto, Unknown };
17 : :
18 : : Pager(uint32_t page_size);
19 : :
20 : : // Show one page. Calls render(offset, limit) to get the rows.
21 : : // Returns true if there are more pages.
22 : : bool show_page(uint32_t total_items,
23 : : std::function<void(uint32_t offset, uint32_t limit)> render,
24 : : OutputFormatter* output);
25 : :
26 : : // Parse user input after a page prompt.
27 : : Action parse_input(const std::string& input, std::string& arg);
28 : :
29 : 6 : uint32_t current_page() const {
30 : 6 : return current_offset_ / page_size_ + 1;
31 : : }
32 : : uint32_t total_pages() const;
33 : : void goto_page(uint32_t page);
34 : : void next_page();
35 : : void prev_page();
36 : :
37 : : private:
38 : : uint32_t page_size_;
39 : : uint32_t current_offset_ = 0;
40 : : uint32_t total_items_ = 0;
41 : : };
42 : :
43 : : } // namespace cli
44 : : } // namespace hpactor
|