]> git.tdb.fi Git - libs/core.git/blob - source/io/console.h
Merge branch 'fs-master'
[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 private:
18         Handle handle;
19
20         Console(unsigned);
21 public:
22         ~Console();
23
24         virtual void set_block(bool);
25         
26         /** If local echo is enabled, characters will appear on the console as they
27         are typed.  Can only be used on an input Console.  */
28         void set_local_echo(bool);
29
30         /** If line buffering is enabled, input will only be available when a
31         newline is encountered.  On some systems, this may also enable line editing.
32         Can only be used on an input Console.
33         */
34         void set_line_buffer(bool);
35
36         /** Retrieves the size of the Console.  Can only be used on an output
37         Console. */
38         void get_size(unsigned &rows, unsigned &cols);
39
40 protected:
41         virtual unsigned do_write(const char *, unsigned);
42         virtual unsigned do_read(char *, unsigned);
43
44 public:
45         virtual const Handle &get_event_handle() { return handle; }
46
47         static Console &instance(unsigned);
48 };
49
50 extern Console &cin;
51 extern Console &cout;
52 extern Console &cerr;
53
54 } // namespace IO
55 } // namespace Msp
56
57 #endif