Skip to content

Commit

Permalink
linux wip
Browse files Browse the repository at this point in the history
Signed-off-by: Christian Parpart <[email protected]>
  • Loading branch information
christianparpart committed Apr 21, 2024
1 parent a506d15 commit 2543758
Show file tree
Hide file tree
Showing 4 changed files with 42 additions and 55 deletions.
12 changes: 0 additions & 12 deletions src/contour/ContourApp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -140,18 +140,6 @@ ContourApp::ContourApp(): app("contour", "Contour Terminal Emulator", CONTOUR_VE
signal(SIGABRT, segvHandler);
#endif

#if defined(_WIN32)
// Enable VT output processing on Conhost.
HANDLE stdoutHandle = GetStdHandle(STD_OUTPUT_HANDLE);
DWORD savedModes {}; // NOTE: Is it required to restore that upon process exit?
if (GetConsoleMode(stdoutHandle, &savedModes) != FALSE)
{
DWORD modes = savedModes;
modes |= ENABLE_VIRTUAL_TERMINAL_PROCESSING;
SetConsoleMode(stdoutHandle, modes);
}
#endif

link("contour.capture", bind(&ContourApp::captureAction, this));
link("contour.list-debug-tags", bind(&ContourApp::listDebugTagsAction, this));
link("contour.set.profile", bind(&ContourApp::profileAction, this));
Expand Down
43 changes: 38 additions & 5 deletions src/crispy/App.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,10 @@
#include <unistd.h>
#endif

#if defined(_WIN32)
#include <Windows.h>
#endif

using std::bind;
using std::cout;
using std::exception;
Expand Down Expand Up @@ -110,11 +114,7 @@ app::app(std::string appName, std::string appTitle, std::string appVersion, std:
_appLicense { std::move(appLicense) },
_localStateDir { xdgStateHome() / _appName }
{
if (char const* logFilterString = getenv("LOG"))
{
logstore::configure(logFilterString);
customizeLogStoreOutput();
}
basicSetup();

_instance = this;

Expand All @@ -128,6 +128,39 @@ app::~app()
_instance = nullptr;
}

void app::basicSetup() noexcept
{
enableVTProcessing();
enableUtf8Output();
if (char const* logFilterString = getenv("LOG"))
{
logstore::configure(logFilterString);
customizeLogStoreOutput();
}
}

void app::enableVTProcessing() noexcept
{
#if defined(_WIN32)
// Enable VT output processing on Conhost.
HANDLE stdoutHandle = GetStdHandle(STD_OUTPUT_HANDLE);
DWORD savedModes {}; // NOTE: Is it required to restore that upon process exit?
if (GetConsoleMode(stdoutHandle, &savedModes) != FALSE)
{
SetConsoleMode(stdoutHandle,
savedModes | ENABLE_VIRTUAL_TERMINAL_PROCESSING | ENABLE_PROCESSED_OUTPUT
| ENABLE_WRAP_AT_EOL_OUTPUT);
}
#endif
}

void app::enableUtf8Output() noexcept
{
#if defined(_WIN32)
SetConsoleOutputCP(CP_UTF8);
#endif
}

void app::link(std::string command, std::function<int()> handler)
{
_handlers[std::move(command)] = std::move(handler);
Expand Down
3 changes: 3 additions & 0 deletions src/crispy/App.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,9 @@ class app
[[nodiscard]] std::string const& appVersion() const noexcept { return _appVersion; }
[[nodiscard]] std::filesystem::path const& localStateDir() const noexcept { return _localStateDir; }

static void basicSetup() noexcept;
static void enableVTProcessing() noexcept;
static void enableUtf8Output() noexcept;
static void customizeLogStoreOutput();

protected:
Expand Down
39 changes: 1 addition & 38 deletions src/vtparser/Parser_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,6 @@
#include <vtparser/ParserEvents.h>

#include <crispy/App.h>
#include <crispy/logstore.h>

#include <crispy/escape.h>

#include <libunicode/convert.h>
Expand All @@ -13,10 +11,6 @@
#include <catch2/catch_session.hpp>
#include <catch2/catch_test_macros.hpp>

#if defined(_WIN32)
#include <Windows.h>
#endif

using namespace std;

class MockParserEvents final: public vtparser::NullParserEvents
Expand Down Expand Up @@ -101,40 +95,9 @@ TEST_CASE("Parser.APC")
REQUIRE(listener.text == "ABCDEF");
}

namespace
{

struct SetupTeardown
{
SetupTeardown()
{
#if defined(_WIN32)
const auto stdoutHandle = GetStdHandle(STD_OUTPUT_HANDLE);
const auto stdoutCP = GetConsoleOutputCP();
DWORD stdoutMode;
GetConsoleMode(stdoutHandle, &stdoutMode);
SetConsoleMode(stdoutHandle,
ENABLE_PROCESSED_OUTPUT | ENABLE_WRAP_AT_EOL_OUTPUT
| ENABLE_VIRTUAL_TERMINAL_PROCESSING);
SetConsoleOutputCP(CP_UTF8);
#endif

char const* logFilterString = getenv("LOG");
if (logFilterString)
{
logstore::configure(logFilterString);
crispy::app::customizeLogStoreOutput();
}
}

~SetupTeardown() = default;
};

} // namespace

int main(int argc, char const* argv[])
{
auto const _ = SetupTeardown {};
crispy::app::basicSetup();

int const result = Catch::Session().run(argc, argv);

Expand Down

0 comments on commit 2543758

Please sign in to comment.