-
Notifications
You must be signed in to change notification settings - Fork 33
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
7 changed files
with
320 additions
and
55 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
<?xml version="1.0" encoding="UTF-8" standalone="yes"?> | ||
<assembly manifestVersion="1.0" xmlns="urn:schemas-microsoft-com:asm.v1" xmlns:asmv3="urn:schemas-microsoft-com:asm.v3"> | ||
<assemblyIdentity | ||
type="win32" | ||
name="borf.BrowEdit3" | ||
version="3.0.0.0" | ||
processorArchitecture="*" | ||
/> | ||
<description>BrowEdit 3</description> | ||
<compatibility xmlns="urn:schemas-microsoft-com:compatibility.v1"> | ||
<application> | ||
<!-- Windows 10 and Windows 11 --> | ||
<supportedOS Id="{8e0f7a12-bfb3-4fe8-b9a5-48fd50a15a9a}"/> | ||
<!-- Windows 8.1 --> | ||
<supportedOS Id="{1f676c76-80e1-4239-95bb-83d0f6d0da78}"/> | ||
<!-- Windows 8 --> | ||
<supportedOS Id="{4a2f28e3-53b9-4441-ba9c-d69d4a4a6e38}"/> | ||
<!-- Windows 7 --> | ||
<supportedOS Id="{35138b9a-5d96-4fbd-8e2d-a2440225f93a}"/> | ||
<!-- Windows Vista --> | ||
<supportedOS Id="{e2011457-1546-43c5-a5fe-008deee3d3f0}"/> | ||
</application> | ||
</compatibility> | ||
<trustInfo xmlns="urn:schemas-microsoft-com:asm.v3"> | ||
<security> | ||
<requestedPrivileges> | ||
<requestedExecutionLevel level="asInvoker" uiAccess="false" /> | ||
</requestedPrivileges> | ||
</security> | ||
</trustInfo> | ||
<asmv3:application> | ||
<asmv3:windowsSettings xmlns:ws2="http://schemas.microsoft.com/SMI/2016/WindowsSettings"> | ||
<!-- <ws2:longPathAware>true</ws2:longPathAware> --> | ||
</asmv3:windowsSettings> | ||
</asmv3:application> | ||
</assembly> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,144 @@ | ||
#include "Console.h" | ||
#include <iostream> | ||
#include <VersionHelpers.h> | ||
|
||
ConsoleInject::ConsoleInject() : | ||
#ifdef _WIN32 | ||
#ifdef ENABLE_VIRTUAL_TERMINAL_PROCESSING | ||
ansiEscape(IsWindows10OrGreater()), | ||
#else | ||
ansiEscape(false), | ||
#endif | ||
|
||
errorHandle(nullptr), | ||
|
||
consoleInputCP(CP_NONE), | ||
consoleOutputCP(CP_NONE), | ||
#else | ||
ansiEscape(true), | ||
#endif | ||
errorSink(ansiEscape) | ||
{ | ||
#ifdef _WIN32 | ||
errorHandle = GetStdHandle(STD_ERROR_HANDLE); | ||
|
||
consoleInputCP = GetConsoleCP(); | ||
consoleOutputCP = GetConsoleOutputCP(); | ||
|
||
SetConsoleCP(CP_UTF8); | ||
SetConsoleOutputCP(CP_UTF8); | ||
|
||
if (ansiEscape) | ||
{ | ||
#ifdef ENABLE_VIRTUAL_TERMINAL_PROCESSING | ||
DWORD mode = 0; | ||
/* | ||
auto input = GetStdHandle(STD_INPUT_HANDLE); | ||
GetConsoleMode(input, &mode); | ||
SetConsoleMode(input, mode | ENABLE_VIRTUAL_TERMINAL_INPUT); | ||
*/ | ||
|
||
auto output = GetStdHandle(STD_OUTPUT_HANDLE); | ||
GetConsoleMode(output, &mode); | ||
SetConsoleMode(output, mode | ENABLE_VIRTUAL_TERMINAL_PROCESSING); | ||
|
||
GetConsoleMode(errorHandle, &mode); | ||
SetConsoleMode(errorHandle, mode | ENABLE_VIRTUAL_TERMINAL_PROCESSING); | ||
#else | ||
// ToDo: check for ANSICON | ||
// #error ANSI escape sequences are only supported on Windows 10+, please install ANSICON (ANSI.sys) | ||
#endif | ||
} | ||
#endif | ||
} | ||
|
||
ConsoleInject::~ConsoleInject() | ||
{ | ||
#ifdef _WIN32 | ||
SetConsoleCP(consoleInputCP); | ||
SetConsoleOutputCP(consoleOutputCP); | ||
#endif | ||
} | ||
|
||
ConsoleInject::Sink::Sink(bool ansiEscape) : | ||
ansiEscape(ansiEscape), | ||
newLine(true), | ||
|
||
sink(), | ||
|
||
#ifdef _WIN32 | ||
consoleAttributes(0), | ||
consoleForgroundMask(FOREGROUND_RED | FOREGROUND_BLUE | FOREGROUND_GREEN | FOREGROUND_INTENSITY), | ||
consoleBackgroundMask(BACKGROUND_RED | BACKGROUND_BLUE | BACKGROUND_GREEN | BACKGROUND_INTENSITY) | ||
#endif | ||
{ | ||
#ifdef _WIN32 | ||
errorHandle = GetStdHandle(STD_ERROR_HANDLE); | ||
CONSOLE_SCREEN_BUFFER_INFO info = {}; | ||
GetConsoleScreenBufferInfo(errorHandle, &info); | ||
|
||
consoleAttributes = info.wAttributes; | ||
#endif | ||
} | ||
|
||
ConsoleInject::ErrorSink::ErrorSink(bool ansiEscape) : Sink(ansiEscape) | ||
{ | ||
sink = std::cerr.rdbuf(this); | ||
} | ||
|
||
ConsoleInject::ErrorSink::~ErrorSink() | ||
{ | ||
std::cerr.rdbuf(sink); | ||
} | ||
|
||
auto ConsoleInject::ErrorSink::overflow(int_type ch) -> int_type | ||
{ | ||
if (traits_type::eq_int_type( ch, traits_type::eof())) | ||
return sink->pubsync() == -1 ? ch : traits_type::not_eof(ch); | ||
|
||
if (newLine) | ||
{ | ||
if (ansiEscape) | ||
{ | ||
std::ostream str(sink); | ||
|
||
if (!(str << "\x1b[31;1m")) | ||
return traits_type::eof(); | ||
} | ||
else | ||
{ | ||
#ifdef _WIN32 | ||
auto attributes = consoleAttributes & ~(consoleForgroundMask | consoleBackgroundMask); | ||
SetConsoleTextAttribute(errorHandle, attributes | FOREGROUND_RED | FOREGROUND_INTENSITY); | ||
#endif | ||
} | ||
} | ||
|
||
newLine = traits_type::to_char_type(ch) == '\n'; | ||
|
||
if (newLine) | ||
{ | ||
if (ansiEscape) | ||
{ | ||
std::ostream str(sink); | ||
|
||
if (!(str << "\x1b[0m")) | ||
return traits_type::eof(); | ||
} | ||
else | ||
{ | ||
#ifdef _WIN32 | ||
SetConsoleTextAttribute(errorHandle, consoleAttributes); | ||
#endif | ||
} | ||
} | ||
|
||
auto out = sink->sputc(ch); | ||
if (out == traits_type::eof()) | ||
{ | ||
// ToDo: fix up unknown characters | ||
return sink->sputc('_'); | ||
} | ||
|
||
return out; | ||
} |
Oops, something went wrong.