summaryrefslogtreecommitdiff
path: root/include/ncurses/basic_winbuf.hpp
blob: adc424a89135513d78bbefcd916310262e98f0d0 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
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_