add color term support and fix encoding error
This commit is contained in:
parent
209bb4ccb5
commit
3b754f0434
|
@ -102,6 +102,7 @@
|
|||
<ConformanceMode>true</ConformanceMode>
|
||||
<AdditionalIncludeDirectories>$(BOOST_INCLUDE_PATH);$(ZLIB_PATH);%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
|
||||
<LanguageStandard>stdcpp20</LanguageStandard>
|
||||
<AdditionalOptions>/utf-8 %(AdditionalOptions)</AdditionalOptions>
|
||||
</ClCompile>
|
||||
<Link>
|
||||
<SubSystem>Console</SubSystem>
|
||||
|
@ -119,6 +120,7 @@
|
|||
<ConformanceMode>true</ConformanceMode>
|
||||
<AdditionalIncludeDirectories>$(BOOST_INCLUDE_PATH);$(ZLIB_PATH);%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
|
||||
<LanguageStandard>stdcpp20</LanguageStandard>
|
||||
<AdditionalOptions>/utf-8 %(AdditionalOptions)</AdditionalOptions>
|
||||
</ClCompile>
|
||||
<Link>
|
||||
<SubSystem>Console</SubSystem>
|
||||
|
@ -136,6 +138,7 @@
|
|||
<ConformanceMode>true</ConformanceMode>
|
||||
<AdditionalIncludeDirectories>$(BOOST_INCLUDE_PATH);$(ZLIB_PATH);%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
|
||||
<LanguageStandard>stdcpp20</LanguageStandard>
|
||||
<AdditionalOptions>/utf-8 %(AdditionalOptions)</AdditionalOptions>
|
||||
</ClCompile>
|
||||
<Link>
|
||||
<SubSystem>Console</SubSystem>
|
||||
|
@ -155,6 +158,7 @@
|
|||
<ConformanceMode>true</ConformanceMode>
|
||||
<AdditionalIncludeDirectories>$(BOOST_INCLUDE_PATH);$(ZLIB_PATH);%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
|
||||
<LanguageStandard>stdcpp20</LanguageStandard>
|
||||
<AdditionalOptions>/utf-8 %(AdditionalOptions)</AdditionalOptions>
|
||||
</ClCompile>
|
||||
<Link>
|
||||
<SubSystem>Console</SubSystem>
|
||||
|
|
42
Unvirt/ColorfulTerminal.cpp
Normal file
42
Unvirt/ColorfulTerminal.cpp
Normal file
|
@ -0,0 +1,42 @@
|
|||
#include "ColorfulTerminal.hpp"
|
||||
#include <VTUtils.hpp>
|
||||
|
||||
#if defined(LIBCMO_OS_WIN32)
|
||||
#include <Windows.h>
|
||||
#include <cstdio>
|
||||
#include <io.h>
|
||||
#endif
|
||||
|
||||
namespace Unvirt {
|
||||
namespace ColorfulTerminal {
|
||||
|
||||
// all of these functions only works on Windows platform
|
||||
// due to shitty Windows implementations.
|
||||
|
||||
bool EnsureTerminalColor(void) {
|
||||
#if defined(LIBCMO_OS_WIN32)
|
||||
if (_isatty(_fileno(stdout))) {
|
||||
HANDLE h_output;
|
||||
DWORD dw_mode;
|
||||
|
||||
h_output = (HANDLE)_get_osfhandle(_fileno(stdout));
|
||||
if (!GetConsoleMode(h_output, &dw_mode)) return false;
|
||||
if (!SetConsoleMode(h_output, dw_mode | ENABLE_VIRTUAL_TERMINAL_PROCESSING)) return false;
|
||||
|
||||
return true;
|
||||
} else return false;
|
||||
#else
|
||||
return true;
|
||||
#endif
|
||||
}
|
||||
|
||||
bool EnsureTerminalEncoding(void) {
|
||||
#if defined(LIBCMO_OS_WIN32)
|
||||
if (!SetConsoleCP(CP_UTF8)) return false;
|
||||
if (!SetConsoleOutputCP(CP_UTF8)) return false;
|
||||
#endif
|
||||
return true;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
31
Unvirt/ColorfulTerminal.hpp
Normal file
31
Unvirt/ColorfulTerminal.hpp
Normal file
|
@ -0,0 +1,31 @@
|
|||
#pragma once
|
||||
|
||||
namespace Unvirt{
|
||||
namespace ColorfulTerminal {
|
||||
|
||||
#define UNVIRT_REMOVE_PARENS_IMPL(...) __VA_ARGS__
|
||||
#define UNVIRT_REMOVE_PARENS(T) UNVIRT_REMOVE_PARENS_IMPL T
|
||||
|
||||
#define UNVIRT_TERMCOL_BLACK(T) "\033[30m" UNVIRT_REMOVE_PARENS(T) "\033[0m"
|
||||
#define UNVIRT_TERMCOL_RED(T) "\033[31m" UNVIRT_REMOVE_PARENS(T) "\033[0m"
|
||||
#define UNVIRT_TERMCOL_GREEN(T) "\033[32m" UNVIRT_REMOVE_PARENS(T) "\033[0m"
|
||||
#define UNVIRT_TERMCOL_YELLOW(T) "\033[33m" UNVIRT_REMOVE_PARENS(T) "\033[0m"
|
||||
#define UNVIRT_TERMCOL_BLUE(T) "\033[34m" UNVIRT_REMOVE_PARENS(T) "\033[0m"
|
||||
#define UNVIRT_TERMCOL_MAGENTA(T) "\033[35m" UNVIRT_REMOVE_PARENS(T) "\033[0m"
|
||||
#define UNVIRT_TERMCOL_CYAN(T) "\033[36m" UNVIRT_REMOVE_PARENS(T) "\033[0m"
|
||||
#define UNVIRT_TERMCOL_WHITE(T) "\033[37m" UNVIRT_REMOVE_PARENS(T) "\033[0m"
|
||||
|
||||
#define UNVIRT_TERMCOL_LIGHT_BLACK(T) "\033[90m" UNVIRT_REMOVE_PARENS(T) "\033[0m"
|
||||
#define UNVIRT_TERMCOL_LIGHT_RED(T) "\033[91m" UNVIRT_REMOVE_PARENS(T) "\033[0m"
|
||||
#define UNVIRT_TERMCOL_LIGHT_GREEN(T) "\033[92m" UNVIRT_REMOVE_PARENS(T) "\033[0m"
|
||||
#define UNVIRT_TERMCOL_LIGHT_YELLOW(T) "\033[93m" UNVIRT_REMOVE_PARENS(T) "\033[0m"
|
||||
#define UNVIRT_TERMCOL_LIGHT_BLUE(T) "\033[94m" UNVIRT_REMOVE_PARENS(T) "\033[0m"
|
||||
#define UNVIRT_TERMCOL_LIGHT_MAGENTA(T) "\033[95m" UNVIRT_REMOVE_PARENS(T) "\033[0m"
|
||||
#define UNVIRT_TERMCOL_LIGHT_CYAN(T) "\033[96m" UNVIRT_REMOVE_PARENS(T) "\033[0m"
|
||||
#define UNVIRT_TERMCOL_LIGHT_WHITE(T) "\033[97m" UNVIRT_REMOVE_PARENS(T) "\033[0m"
|
||||
|
||||
bool EnsureTerminalColor(void);
|
||||
bool EnsureTerminalEncoding(void);
|
||||
|
||||
}
|
||||
}
|
|
@ -1,11 +1,17 @@
|
|||
#include "AccessibleValue.hpp"
|
||||
#include "ColorfulTerminal.hpp"
|
||||
#include "VTStruct.hpp"
|
||||
#include <cstdio>
|
||||
|
||||
int main(int argc, char* argv[]) {
|
||||
Unvirt::ColorfulTerminal::EnsureTerminalColor();
|
||||
Unvirt::ColorfulTerminal::EnsureTerminalEncoding();
|
||||
|
||||
LibCmo::Utils::VirtoolsContext vtctx;
|
||||
LibCmo::CKFile vtfile(vtctx);
|
||||
vtfile.Load("Language.old.nmo", LibCmo::CK_LOAD_FLAGS::CK_LOAD_DEFAULT);
|
||||
|
||||
printf(UNVIRT_TERMCOL_LIGHT_YELLOW(("Hello, %s")), u8"㴮!");
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
|
|
@ -102,6 +102,7 @@
|
|||
<ConformanceMode>true</ConformanceMode>
|
||||
<AdditionalIncludeDirectories>$(BOOST_INCLUDE_PATH);$(ZLIB_PATH);../LibCmo;$(SQLITE_HEADER_PATH);%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
|
||||
<LanguageStandard>stdcpp20</LanguageStandard>
|
||||
<AdditionalOptions>/utf-8 %(AdditionalOptions)</AdditionalOptions>
|
||||
</ClCompile>
|
||||
<Link>
|
||||
<SubSystem>Console</SubSystem>
|
||||
|
@ -120,6 +121,7 @@
|
|||
<ConformanceMode>true</ConformanceMode>
|
||||
<AdditionalIncludeDirectories>$(BOOST_INCLUDE_PATH);$(ZLIB_PATH);../LibCmo;$(SQLITE_HEADER_PATH);%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
|
||||
<LanguageStandard>stdcpp20</LanguageStandard>
|
||||
<AdditionalOptions>/utf-8 %(AdditionalOptions)</AdditionalOptions>
|
||||
</ClCompile>
|
||||
<Link>
|
||||
<SubSystem>Console</SubSystem>
|
||||
|
@ -138,6 +140,7 @@
|
|||
<ConformanceMode>true</ConformanceMode>
|
||||
<AdditionalIncludeDirectories>$(BOOST_INCLUDE_PATH);$(ZLIB_PATH);../LibCmo;$(SQLITE_HEADER_PATH);%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
|
||||
<LanguageStandard>stdcpp20</LanguageStandard>
|
||||
<AdditionalOptions>/utf-8 %(AdditionalOptions)</AdditionalOptions>
|
||||
</ClCompile>
|
||||
<Link>
|
||||
<SubSystem>Console</SubSystem>
|
||||
|
@ -156,6 +159,7 @@
|
|||
<ConformanceMode>true</ConformanceMode>
|
||||
<AdditionalIncludeDirectories>$(BOOST_INCLUDE_PATH);$(ZLIB_PATH);../LibCmo;$(SQLITE_HEADER_PATH);%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
|
||||
<LanguageStandard>stdcpp20</LanguageStandard>
|
||||
<AdditionalOptions>/utf-8 %(AdditionalOptions)</AdditionalOptions>
|
||||
</ClCompile>
|
||||
<Link>
|
||||
<SubSystem>Console</SubSystem>
|
||||
|
@ -168,11 +172,13 @@
|
|||
</ItemDefinitionGroup>
|
||||
<ItemGroup>
|
||||
<ClCompile Include="AccessibleValue.cpp" />
|
||||
<ClCompile Include="ColorfulTerminal.cpp" />
|
||||
<ClCompile Include="StringHelper.cpp" />
|
||||
<ClCompile Include="Unvirt.cpp" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ClInclude Include="AccessibleValue.hpp" />
|
||||
<ClInclude Include="ColorfulTerminal.hpp" />
|
||||
<ClInclude Include="StringHelper.hpp" />
|
||||
</ItemGroup>
|
||||
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
|
||||
|
|
|
@ -24,6 +24,9 @@
|
|||
<ClCompile Include="StringHelper.cpp">
|
||||
<Filter>Sources</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="ColorfulTerminal.cpp">
|
||||
<Filter>Sources</Filter>
|
||||
</ClCompile>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ClInclude Include="AccessibleValue.hpp">
|
||||
|
@ -32,5 +35,8 @@
|
|||
<ClInclude Include="StringHelper.hpp">
|
||||
<Filter>Headers</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="ColorfulTerminal.hpp">
|
||||
<Filter>Headers</Filter>
|
||||
</ClInclude>
|
||||
</ItemGroup>
|
||||
</Project>
|
Loading…
Reference in New Issue
Block a user