| 123456789101112131415161718192021222324252627282930313233343536 |
- //
- // cli.hpp
- // ncurses-wrapper
- //
- // Created by Sam Jaffe on 7/23/24.
- //
- #pragma once
- #include <string>
- #include <vector>
- #include <ncurses-wrapper/forward.h>
- #include <ncurses-wrapper/window.h>
- namespace curses {
- class Cli {
- private:
- Window window_;
- std::string prompt_;
- std::vector<std::string> stack_{""};
- int horizontal_offset_{0};
- int vertical_offset_{0};
- public:
- template <typename... Flags>
- explicit Cli(std::string const &prompt, Flags const &...flags)
- : window_(flags..., NoEcho, Scrollable, ExtendedKeys), prompt_(prompt) {}
-
- void loop(std::function<void(curses::Window &, std::string)> on_enter);
-
- private:
- size_t index() const { return stack_.size() - vertical_offset_ - 1; }
- std::string &get() { return stack_.at(index()); }
- };
- }
|