diff options
Diffstat (limited to 'include/ncurses/basic_winbuf.hpp')
-rw-r--r-- | include/ncurses/basic_winbuf.hpp | 48 |
1 files changed, 48 insertions, 0 deletions
diff --git a/include/ncurses/basic_winbuf.hpp b/include/ncurses/basic_winbuf.hpp new file mode 100644 index 0000000..adc424a --- /dev/null +++ b/include/ncurses/basic_winbuf.hpp @@ -0,0 +1,48 @@ +#ifndef INCLUDE_NCURSES_BASIC_WINBUF_HPP_ +#define INCLUDE_NCURSES_BASIC_WINBUF_HPP_ + +#include <streambuf> + +#include <ncurses.h> + +#include <ncurses/utils/preamble.hpp> +#include <ncurses/window.hpp> + +namespace NCURSES_CPP_NAMESPACE { + +template <typename CharT, typename Traits = std::char_traits<CharT>> +class basic_winbuf final : public std::basic_streambuf<CharT, Traits> { +public: + using Base = std::basic_streambuf<CharT, Traits>; + using typename Base::char_type; + using typename Base::int_type; + using typename Base::off_type; + using typename Base::pos_type; + + explicit basic_winbuf(window &win) : win_(win), x_pos_(0), y_pos_(0) {} + + /*int_type uflow() override {}*/ + /*int_type underflow() override {}*/ + int_type overflow(int_type ch = Traits::eof()) override {} + std::streamsize xsputn(const char_type *s, std::streamsize n) override { + // TODO: change to call to new trait's callback for each supported type + // for char/wchar_t/other_chars use wadd(w)nstr + // for curs_char/curs_wchar use for loop of wadd(w)ch + waddnstr(static_cast<WINDOW *>(win_), s, n); + } + // TODO: overload << operator with full_attrs to do attr_on, etc... + + void pos(int y_pos, int x_pos) NCURSES_CPP_NOEXCEPT { + y_pos_ = y_pos; + x_pos_ = x_pos; + } + +private: + window &win_; + int x_pos_; + int y_pos_; +}; + +} // namespace NCURSES_CPP_NAMESPACE + +#endif // INCLUDE_NCURSES_BASIC_WINBUF_HPP_ |