1 #ifndef MSP_IO_CONSOLE_H_
2 #define MSP_IO_CONSOLE_H_
4 #include <msp/core/mspcore_api.h>
5 #include "eventobject.h"
12 Provides access to standard input, output and error streams. This class can't
13 be instantiated directly - use one of the cin, cout and cerr references
16 class MSPCORE_API Console: public EventObject
35 void set_block(bool) override;
36 void set_inherit(bool) override;
38 /** If local echo is enabled, characters will appear on the console as they
39 are typed. Can only be used on an input Console. */
40 void set_local_echo(bool);
42 /** If line buffering is enabled, input will only be available when a
43 newline is encountered. On some systems, this may also enable line editing.
44 Can only be used on an input Console.
46 void set_line_buffer(bool);
48 /** Retrieves the size of the Console. Can only be used on an output
50 void get_size(unsigned &rows, unsigned &cols);
52 /** Redirects input from or output to another I/O object. This performs a
53 system-level redirect. Closing the other object won't affect the
55 void redirect(Base &);
58 std::size_t do_write(const char *, std::size_t) override;
59 std::size_t do_read(char *, std::size_t) override;
62 const Handle &get_handle(Mode) override;
63 const Handle &get_event_handle() override { return handle; }
65 static Console &instance(Stream);
68 // TODO make these inline instead of static when upgrading to C++17.
69 static Console &cin = Console::instance(Console::CIN);
70 static Console &cout = Console::instance(Console::COUT);
71 static Console &cerr = Console::instance(Console::CERR);