Skip to content

Commit 711a83a

Browse files
authored
Merge pull request #60 from p0nce/console-colors
Speed-up when VT100 escape codes are enabled on the console
2 parents 3dde2a8 + f20d1b9 commit 711a83a

File tree

2 files changed

+12
-1
lines changed

2 files changed

+12
-1
lines changed

colorize/source/redub/libs/colorize/cwrite.d

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,12 @@ void cwrite(S...)(File f, S args)
4747
{
4848
WinTermEmulation winterm;
4949
winterm.initialize();
50+
if (winterm.supportVT100)
51+
{
52+
f.write(s);
53+
return;
54+
}
55+
5056
foreach(dchar c ; s)
5157
{
5258
auto charAction = winterm.feed(c);

colorize/source/redub/libs/colorize/winterm.d

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,12 +19,17 @@ version(Windows)
1919
struct WinTermEmulation
2020
{
2121
public:
22-
@nogc void initialize() nothrow
22+
bool supportVT100; // if true, that whole emulation is useless.
23+
24+
void initialize() nothrow
2325
{
2426
// saves console attributes
2527
_console = GetStdHandle(STD_OUTPUT_HANDLE);
2628
_savedInitialColor = (0 != GetConsoleScreenBufferInfo(_console, &consoleInfo));
2729
_state = State.initial;
30+
uint mode;
31+
if (GetConsoleMode(_console, &mode))
32+
supportVT100 = (mode & ENABLE_VIRTUAL_TERMINAL_INPUT) != 0;
2833
}
2934

3035
@nogc ~this() nothrow

0 commit comments

Comments
 (0)