diff --git a/src/core/windows.cpp b/src/core/windows.cpp index 6daec55..685f515 100755 --- a/src/core/windows.cpp +++ b/src/core/windows.cpp @@ -10,10 +10,10 @@ // Typically, you’d define this ID in a "resource.h" file and include it in both "icon.rc" and this file // However, I want to avoid any platform-specific files whenever possible -#include // for setlocale, LC_ALL -#include // for std::optional, std::nullopt -#include // for std::string -#include // for SetConsoleCP, SetConsoleOutputCP, GetLastError, HWND, HICON, LoadIcon, GetModuleHandle, MAKEINTRESOURCE, SendMessage, WM_SETICON, ICON_BIG, ICON_SMALL, LPARAM +#include // for std::optional, std::nullopt +#include // for std::string + +#include // for HWND, HICON, LoadIcon, GetModuleHandle, MAKEINTRESOURCE, GetLastError, SendMessage, WM_SETICON, ICON_BIG, ICON_SMALL, LPARAM #include #include @@ -22,18 +22,6 @@ namespace core::windows { -std::optional setup_utf8_console() -{ - if (!SetConsoleCP(CP_UTF8) || !SetConsoleOutputCP(CP_UTF8)) { - return fmt::format("Failed to set UTF-8 code page: {}", GetLastError()); - } - - if (!setlocale(LC_ALL, ".UTF8")) { - return "Failed to set UTF-8 locale"; - } - return std::nullopt; -} - std::optional setup_titlebar_icon(const sf::Window &window) { // Get the native window handle from the SFML window diff --git a/src/core/windows.hpp b/src/core/windows.hpp index a543504..c46e157 100644 --- a/src/core/windows.hpp +++ b/src/core/windows.hpp @@ -15,13 +15,6 @@ namespace core::windows { -/** - * @brief Setup UTF-8 input/output on Windows. Do nothing on other platforms. - * - * @return Error message if the setup failed, "std::nullopt" otherwise. - */ -[[nodiscard]] std::optional setup_utf8_console(); - /** * @brief Setup the titlebar icon on Windows using the embedded icon data (must be embedded by CMake). * diff --git a/src/main.cpp b/src/main.cpp index 6b11366..df1f7e4 100755 --- a/src/main.cpp +++ b/src/main.cpp @@ -6,12 +6,13 @@ #include // for std::exception #include - -#include "app.hpp" #if defined(_WIN32) -#include "core/windows.hpp" +#define WIN32_LEAN_AND_MEAN // Exclude rarely-used stuff from Windows headers +#include // for SetConsoleCP, SetConsoleOutputCP, CP_UTF8 #endif +#include "app.hpp" + /** * @brief Entry-point of the application. * @@ -19,16 +20,11 @@ */ int main() { - try { -#if defined(_WIN32) - // Boilerplate to make Windows behave more like *nix - - // Setup UTF-8 input/output and locale - if (const auto e = core::windows::setup_utf8_console(); e.has_value()) { - fmt::print(stderr, "Warning: {}\n", *e); - } +#if defined(_WIN32) // Setup UTF-8 input/output + SetConsoleCP(CP_UTF8); + SetConsoleOutputCP(CP_UTF8); #endif - + try { // Run the app app::run(); } diff --git a/tests/test_all.cpp b/tests/test_all.cpp index d4a9891..e810fc0 100644 --- a/tests/test_all.cpp +++ b/tests/test_all.cpp @@ -20,7 +20,8 @@ #include "core/string.hpp" #include "modules/vocabulary.hpp" #if defined(_WIN32) -#include "core/windows.hpp" +#define WIN32_LEAN_AND_MEAN // Exclude rarely-used stuff from Windows headers +#include // for SetConsoleCP, SetConsoleOutputCP, CP_UTF8 #endif namespace test_assets { @@ -53,11 +54,9 @@ namespace test_vocabulary { int main(int argc, char **argv) { -#if defined(_WIN32) - // Setup UTF-8 input/output on Windows (does nothing on other platforms) - if (const auto e = core::windows::setup_utf8_console(); e.has_value()) { - fmt::print(stderr, "Warning: {}\n", *e); - } +#if defined(_WIN32) // Setup UTF-8 input/output + SetConsoleCP(CP_UTF8); + SetConsoleOutputCP(CP_UTF8); #endif // Define the formatted help message