// // window.h // ncurses-wrapper // // Created by Sam Jaffe on 7/23/24. // #pragma once #include #include #include #include #include #undef getch #undef delch namespace curses { constexpr struct Bold_t {} Bold; constexpr struct NoEcho_t {} NoEcho; // Don't automatically print input characters constexpr struct WithColor_t {} WithColor; constexpr struct Scrollable_t {} Scrollable; // Enable scrolling constexpr struct ExtendedKeys_t {} ExtendedKeys; // Enable KEY_* keys as unique items class Window { private: friend class AttributeScope; WINDOW *self_; public: template Window(Flags const &...flags) : Window(initscr(), flags...) {} template Window(Bounds const &term, Flags const &...flags) : Window(newwin(term.height, term.width, 0, 0), flags...) {} ~Window(); void move(Position const &pos); void move(Offset const &off); Position getpos(); Bounds getsize(); int getch(); int delch(); void clear_line(); void clear(); Status printf(char const *fmt, ...) GCC_PRINTFLIKE(2, 3); template AttributeScope with(Attrs const &...attrs) { return {{to_attr(attrs...)}, *this}; } private: template Window(WINDOW *win, Flags const &...flags) : self_(win) { clear(); [[maybe_unused]] int _[] = {(init_with(flags), 0)...}; } void init_with(NoEcho_t); void init_with(WithColor_t); void init_with(Scrollable_t); void init_with(ExtendedKeys_t); NCURSES_ATTR_T to_attr(Bold_t) const; NCURSES_ATTR_T to_attr(ColorPair const &color) const; }; Window &operator<<(Window &os, std::string const &value); Window &operator<<(Window &os, std::string_view value); Window &operator<<(Window &os, char const *value); Window &operator<<(Window &os, int value); Window &operator<<(Window &os, char value); }