-
Notifications
You must be signed in to change notification settings - Fork 766
/
Copy pathconsole.cpp
47 lines (39 loc) · 1.19 KB
/
console.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
#include <Windows.h>
#include <tchar.h>
#include "console.hpp"
#include "cpp_tstring.hpp"
_console::_console() {
this->output = GetStdHandle(STD_OUTPUT_HANDLE);
this->input = GetStdHandle(STD_INPUT_HANDLE);
this->error = GetStdHandle(STD_ERROR_HANDLE);
}
void _console::writeOutput(const TCHAR str[]) {
WriteConsole(this->output, str, lstrlen(str), NULL, NULL);
}
void _console::writeOutput(const tstring str) {
writeOutput(str.c_str());
}
void _console::writeError(const TCHAR str[]) {
WriteConsole(this->error, str, lstrlen(str), NULL, NULL);
}
void _console::writeError(const tstring str) {
writeError(str.c_str());
}
DWORD _console::readFixedSizeInput(TCHAR* str, const DWORD size, const PCONSOLE_READCONSOLE_CONTROL const pReadConsoleControl) {
for (size_t i = 0; i < size; i++) str[i] = 0;
DWORD length;
if (!ReadConsole(this->input, str, size, &length, pReadConsoleControl)) abort();
return length;
}
tstring _console::readInput() {
tstring input;
TCHAR currChar = TEXT('\0');
DWORD temp = 0;
while (currChar != TEXT('\n')) {
if (!ReadConsole(this->input, &currChar, 1, &temp, NULL)) abort();
input.push_back(currChar);
}
input.pop_back();
return input;
}
_console console = {};