]> git.tdb.fi Git - libs/core.git/blob - source/console.h
Use the console handle for read/write on *nix
[libs/core.git] / source / console.h
1 /* $Id$
2
3 This file is part of libmspio
4 Copyright © 2008  Mikko Rasa, Mikkosoft Productions
5 Distributed under the LGPL
6 */
7
8 #ifndef MSP_IO_CONSOLE_H_
9 #define MSP_IO_CONSOLE_H_
10
11 #include "base.h"
12
13 namespace Msp {
14 namespace IO {
15
16 /**
17 Provides access to standard input, output and error streams.  This class can't
18 be instantiated directly - use one of the cin, cout and cerr references
19 instead.
20 */
21 class Console: public Base
22 {
23 private:
24         Handle handle;
25
26         Console(unsigned);
27 public:
28         ~Console();
29
30         virtual void set_block(bool);
31         
32         /** If local echo is enabled, characters will appear on the console as they
33         are typed.  Can only be used on an input Console.  */
34         void set_local_echo(bool);
35
36         /** If line buffering is enabled, input will only be available when a
37         newline is encountered.  On some systems, this may also enable line editing.
38         Can only be used on an input Console.
39         */
40         void set_line_buffer(bool);
41
42         /**
43         Retrieves the size of the Console.  Can only be used on an output Console.
44         */
45         void get_size(unsigned &rows, unsigned &cols);
46
47         virtual Handle get_event_handle();
48 protected:
49         virtual unsigned do_write(const char *, unsigned);
50         virtual unsigned do_read(char *, unsigned);
51 public:
52         static Console &instance(unsigned);
53 };
54
55 extern Console &cin;
56 extern Console &cout;
57 extern Console &cerr;
58
59 } // namespace IO
60 } // namespace Msp
61
62 #endif