151 lines
3.2 KiB
C++
151 lines
3.2 KiB
C++
/***
|
|
Copyright (C) 2021 J Reece Wilson (a/k/a "Reece"). All rights reserved.
|
|
|
|
File: Console.cpp
|
|
Date: 2021-6-8
|
|
Author: Reece
|
|
***/
|
|
#include <Source/RuntimeInternal.hpp>
|
|
#include "Console.hpp"
|
|
#include "Commands/Commands.hpp"
|
|
#include "Hooks/Hooks.hpp"
|
|
#include "Logging/AuLogger.hpp"
|
|
#include "ConsoleStd/ConsoleStd.hpp"
|
|
#include "ConsoleWxWidgets/ConsoleWxWidgets.hpp"
|
|
#include "ConsoleFIO/ConsoleFIO.hpp"
|
|
#include "ConsoleTTY/ConsoleTTY.hpp"
|
|
#include "Flusher.hpp"
|
|
|
|
namespace Aurora::Console
|
|
{
|
|
static AuList<AuSPtr<Logging::IBasicSink>> gDefaultSinks;
|
|
|
|
void AddDefaultLogger(const AuSPtr<Logging::IBasicSink> &logger)
|
|
{
|
|
gDefaultSinks.push_back(logger);
|
|
}
|
|
|
|
AuSPtr<Logging::ILogger> CreateDefaultLogger()
|
|
{
|
|
return Logging::NewLoggerShared(gDefaultSinks);
|
|
}
|
|
|
|
static void FinailizeDefaultLogger()
|
|
{
|
|
gDefaultLogger = CreateDefaultLogger();
|
|
//gDefaultSinks.clear();
|
|
}
|
|
|
|
AUKN_SYM AuSPtr<AuLoop::ILoopSource> StdInBufferLoopSource()
|
|
{
|
|
return ConsoleStd::GetLoopSource();
|
|
}
|
|
|
|
AUKN_SYM AuSPtr<Logging::ILogger> GetDefaultLogInterface()
|
|
{
|
|
return gDefaultLogger;
|
|
}
|
|
|
|
AUKN_SYM AuUInt32 ReadStdIn(void *buffer, AuUInt32 length)
|
|
{
|
|
return ConsoleStd::ReadStdIn(buffer, length);
|
|
}
|
|
|
|
AUKN_SYM AuUInt32 WriteStdOut(const void *buffer, AuUInt32 length)
|
|
{
|
|
return ConsoleStd::WriteStdOut(buffer, length);
|
|
}
|
|
|
|
AUKN_SYM bool DispatchRawLine(const AuString &string)
|
|
{
|
|
if (Hooks::gExternalLineProcessor)
|
|
{
|
|
Commands::RunCommandFunction([&string]()
|
|
{
|
|
Hooks::gExternalLineProcessor->OnProcessedLineUTF8(string);
|
|
});
|
|
return true;
|
|
}
|
|
|
|
return Commands::DispatchCommand(string);
|
|
}
|
|
|
|
void Init()
|
|
{
|
|
Hooks::Init();
|
|
ConsoleStd::Init();
|
|
ConsoleWxWidgets::Init();
|
|
|
|
#if defined(AURORA_IS_MODERNNT_DERIVED) && (defined(STAGING) || defined(DEBUG))
|
|
#if defined(STAGING)
|
|
if (IsDebuggerPresent())
|
|
{
|
|
#endif
|
|
AddDefaultLogger(NewDebugLoggerShared());
|
|
#if defined(STAGING)
|
|
}
|
|
#endif
|
|
#endif
|
|
}
|
|
|
|
void Init2()
|
|
{
|
|
ConsoleFIO::Init();
|
|
ConsoleTTY::Init();
|
|
|
|
FinailizeDefaultLogger();
|
|
Logging::InitLoggers();
|
|
}
|
|
|
|
void PumpOnMain()
|
|
{
|
|
Commands::PumpCommands();
|
|
ConsoleStd::Pump();
|
|
}
|
|
|
|
// dumb
|
|
void PumpOffMain()
|
|
{
|
|
ConsoleWxWidgets::Pump();
|
|
ConsoleFIO::Pump();
|
|
ConsoleTTY::Pump();
|
|
}
|
|
|
|
void Pump()
|
|
{
|
|
PumpOnMain();
|
|
PumpOffMain();
|
|
}
|
|
|
|
void Exit()
|
|
{
|
|
try
|
|
{
|
|
ConsoleTTY::PumpForce();
|
|
}
|
|
catch (...)
|
|
{
|
|
|
|
}
|
|
ConsoleStd::Flush();
|
|
gDefaultSinks.clear();
|
|
gDefaultLogger.reset();
|
|
Logging::DeinitLoggers();
|
|
ConsoleTTY::Exit();
|
|
ConsoleFIO::Exit();
|
|
ConsoleWxWidgets::Exit();
|
|
ConsoleStd::Exit();
|
|
Hooks::Deinit();
|
|
}
|
|
|
|
AUKN_SYM void OpenLateStd()
|
|
{
|
|
ConsoleStd::Start();
|
|
FinailizeDefaultLogger();
|
|
}
|
|
|
|
AUKN_SYM void OpenLateGUI()
|
|
{
|
|
ConsoleWxWidgets::Start();
|
|
}
|
|
} |