#include #include #include #include #include static bool is_bold (WINDOW *win) { short pair; attr_t attrs; wattr_get (win, &attrs, &pair, NULL); return attrs & WA_BOLD; } using ncurses::pen; void pen::write (WINDOW *win, char const *str, int len) { waddnstr (win, str, len); } void pen::write (WINDOW *win, std::string const &str) { write (win, str.data (), str.length ()); } void pen::write (WINDOW *win, char const ch) { NCURSES_ASSERT (waddch (win, ch)); } std::string const &pen::ltitle (bool bold) { static std::string const s[2] = { "┤", "╣" }; return s[bold]; } std::string const &pen::rtitle (bool bold) { static std::string const s[2] = { "├", "╠" }; return s[bold]; } std::string const &pen::ulcorner (bool bold) { static std::string const s[2] = { "┌", "╔" }; return s[bold]; } std::string const &pen::llcorner (bool bold) { static std::string const s[2] = { "└", "╚" }; return s[bold]; } std::string const &pen::urcorner (bool bold) { static std::string const s[2] = { "┐", "╗" }; return s[bold]; } std::string const &pen::lrcorner (bool bold) { static std::string const s[2] = { "┘", "╝" }; return s[bold]; } std::string const &pen::h_line (bool bold) { static std::string const s[2] = { "─", "═" }; return s[bold]; } std::string const &pen::v_line (bool bold) { static std::string const s[2] = { "│", "║" }; return s[bold]; } pen::pen (window &win) : win_ (win.win ()) { } pen::pen (pad &pad) : win_ (pad.win ()) { } /**< move pen to the new position */ void pen::move (int x, int y) { NCURSES_ASSERT (wmove (win_, y, x)); } void pen::commit () { NCURSES_ASSERT (wnoutrefresh (win_)); } int pen::x () const { return getcurx (win_); } int pen::y () const { return getcury (win_); } void pen::clear () { NCURSES_ASSERT (werase (win_)); } void pen::fill (color const &col) { NCURSES_ASSERT (wbkgd (win_, COLOR_PAIR (col.num ()))); } void pen::set_color (color const &c) { /* what should I use here: wattrset or wattr_set */ NCURSES_ASSERT (wattr_set (win_, c.attr (), c.num (), 0)); } void pen::frame () { move (0, 0); bool const bold = is_bold (win_); int maxx, maxy; getmaxyx (win_, maxy, maxx); write (ulcorner (bold)); for (int i = 1; i < maxx - 1; i++) write (h_line (bold)); write (urcorner (bold)); for (int i = 1; i < maxy; i++) { write (v_line (bold)); move (0, i); } write (llcorner (bold)); for (int i = 1; i < maxx - 1; i++) write (h_line (bold)); write (lrcorner (bold)); for (int i = 1; i < maxy - 1; i++) { move (maxx - 1, i); write (v_line (bold)); } } void pen::title (std::string const &title) { bool const bold = is_bold (win_); move (2, 0); write (ltitle (bold)); write (title); write (rtitle (bold)); } void pen::write (std::string const &str) { write (win_, str); } void pen::write (char const ch) { write (win_, ch); }