1 #include <msp/core/systemerror.h>
3 #include "handle_private.h"
9 DWORD stream_to_sys(Msp::IO::Console::Stream stream)
13 case Msp::IO::Console::CIN: return STD_INPUT_HANDLE;
14 case Msp::IO::Console::COUT: return STD_OUTPUT_HANDLE;
15 case Msp::IO::Console::CERR: return STD_ERROR_HANDLE;
16 default: throw invalid_argument("stream_to_sys");
26 void Console::platform_init()
28 *handle = GetStdHandle(stream_to_sys(stream));
34 void Console::set_local_echo(bool e)
39 GetConsoleMode(*handle, &m);
40 SetConsoleMode(*handle, (m&~ENABLE_ECHO_INPUT) | (e?ENABLE_ECHO_INPUT:0));
43 void Console::set_line_buffer(bool l)
48 if(!GetConsoleMode(*handle, &m))
49 throw system_error("GetConsoleMode");
50 if(!SetConsoleMode(*handle, (m&~ENABLE_LINE_INPUT) | (l?ENABLE_LINE_INPUT:0)))
51 throw system_error("SetConsoleMode");
54 void Console::get_size(unsigned &rows, unsigned &cols)
56 check_access(M_WRITE);
58 CONSOLE_SCREEN_BUFFER_INFO sbi;
59 if(!GetConsoleScreenBufferInfo(*handle, &sbi))
60 throw system_error("GetConsoleScreenBufferInfo");
61 // Right/bottom coords are inclusive
62 rows = sbi.srWindow.Bottom+1-sbi.srWindow.Top;
63 cols = sbi.srWindow.Right+1-sbi.srWindow.Left;
66 void Console::redirect(Base &other)
68 SetStdHandle(stream_to_sys(stream), *other.get_handle(mode));