-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathConUtils.cpp
More file actions
74 lines (67 loc) · 1.87 KB
/
ConUtils.cpp
File metadata and controls
74 lines (67 loc) · 1.87 KB
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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
#include "stdafx.h"
#include "ConUtils.h"
void CopyToClipboard(const wchar_t* pSrc, size_t len)
{
if (pSrc != nullptr && len > 0)
{
// TODO Convert EOL to '\r\n'
HGLOBAL hMem = NULL;
hMem = GlobalAlloc(GMEM_MOVEABLE, (len + 1) * sizeof(wchar_t));
wchar_t* pMem = static_cast<wchar_t*>(GlobalLock(hMem));
memcpy(pMem, pSrc, len * sizeof(wchar_t));
pMem[len] = L'\0';
GlobalUnlock(hMem);
OpenClipboard(0);
EmptyClipboard();
SetClipboardData(CF_UNICODETEXT, hMem);
CloseClipboard();
}
}
void SetCursorVisible(HANDLE hScreen, CONSOLE_CURSOR_INFO& cci, BOOL bVisible)
{
if (cci.bVisible != bVisible)
{
cci.bVisible = bVisible;
SetConsoleCursorInfo(hScreen, &cci);
}
}
void DrawBuffer(HANDLE hScreen, const Buffer& buffer, COORD posBuffer)
{
SMALL_RECT wr = Rectangle(posBuffer, buffer.size);
WriteConsoleOutput(hScreen, buffer.data.data(), buffer.size, _COORD(0, 0), &wr);
}
void Write(std::vector<CHAR_INFO>::iterator b, std::vector<CHAR_INFO>::iterator e, const wchar_t* s)
{
auto it = b;
const wchar_t* t = s;
while (it != e && *t != L'\0')
{
if (*t == L'\t')
{
for (int i = 0; i < 4; ++i) // TODO Should really be x - x%4
{
it->Char.UnicodeChar = L' ';
++it;
}
}
else
{
it->Char.UnicodeChar = *t;
++it;
}
++t;
}
}
void WriteBegin(Buffer& b, COORD o, const wchar_t* s)
{
// TODO Check bounds
auto it = b.data.begin() + b.offset(o);
Write(it, b.data.end(), s);
}
void WriteEnd(Buffer& b, COORD o, const wchar_t* s)
{
// TODO Check bounds
size_t offset = wcslen(s) < b.offset(o) ? b.offset(o) - wcslen(s) : 0;
auto it = b.data.begin() + offset;
Write(it, b.data.end(), s);
}