mirror of
https://github.com/WerWolv/ImHex.git
synced 2026-03-30 13:05:25 -05:00
sys: Log to a file when ImHex wasn't opened though a terminal
This commit is contained in:
@@ -3,13 +3,18 @@
|
||||
#if defined(OS_LINUX)
|
||||
|
||||
#include <hex/helpers/utils.hpp>
|
||||
#include <hex/helpers/logger.hpp>
|
||||
|
||||
#include <nlohmann/json.hpp>
|
||||
#include <sys/wait.h>
|
||||
#include <unistd.h>
|
||||
|
||||
namespace hex {
|
||||
|
||||
void Window::initNative() {
|
||||
|
||||
if (!isatty(STDOUT_FILENO)) {
|
||||
log::redirectToFile();
|
||||
}
|
||||
}
|
||||
|
||||
void Window::setupNativeWindow() {
|
||||
|
||||
@@ -2,12 +2,17 @@
|
||||
|
||||
#if defined(OS_MACOS)
|
||||
|
||||
#include <hex/helpers/logger.hpp>
|
||||
|
||||
#include <nlohmann/json.hpp>
|
||||
#include <unistd.h>
|
||||
|
||||
namespace hex {
|
||||
|
||||
void Window::initNative() {
|
||||
|
||||
if (!isatty(STDOUT_FILENO)) {
|
||||
log::redirectToFile();
|
||||
}
|
||||
}
|
||||
|
||||
void Window::setupNativeWindow() {
|
||||
|
||||
@@ -172,25 +172,26 @@
|
||||
// Redirect cin, cout and cerr to that console
|
||||
freopen("CONIN$", "r", stdin);
|
||||
freopen("CONOUT$", "w", stdout);
|
||||
freopen("CONERR$", "w", stderr);
|
||||
freopen("CONOUT$", "w", stderr);
|
||||
setvbuf(stdin, nullptr, _IONBF, 0);
|
||||
setvbuf(stdout, nullptr, _IONBF, 0);
|
||||
setvbuf(stderr, nullptr, _IONBF, 0);
|
||||
|
||||
fmt::print("\n");
|
||||
}
|
||||
|
||||
|
||||
// Enable color format specifiers in console
|
||||
{
|
||||
auto hConsole = ::GetStdHandle(STD_OUTPUT_HANDLE);
|
||||
if (hConsole != INVALID_HANDLE_VALUE) {
|
||||
DWORD mode = 0;
|
||||
if (::GetConsoleMode(hConsole, &mode)) {
|
||||
mode |= ENABLE_VIRTUAL_TERMINAL_PROCESSING | ENABLE_PROCESSED_OUTPUT | ENABLE_WRAP_AT_EOL_OUTPUT;
|
||||
::SetConsoleMode(hConsole, mode);
|
||||
// Enable color format specifiers in console
|
||||
{
|
||||
auto hConsole = ::GetStdHandle(STD_OUTPUT_HANDLE);
|
||||
if (hConsole != INVALID_HANDLE_VALUE) {
|
||||
DWORD mode = 0;
|
||||
if (::GetConsoleMode(hConsole, &mode)) {
|
||||
mode |= ENABLE_VIRTUAL_TERMINAL_PROCESSING | ENABLE_PROCESSED_OUTPUT | ENABLE_WRAP_AT_EOL_OUTPUT;
|
||||
::SetConsoleMode(hConsole, mode);
|
||||
}
|
||||
}
|
||||
}
|
||||
} else {
|
||||
log::redirectToFile();
|
||||
}
|
||||
|
||||
// Open new files in already existing ImHex instance
|
||||
|
||||
Reference in New Issue
Block a user