]> git.tdb.fi Git - libs/core.git/blob - source/io/console.h
d29ef003998c005c32d83305003e0b83377a8dd4
[libs/core.git] / source / io / console.h
1 #ifndef MSP_IO_CONSOLE_H_
2 #define MSP_IO_CONSOLE_H_
3
4 #include "eventobject.h"
5 #include "handle.h"
6
7 namespace Msp {
8 namespace IO {
9
10 /**
11 Provides access to standard input, output and error streams.  This class can't
12 be instantiated directly - use one of the cin, cout and cerr references
13 instead.
14 */
15 class Console: public EventObject
16 {
17 public:
18         enum Stream
19         {
20                 INPUT = 0,
21                 OUTPUT = 1,
22                 ERROR = 2
23         };
24
25 private:
26         Stream stream;
27         Handle handle;
28
29         Console(Stream);
30 public:
31         ~Console();
32
33         virtual void set_block(bool);
34         
35         /** If local echo is enabled, characters will appear on the console as they
36         are typed.  Can only be used on an input Console.  */
37         void set_local_echo(bool);
38
39         /** If line buffering is enabled, input will only be available when a
40         newline is encountered.  On some systems, this may also enable line editing.
41         Can only be used on an input Console.
42         */
43         void set_line_buffer(bool);
44
45         /** Retrieves the size of the Console.  Can only be used on an output
46         Console. */
47         void get_size(unsigned &rows, unsigned &cols);
48
49         /** Redirects input from or output to another I/O object.  This performs a
50         system-level redirect.  Closing the other object won't affect the
51         redirection. */
52         void redirect(Base &);
53
54 protected:
55         virtual unsigned do_write(const char *, unsigned);
56         virtual unsigned do_read(char *, unsigned);
57
58 public:
59         virtual const Handle &get_event_handle() { return handle; }
60
61         static Console &instance(Stream);
62 };
63
64 extern Console &cin;
65 extern Console &cout;
66 extern Console &cerr;
67
68 } // namespace IO
69 } // namespace Msp
70
71 #endif