1 #include <msp/core/except.h>
2 #include <msp/core/systemerror.h>
4 #include "handle_private.h"
10 DWORD stream_to_sys(Msp::IO::Console::Stream stream)
14 case Msp::IO::Console::CIN: return STD_INPUT_HANDLE;
15 case Msp::IO::Console::COUT: return STD_OUTPUT_HANDLE;
16 case Msp::IO::Console::CERR: return STD_ERROR_HANDLE;
17 default: throw Msp::internal_error("stream_to_sys");
27 void Console::platform_init()
29 *handle = GetStdHandle(stream_to_sys(stream));
35 void Console::set_local_echo(bool e)
40 GetConsoleMode(*handle, &m);
41 SetConsoleMode(*handle, (m&~ENABLE_ECHO_INPUT) | (e?ENABLE_ECHO_INPUT:0));
44 void Console::set_line_buffer(bool l)
49 if(!GetConsoleMode(*handle, &m))
50 throw system_error("GetConsoleMode");
51 if(!SetConsoleMode(*handle, (m&~ENABLE_LINE_INPUT) | (l?ENABLE_LINE_INPUT:0)))
52 throw system_error("SetConsoleMode");
55 void Console::get_size(unsigned &rows, unsigned &cols)
57 check_access(M_WRITE);
59 CONSOLE_SCREEN_BUFFER_INFO sbi;
60 if(!GetConsoleScreenBufferInfo(*handle, &sbi))
61 throw system_error("GetConsoleScreenBufferInfo");
62 // Right/bottom coords are inclusive
63 rows = sbi.srWindow.Bottom+1-sbi.srWindow.Top;
64 cols = sbi.srWindow.Right+1-sbi.srWindow.Left;
67 void Console::redirect(Base &other)
69 SetStdHandle(stream_to_sys(stream), *other.get_handle(mode));