19 namespace duds {
namespace hardware {
namespace display {
32 template <
class Char,
class Traits = std::
char_traits<Char> >
37 std::shared_ptr<TextDisplay>
disp;
43 typename Traits::int_type c = Traits::eof()
50 if (c == Traits::eof()) {
51 return Traits::not_eof(c);
56 disp->move(0, disp->rowPos());
60 disp->clearTo(disp->columns() - 1, disp->rowPos());
81 const std::shared_ptr<TextDisplay> &
display()
const {
87 virtual unsigned int column()
const {
88 return disp->columnPos();
93 virtual unsigned int row()
const {
94 return disp->rowPos();
122 virtual void clearTo(
unsigned int c,
unsigned int r) {
154 template <
class Char,
class Traits = std::
char_traits<Char> >
203 if (++cpos >= columnsize) {
205 if (++rpos >= rowsize) {
208 base::setp(base::pbase(), base::epptr());
223 while ((cpos != c) || (rpos != r)) {
237 base::pbump(-(
int)cpos);
242 clearToImpl(columnsize - 1, rpos);
256 typename Traits::int_type c = Traits::eof()
259 if (c != Traits::eof()) {
263 return Traits::not_eof(c);
265 virtual std::streamsize
xsputn(
const Char* s, std::streamsize count) {
267 for (std::streamsize cnt = count; cnt > 0; ++s, --cnt) {
279 typename std::vector<Char>::iterator siter = shown.begin();
280 typename std::vector<Char>::iterator uiter = update.begin();
282 for (
int r = 0; r < rowsize; ++r) {
283 for (
int c = 0; c < columnsize; ++siter, ++uiter, ++c) {
285 if (*siter != *uiter) {
289 base::display()->move(c, r);
292 assert(base::display()->columnPos() == c);
293 assert(base::display()->rowPos() == r);
295 base::display()->write((
int)*uiter);
307 typename base::off_type off,
308 std::ios_base::seekdir dir,
309 std::ios_base::openmode which = std::ios_base::out
312 if (which & std::ios_base::out) {
315 typename base::pos_type cp = base::pptr() - base::pbase();
316 typename base::pos_type op;
318 case std::ios_base::beg:
321 case std::ios_base::cur:
324 case std::ios_base::end:
325 op = working.size() + off;
328 return typename base::pos_type(-1);
331 if ((op > 0) && (op < working.size())) {
333 base::setp(base::pbase(), base::epptr());
337 rpos = op / columnsize;
338 cpos = op % columnsize;
342 return typename base::pos_type(-1);
345 typename base::pos_type pos,
346 std::ios_base::openmode which = std::ios_base::out
348 return seekoff(
typename base::off_type(pos), std::ios_base::beg, which);
358 columnsize(d->columns()),
362 shown(d->columns() * d->rows(),
' '),
363 update(d->columns() * d->rows(),
' '),
364 working(d->columns() * d->rows(),
' ') {
365 base::setp(&(working[0]), &(working[0]) + (columnsize * rowsize));
370 virtual unsigned int row()
const {
375 if ((c >= columnsize) || (r >= rowsize)) {
382 base::setp(base::pbase(), base::epptr());
385 base::pbump(r * columnsize + c);
390 std::memset(&(working[0]),
' ', working.size());
392 base::setp(base::pbase(), base::epptr());
395 virtual void clearTo(
unsigned int c,
unsigned int r) {
397 if ((c >= columnsize) || (r >= rowsize)) {
409 clearToImpl(columnsize - 1, rpos);
423 template <
class Char =
char,
class Traits = std::
char_traits<Char> >
425 using base = std::basic_ostream<Char, Traits>;
444 this->pword(xidx) =
this;
455 const std::shared_ptr<TextDisplay> &
display()
const {
484 void clearTo(
unsigned int c,
unsigned int r) {
507 template <
class Char,
class Traits = std::
char_traits<Char> >
541 template <
class Char,
class Traits = std::
char_traits<Char> >
562 template <
class Char,
class Traits>
571 template <
class Char,
class Traits>
572 std::basic_ostream<Char, Traits> &
clear(std::basic_ostream<Char, Traits> &os) {
584 template <
class Char,
class Traits>
585 std::basic_ostream<Char, Traits> &
startLine(std::basic_ostream<Char, Traits> &os) {
600 move_impl(
unsigned int c,
unsigned int r) : col(c), row(r) { }
601 template <
class Char,
class Traits>
603 std::basic_ostream<Char, Traits> &os,
const move_impl &mi
636 template <
class Char,
class Traits>
638 std::basic_ostream<Char, Traits> &os,
const clearTo_impl &mi
Part of the move() display stream manipulator.
boost::error_info< struct Info_DisplayPosition, Info_DisplayColRow > TextDisplayPositionInfo
Column and row of a display position as part of an error.
std::basic_ostream< Char, Traits > base
TextDisplayBasicBufferedStreambuf< char > TextDisplayBufferedStreambuf
Most common type for the TextDisplayBasicBufferedStreambuf.
void startLine()
Moves the cursor to the start of a line clearing text along the way.
const std::shared_ptr< TextDisplay > & display() const
Returns the output display.
An output stream for buffering writes to TextDisplay objects.
virtual unsigned int row() const
Returns the cursos's row position.
virtual unsigned int row() const
Returns the cursos's row position.
unsigned int columnPos() const
The current column position of the cursor.
static int xallocIndex()
Returns the index from xalloc(); needed by the stream manipulators.
The specified location is beyond the bounds of the display.
Part of the clearTo() display stream manipulator.
static const int xidx
The value from xalloc() used for stream manipulators to identify this stream type.
std::vector< Char > update
The buffer that is being written to the display.
std::uint8_t cpos
Cursor column position.
void clearTo(unsigned int c, unsigned int r)
Clear text from the current cursor position to the given position, inclusive.
virtual void startLine()
Moves the cursor to the start of a line clearing text along the way.
TextDisplayBasicStream< char > TextDisplayStream
Most common type for the TextDisplayBasicStream.
move_impl move(unsigned int c, unsigned int r)
Display stream manipulator that moves the display cursor to the given location.
virtual Traits::int_type overflow(typename Traits::int_type c=Traits::eof())
Writes a character to the start of the display after wrapping around from the end.
virtual unsigned int column() const
Returns the cursos's column position.
virtual void startLine()
Moves the cursor to the start of a line clearing text along the way.
TextDisplayBaseStream(TextDisplayBasicStreambuf< Char, Traits > *tbuf)
Makes an output stream that writes to the given display.
move_impl(unsigned int c, unsigned int r)
virtual void clearTo(unsigned int c, unsigned int r)
Clear text from the current cursor position to the given position, inclusive.
TextDisplayBasicStreambuf(const std::shared_ptr< TextDisplay > &d)
Makes the stream buffer with a display for output.
unsigned int columns() const
Returns the number of columns on the display.
std::uint8_t columnsize
Number of columns on the display.
virtual unsigned int column() const
Returns the cursos's column position.
virtual void moveCursor(unsigned int c, unsigned int r)
Moves the display's cursor to the given location.
virtual void clearTo(unsigned int c, unsigned int r)
Clear text from the current cursor position to the given position, inclusive.
Stores column and row data for display errors.
The base class for output streams that write to TextDisplay objects.
TextDisplayBasicStreambuf< char > TextDisplayStreambuf
Most common type for the TextDisplayBasicStreambuf.
std::vector< Char > shown
The buffer currently shown by the display.
std::uint8_t rpos
Cursor row position.
std::basic_ostream< Char, Traits > & clear(std::basic_ostream< Char, Traits > &os)
Display stream manipulator that clears all text from the display and places the cursor in the upper l...
void moveCursor(unsigned int c, unsigned int r)
Moves the display's cursor to the given location.
TextDisplayBasicStream(const std::shared_ptr< TextDisplay > &d)
Makes an output stream that immediately writes to the given display.
duds::general::Spinlock wblock
Write block.
TextDisplayBasicStreambuf< Char, Traits > * tdbb
The buffer handling the output.
Writes output from a stream into an internal buffer, and writes that buffer to the display when sync(...
virtual base::pos_type seekpos(typename base::pos_type pos, std::ios_base::openmode which=std::ios_base::out)
A simple spinlock following the lockable and timed lockable concepts so that it can be used with std:...
ConversationVector & operator<<(ConversationVector &cv, const Int &i)
Insertion operator to add an integer to a ConversationVector object.
virtual Traits::int_type overflow(typename Traits::int_type c=Traits::eof())
Writes a character to the display.
TextDisplayBasicBufferedStream< char > TextDisplayBufferedStream
Most common type for the TextDisplayBasicBufferedStream.
virtual void moveCursor(unsigned int c, unsigned int r)
Moves the display's cursor to the given location.
std::shared_ptr< TextDisplay > disp
The display that will receive the output.
void clearToImpl(unsigned int c, unsigned int r)
Clears a portion of the buffer with spaces from the current cursor position to the indicated position...
TextDisplayBasicBufferedStreambuf(const std::shared_ptr< TextDisplay > &d)
Makes the stream buffer with a display for output.
void clearDisplay()
Remove all text from the display and place the cursor in the upper left corner.
TextDisplayBasicStreambuf< Char, Traits > buff
The buffer handling the output.
virtual void clearDisplay()
Remove all text from the display and place the cursor in the upper left corner.
void bufWrite(Char c)
Handles writing a character into the buffer or moving the cursor for new lines and carriage returns...
clearTo_impl(unsigned int c, unsigned int r)
TextDisplayBasicBufferedStream(const std::shared_ptr< TextDisplay > &d)
Makes an output stream that writes to a buffer, and writes that buffer to the given display when flus...
Moves output from an output stream to a TextDisplay one character at a time.
virtual void clearDisplay()
Remove all text from the display and place the cursor in the upper left corner.
std::uint8_t rowsize
Number of rows on the display.
An output stream for immediately writing data to TextDisplay objects.
std::vector< Char > working
The buffer that accepts new data.
virtual base::pos_type seekoff(typename base::off_type off, std::ios_base::seekdir dir, std::ios_base::openmode which=std::ios_base::out)
void write(Char c)
Internal function to write a printable character to the buffer.
A fairly generic interface to a character based display that lacks color.
TextDisplayBasicBufferedStreambuf< Char, Traits > buff
The buffer handling the output.
const std::shared_ptr< TextDisplay > & display() const
Returns the output display.
#define DUDS_THROW_EXCEPTION(x)
Works like BOOST_THROW_EXCEPTION, but includes a stack trace if DUDS_ERRORS_VERBOSE is defined...
void clearTo(unsigned int c, unsigned int r)
Clear text from the current cursor position to the given position, inclusive.
unsigned int rowPos() const
The current row position of the cursor.
std::lock_guard< duds::general::Spinlock > SpinLockGuard
A convenience typedef for a std::lock_guard using the Spinlock object.
virtual std::streamsize xsputn(const Char *s, std::streamsize count)
boost::error_info< struct Info_DisplaySize, Info_DisplayColRow > TextDisplaySizeInfo
Column and row size of a display as part of an error.