From 85e1c1e5a3edfba699bfc14f37a5c71e24146dfd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mart=C3=ADn=20Lucas=20Golini?= Date: Mon, 4 Jul 2022 00:55:50 -0300 Subject: [PATCH] More refactor. --- .../eterm/include/eterm/system/autohandle.hpp | 2 +- .../eterm/include/eterm/system/ipipe.hpp | 2 +- .../eterm/include/eterm/system/iprocess.hpp | 2 +- .../include/eterm/system/iprocessfactory.hpp | 5 +- .../eterm/include/eterm/system/pipe.hpp | 2 +- .../eterm/include/eterm/system/process.hpp | 5 +- .../include/eterm/system/processfactory.hpp | 5 +- .../eterm/terminal/ipseudoterminal.hpp | 6 +- .../eterm/terminal/iterminaldisplay.hpp | 6 +- .../include/eterm/terminal/pseudoterminal.hpp | 9 +- .../eterm/terminal/terminaldisplay.hpp | 7 +- .../eterm/terminal/terminalemulator.hpp | 6 +- .../include/eterm/terminal/terminaltypes.hpp | 4 +- .../eterm/src/eterm/system/autohandle.cpp | 2 +- src/modules/eterm/src/eterm/system/pipe.cpp | 4 +- .../eterm/src/eterm/system/process.cpp | 89 +++++++++++-------- .../eterm/src/eterm/system/processfactory.cpp | 6 +- .../src/eterm/terminal/iterminaldisplay.cpp | 4 +- .../src/eterm/terminal/pseudoterminal.cpp | 14 ++- .../src/eterm/terminal/terminaldisplay.cpp | 6 +- .../src/eterm/terminal/terminalemulator.cpp | 6 +- .../src/eterm/terminal/windowserrors.hpp | 9 +- src/tools/eterm/eterm.cpp | 33 +++++-- 23 files changed, 149 insertions(+), 85 deletions(-) diff --git a/src/modules/eterm/include/eterm/system/autohandle.hpp b/src/modules/eterm/include/eterm/system/autohandle.hpp index c677677b5..c1ce15e86 100644 --- a/src/modules/eterm/include/eterm/system/autohandle.hpp +++ b/src/modules/eterm/include/eterm/system/autohandle.hpp @@ -22,7 +22,7 @@ // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER // DEALINGS IN THE SOFTWARE. -namespace EE { namespace System { +namespace eterm { namespace System { // This class is designed to automatically free a resource handle when destructed class AutoHandle final { diff --git a/src/modules/eterm/include/eterm/system/ipipe.hpp b/src/modules/eterm/include/eterm/system/ipipe.hpp index 5293ad4ad..fd3a22f38 100644 --- a/src/modules/eterm/include/eterm/system/ipipe.hpp +++ b/src/modules/eterm/include/eterm/system/ipipe.hpp @@ -24,7 +24,7 @@ #include #include -namespace EE { namespace System { +namespace eterm { namespace System { class IPipe { public: diff --git a/src/modules/eterm/include/eterm/system/iprocess.hpp b/src/modules/eterm/include/eterm/system/iprocess.hpp index 89766cadb..fd2b93109 100644 --- a/src/modules/eterm/include/eterm/system/iprocess.hpp +++ b/src/modules/eterm/include/eterm/system/iprocess.hpp @@ -22,7 +22,7 @@ // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER // DEALINGS IN THE SOFTWARE. -namespace EE { namespace System { +namespace eterm { namespace System { enum class ProcessStatus { RUNNING = 0, EXITED }; diff --git a/src/modules/eterm/include/eterm/system/iprocessfactory.hpp b/src/modules/eterm/include/eterm/system/iprocessfactory.hpp index e60a84fc7..9d6e18c6d 100644 --- a/src/modules/eterm/include/eterm/system/iprocessfactory.hpp +++ b/src/modules/eterm/include/eterm/system/iprocessfactory.hpp @@ -28,9 +28,10 @@ #include #include -using namespace EE::Terminal; +using namespace eterm::System; +using namespace eterm::Terminal; -namespace EE { namespace System { +namespace eterm { namespace System { class IProcessFactory { public: diff --git a/src/modules/eterm/include/eterm/system/pipe.hpp b/src/modules/eterm/include/eterm/system/pipe.hpp index cc791a250..6be432d39 100644 --- a/src/modules/eterm/include/eterm/system/pipe.hpp +++ b/src/modules/eterm/include/eterm/system/pipe.hpp @@ -25,7 +25,7 @@ #include #include -namespace EE { namespace System { +namespace eterm { namespace System { class Process; diff --git a/src/modules/eterm/include/eterm/system/process.hpp b/src/modules/eterm/include/eterm/system/process.hpp index 889fa6329..b17579678 100644 --- a/src/modules/eterm/include/eterm/system/process.hpp +++ b/src/modules/eterm/include/eterm/system/process.hpp @@ -28,7 +28,7 @@ #include #include -namespace EE { namespace System { +namespace eterm { namespace System { class Process final : public IProcess { public: @@ -70,8 +70,9 @@ class Process final : public IProcess { bool mLeaveRunning{ false }; AutoHandle mProcessHandle; void* mLpAttributeList; + int mPID; - Process( AutoHandle&& processHandle, void* lpAttributeList ); + Process( AutoHandle&& processHandle, void* lpAttributeList, int pid ); #else int mPID; diff --git a/src/modules/eterm/include/eterm/system/processfactory.hpp b/src/modules/eterm/include/eterm/system/processfactory.hpp index 302f2c0aa..0428f9cb3 100644 --- a/src/modules/eterm/include/eterm/system/processfactory.hpp +++ b/src/modules/eterm/include/eterm/system/processfactory.hpp @@ -23,9 +23,10 @@ // DEALINGS IN THE SOFTWARE. #include -using namespace EE::Terminal; +using namespace eterm::System; +using namespace eterm::Terminal; -namespace EE { namespace System { +namespace eterm { namespace System { class ProcessFactory : public IProcessFactory { public: diff --git a/src/modules/eterm/include/eterm/terminal/ipseudoterminal.hpp b/src/modules/eterm/include/eterm/terminal/ipseudoterminal.hpp index 2abf14704..a6156a358 100644 --- a/src/modules/eterm/include/eterm/terminal/ipseudoterminal.hpp +++ b/src/modules/eterm/include/eterm/terminal/ipseudoterminal.hpp @@ -24,9 +24,9 @@ #include #include -namespace EE { namespace Terminal { +namespace eterm { namespace Terminal { -class IPseudoTerminal : public EE::System::IPipe { +class IPseudoTerminal : public eterm::System::IPipe { public: IPseudoTerminal() = default; @@ -47,6 +47,6 @@ class IPseudoTerminal : public EE::System::IPipe { virtual bool resize( int columns, int rows ) = 0; }; -}} // namespace EE::Terminal +}} // namespace eterm::Terminal #endif diff --git a/src/modules/eterm/include/eterm/terminal/iterminaldisplay.hpp b/src/modules/eterm/include/eterm/terminal/iterminaldisplay.hpp index f0ded5003..6bb5d9c3b 100644 --- a/src/modules/eterm/include/eterm/terminal/iterminaldisplay.hpp +++ b/src/modules/eterm/include/eterm/terminal/iterminaldisplay.hpp @@ -24,7 +24,9 @@ #include #include -namespace EE { namespace Terminal { +using namespace EE; + +namespace eterm { namespace Terminal { class TerminalEmulator; @@ -87,6 +89,6 @@ class ITerminalDisplay { virtual void onProcessExit( int exitCode ); }; -}} // namespace EE::Terminal +}} // namespace eterm::Terminal #endif diff --git a/src/modules/eterm/include/eterm/terminal/pseudoterminal.hpp b/src/modules/eterm/include/eterm/terminal/pseudoterminal.hpp index 34107154d..aebab07b0 100644 --- a/src/modules/eterm/include/eterm/terminal/pseudoterminal.hpp +++ b/src/modules/eterm/include/eterm/terminal/pseudoterminal.hpp @@ -27,15 +27,14 @@ #include using namespace EE::Math; +using namespace eterm::System; -namespace EE { +namespace eterm { namespace System { class Process; } -using namespace EE::System; - namespace Terminal { class PseudoTerminal final : public IPseudoTerminal { @@ -62,7 +61,7 @@ class PseudoTerminal final : public IPseudoTerminal { static std::unique_ptr create( int columns, int rows ); private: - friend class ::EE::System::Process; + friend class ::eterm::System::Process; #ifdef _WIN32 Vector2i mSize; @@ -84,6 +83,6 @@ class PseudoTerminal final : public IPseudoTerminal { #endif }; } // namespace Terminal -} // namespace EE +} // namespace eterm #endif diff --git a/src/modules/eterm/include/eterm/terminal/terminaldisplay.hpp b/src/modules/eterm/include/eterm/terminal/terminaldisplay.hpp index 84b75c657..f8080d315 100644 --- a/src/modules/eterm/include/eterm/terminal/terminaldisplay.hpp +++ b/src/modules/eterm/include/eterm/terminal/terminaldisplay.hpp @@ -18,9 +18,12 @@ #include using namespace EE; -using namespace EE::Terminal; using namespace EE::Window; using namespace EE::System; +using namespace eterm::System; +using namespace eterm::Terminal; + +namespace eterm { namespace Terminal { enum class TerminalShortcutAction { PASTE, @@ -286,4 +289,6 @@ class TerminalDisplay : public ITerminalDisplay { void drawFrameBuffer(); }; +}} // namespace eterm::Terminal + #endif // ETERM_TERMINALDISPLAY_HPP diff --git a/src/modules/eterm/include/eterm/terminal/terminalemulator.hpp b/src/modules/eterm/include/eterm/terminal/terminalemulator.hpp index cc5434f14..2048ec0d4 100644 --- a/src/modules/eterm/include/eterm/terminal/terminalemulator.hpp +++ b/src/modules/eterm/include/eterm/terminal/terminalemulator.hpp @@ -46,11 +46,11 @@ #include using namespace EE; -using namespace EE::System; using namespace EE::Math; using namespace EE::Window; +using namespace eterm::System; -namespace EE { namespace Terminal { +namespace eterm { namespace Terminal { constexpr int ESC_BUF_SIZ = 512; constexpr int ESC_ARG_SIZ = 16; @@ -324,6 +324,6 @@ class TerminalEmulator final { const size_t& historySize = 1000 ); }; -}} // namespace EE::Terminal +}} // namespace eterm::Terminal #endif diff --git a/src/modules/eterm/include/eterm/terminal/terminaltypes.hpp b/src/modules/eterm/include/eterm/terminal/terminaltypes.hpp index 8261e7fda..4269e5d4f 100644 --- a/src/modules/eterm/include/eterm/terminal/terminaltypes.hpp +++ b/src/modules/eterm/include/eterm/terminal/terminaltypes.hpp @@ -26,7 +26,7 @@ #include #include -namespace EE { namespace Terminal { +namespace eterm { namespace Terminal { enum TerminalCursorMode { BlinkingBlock = 0, @@ -174,6 +174,6 @@ struct TerminalSelection { int alt; }; -}} // namespace EE::Terminal +}} // namespace eterm::Terminal #endif diff --git a/src/modules/eterm/src/eterm/system/autohandle.cpp b/src/modules/eterm/src/eterm/system/autohandle.cpp index 9bf5cc28d..0ef1a9bc3 100644 --- a/src/modules/eterm/src/eterm/system/autohandle.cpp +++ b/src/modules/eterm/src/eterm/system/autohandle.cpp @@ -27,7 +27,7 @@ #include #endif -namespace EE { namespace System { +namespace eterm { namespace System { AutoHandle::AutoHandle() : mHandle( invalid_value() ) {} AutoHandle::AutoHandle( AutoHandle&& other ) : mHandle( other.mHandle ) { diff --git a/src/modules/eterm/src/eterm/system/pipe.cpp b/src/modules/eterm/src/eterm/system/pipe.cpp index 5a8c37a03..19255af1d 100644 --- a/src/modules/eterm/src/eterm/system/pipe.cpp +++ b/src/modules/eterm/src/eterm/system/pipe.cpp @@ -3,7 +3,7 @@ #include #include -using namespace EE::System; +namespace eterm { namespace System { Pipe::Pipe( AutoHandle&& readHandle, AutoHandle&& writeHandle ) : mInputHandle( std::move( readHandle ) ), mOutputHandle( std::move( writeHandle ) ) {} @@ -49,4 +49,6 @@ int Pipe::read( char* buf, size_t n, bool block ) { return (int)read; } +}} + #endif diff --git a/src/modules/eterm/src/eterm/system/process.cpp b/src/modules/eterm/src/eterm/system/process.cpp index b2e72cd8c..8b35c6dc5 100644 --- a/src/modules/eterm/src/eterm/system/process.cpp +++ b/src/modules/eterm/src/eterm/system/process.cpp @@ -22,6 +22,7 @@ #ifndef _WIN32 #include +#include #include #include #include @@ -44,6 +45,8 @@ using namespace EE::System; +namespace eterm { namespace System { + Process::~Process() { if ( mPID != -1 ) { kill( mPID, SIGHUP ); @@ -92,7 +95,7 @@ void Process::waitForExit() { } bool Process::hasExited() const { - return mStatus == EE::System::ProcessStatus::EXITED; + return mStatus == ProcessStatus::EXITED; } int Process::getExitCode() const { @@ -197,6 +200,8 @@ Process::createWithPseudoTerminal( const std::string& program, const std::vector return nullptr; } +}} // namespace eterm::System + #else #include @@ -208,9 +213,10 @@ Process::createWithPseudoTerminal( const std::string& program, const std::vector #define NTDDI_VERSION NTDDI_WIN10_RS5 #include -using namespace EE::System; using namespace EE; +namespace eterm { namespace System { + static std::wstring stringToWideString( const std::string& str ) { if ( str.empty() ) return std::wstring(); @@ -223,46 +229,48 @@ static std::wstring stringToWideString( const std::string& str ) { #define HANDLE_WIN_ERR( err ) HRESULT_FROM_WIN32( err ), PrintWinApiError( err ) static HRESULT InitializeStartupInfoAttachedToPseudoConsole( STARTUPINFOEXW* pStartupInfo, - HPCON hPC ) { - HRESULT hr{ E_UNEXPECTED }; + HPCON hpc ) { + // Prepare Startup Information structure + STARTUPINFOEXW si; + ZeroMemory( &si, sizeof( si ) ); + si.StartupInfo.cb = sizeof( STARTUPINFOEXW ); - if ( pStartupInfo ) { - SIZE_T attrListSize{}; + // Discover the size required for the list + SIZE_T bytesRequired; + InitializeProcThreadAttributeList( NULL, 1, 0, &bytesRequired ); - pStartupInfo->StartupInfo.cb = sizeof( STARTUPINFOEXW ); - // pStartupInfo->StartupInfo.dwFlags = STARTF_USESTDHANDLES; - - // Get the size of the thread attribute list. - InitializeProcThreadAttributeList( NULL, 1, 0, &attrListSize ); - - // Allocate a thread attribute list of the correct size - pStartupInfo->lpAttributeList = reinterpret_cast( - HeapAlloc( GetProcessHeap(), 0, attrListSize ) ); - - // Initialize thread attribute list - if ( pStartupInfo->lpAttributeList && - InitializeProcThreadAttributeList( pStartupInfo->lpAttributeList, 1, 0, - &attrListSize ) ) { - // Set Pseudo Console attribute - hr = UpdateProcThreadAttribute( pStartupInfo->lpAttributeList, 0, - PROC_THREAD_ATTRIBUTE_PSEUDOCONSOLE, hPC, sizeof( hPC ), - NULL, NULL ) - ? S_OK - : HANDLE_WIN_ERR( GetLastError() ); - printf( "errrr1: %ld", hr ); - } else { - hr = HANDLE_WIN_ERR( GetLastError() ); - } + // Allocate memory to represent the list + si.lpAttributeList = + (PPROC_THREAD_ATTRIBUTE_LIST)HeapAlloc( GetProcessHeap(), 0, bytesRequired ); + if ( !si.lpAttributeList ) { + return E_OUTOFMEMORY; } - return hr; + + // Initialize the list memory location + if ( !InitializeProcThreadAttributeList( si.lpAttributeList, 1, 0, &bytesRequired ) ) { + HeapFree( GetProcessHeap(), 0, si.lpAttributeList ); + return HRESULT_FROM_WIN32( GetLastError() ); + } + + // Set the pseudoconsole information into the list + if ( !UpdateProcThreadAttribute( si.lpAttributeList, 0, PROC_THREAD_ATTRIBUTE_PSEUDOCONSOLE, + hpc, sizeof( hpc ), NULL, NULL ) ) { + HeapFree( GetProcessHeap(), 0, si.lpAttributeList ); + return HRESULT_FROM_WIN32( GetLastError() ); + } + + *pStartupInfo = si; + + return S_OK; } -Process::Process( AutoHandle&& hProcess, void* lpAttributeList ) : +Process::Process( AutoHandle&& hProcess, void* lpAttributeList, int pid ) : mStatus( ProcessStatus::RUNNING ), - mLeaveRunning( false ), mExitCode( 1 ), + mLeaveRunning( false ), mProcessHandle( std::move( hProcess ) ), - mLpAttributeList( lpAttributeList ) {} + mLpAttributeList( lpAttributeList ), + mPID( pid ) {} Process::~Process() { if ( mLpAttributeList ) { @@ -379,10 +387,11 @@ std::unique_ptr Process::createWithPipe( const std::string& program, AutoHandle hProcess{ piProcInfo.hProcess }; AutoHandle hThread{ piProcInfo.hThread }; - return std::unique_ptr( new Process( std::move( hProcess ), NULL ) ); + return std::unique_ptr( + new Process( std::move( hProcess ), NULL, piProcInfo.dwProcessId ) ); } - // PrintWinApiError( GetLastError() ); + PrintWinApiError( GetLastError() ); return nullptr; } @@ -414,7 +423,7 @@ Process::createWithPseudoTerminal( const std::string& program, const std::vector if ( ( hr = InitializeStartupInfoAttachedToPseudoConsole( &startupInfo, pseudoTerminal.mPHPC ) ) != S_OK ) { - printf( "InitializeStartupInfoAttachedToPseudoConsole failed\n" ); + Log::error( "InitializeStartupInfoAttachedToPseudoConsole failed." ); PrintErrorResult( hr ); goto fail; } @@ -434,7 +443,7 @@ Process::createWithPseudoTerminal( const std::string& program, const std::vector : HANDLE_WIN_ERR( GetLastError() ); if ( hr != S_OK ) { - printf( "CreateProcessW failed\n" ); + Log::error( "CreateProcessW failed\n" ); goto fail; } @@ -444,9 +453,11 @@ Process::createWithPseudoTerminal( const std::string& program, const std::vector pseudoTerminal.mAttached = true; return std::unique_ptr( - new Process( std::move( hProcess ), startupInfo.lpAttributeList ) ); + new Process( std::move( hProcess ), startupInfo.lpAttributeList, piClient.dwProcessId ) ); fail: return std::unique_ptr(); } +}} // namespace eterm::System + #endif diff --git a/src/modules/eterm/src/eterm/system/processfactory.cpp b/src/modules/eterm/src/eterm/system/processfactory.cpp index 31a5b6573..f4e0b8e3e 100644 --- a/src/modules/eterm/src/eterm/system/processfactory.cpp +++ b/src/modules/eterm/src/eterm/system/processfactory.cpp @@ -2,7 +2,9 @@ #include #include -using namespace EE::System; +using namespace eterm::System; + +namespace eterm { namespace System { std::unique_ptr ProcessFactory::createWithStdioPipe( const std::string& program, const std::vector& args, @@ -35,3 +37,5 @@ std::unique_ptr ProcessFactory::createWithPseudoTerminal( outPseudoTerminal = std::move( pseudoTerminal ); return process; } + +}} diff --git a/src/modules/eterm/src/eterm/terminal/iterminaldisplay.cpp b/src/modules/eterm/src/eterm/terminal/iterminaldisplay.cpp index f38f1d160..3f809d518 100644 --- a/src/modules/eterm/src/eterm/terminal/iterminaldisplay.cpp +++ b/src/modules/eterm/src/eterm/terminal/iterminaldisplay.cpp @@ -25,7 +25,7 @@ #define MODBIT( x, set, bit ) ( ( set ) ? ( ( x ) |= ( bit ) ) : ( ( x ) &= ~( bit ) ) ) -using namespace EE::Terminal; +namespace eterm { namespace Terminal { ITerminalDisplay::ITerminalDisplay() : mMode( MODE_VISIBLE ), mCursorMode( SteadyBar ), mEmulator( nullptr ) {} @@ -75,3 +75,5 @@ const char* ITerminalDisplay::getClipboard() const { } void ITerminalDisplay::onProcessExit( int /*exitCode*/ ) {} + +}} diff --git a/src/modules/eterm/src/eterm/terminal/pseudoterminal.cpp b/src/modules/eterm/src/eterm/terminal/pseudoterminal.cpp index 3a541ba0d..b121904c1 100644 --- a/src/modules/eterm/src/eterm/terminal/pseudoterminal.cpp +++ b/src/modules/eterm/src/eterm/terminal/pseudoterminal.cpp @@ -42,6 +42,8 @@ #include using namespace EE::System; +namespace eterm { namespace Terminal { + #if EE_PLATFORM == EE_PLATFORM_ANDROID #include @@ -90,8 +92,6 @@ fail: } #endif -using namespace EE::Terminal; - PseudoTerminal::~PseudoTerminal() {} PseudoTerminal::PseudoTerminal( int columns, int rows, AutoHandle&& master, AutoHandle&& slave ) : @@ -186,6 +186,8 @@ std::unique_ptr PseudoTerminal::create( int columns, int rows ) #endif } +}} // namespace eterm::Terminal + #else #include #include @@ -193,7 +195,7 @@ std::unique_ptr PseudoTerminal::create( int columns, int rows ) #define NTDDI_VERSION NTDDI_WIN10_RS5 #include -using namespace EE::Terminal; +namespace eterm { namespace Terminal { PseudoTerminal::~PseudoTerminal() { ClosePseudoConsole( mPHPC ); @@ -250,8 +252,9 @@ int PseudoTerminal::read( char* buf, size_t n, bool block ) { PrintLastWinApiError(); return -1; } - if ( available == 0 ) + if ( available == 0 ) { return 0; + } } if ( !ReadFile( mInputHandle.handle(), buf, available, &read, nullptr ) ) { @@ -300,4 +303,7 @@ std::unique_ptr PseudoTerminal::create( int columns, int rows ) return Pointer( new PseudoTerminal( columns, rows, std::move( hPipeIn ), std::move( hPipeOut ), hPC ) ); } + +}} // namespace eterm::Terminal + #endif diff --git a/src/modules/eterm/src/eterm/terminal/terminaldisplay.cpp b/src/modules/eterm/src/eterm/terminal/terminaldisplay.cpp index 3e8468378..104d19ad4 100644 --- a/src/modules/eterm/src/eterm/terminal/terminaldisplay.cpp +++ b/src/modules/eterm/src/eterm/terminal/terminaldisplay.cpp @@ -10,6 +10,8 @@ #include #include +namespace eterm { namespace Terminal { + #define BETWEEN( x, a, b ) ( ( a ) <= ( x ) && ( x ) <= ( b ) ) #define IS_SET( flag ) ( ( mMode & ( flag ) ) != 0 ) #define DIV( n, d ) ( ( ( n ) + ( d ) / 2.0f ) / ( d ) ) @@ -1402,7 +1404,7 @@ void TerminalDisplay::invalidateCursor() { } void TerminalDisplay::invalidateLine( const int& line ) { - if ( line >= mDirtyLines.size() ) { + if ( line >= (int)mDirtyLines.size() ) { mDirtyLines.resize( line + 1 ); } mDirtyLines[line] = true; @@ -1458,3 +1460,5 @@ void TerminalDisplay::drawFrameBuffer() { textureRegion.draw( mPosition.floor().x, mPosition.floor().y ); } } + +}} // namespace eterm::Terminal diff --git a/src/modules/eterm/src/eterm/terminal/terminalemulator.cpp b/src/modules/eterm/src/eterm/terminal/terminalemulator.cpp index 3ba7e36d8..72bfa578b 100644 --- a/src/modules/eterm/src/eterm/terminal/terminalemulator.cpp +++ b/src/modules/eterm/src/eterm/terminal/terminalemulator.cpp @@ -50,6 +50,8 @@ #include #include +namespace eterm { namespace Terminal { + /* identification sequence returned in DA and DECID */ static const char* vtiden = "\033[?6c"; @@ -111,8 +113,6 @@ static const unsigned int tabspaces = 4; ? mTerm.hist[( ( y ) + mTerm.histi - mTerm.scr + mTerm.histsize + 1 ) % mTerm.histsize] \ : mTerm.line[(y)-mTerm.scr] ) -using namespace EE::Terminal; - typedef struct emoji_range { int32_t min_code; int32_t max_code; @@ -2632,3 +2632,5 @@ void TerminalEmulator::update() { onProcessExit( mExitCode ); } } + +}} // namespace eterm::Terminal diff --git a/src/modules/eterm/src/eterm/terminal/windowserrors.hpp b/src/modules/eterm/src/eterm/terminal/windowserrors.hpp index 2b8642649..cf5edd5f1 100644 --- a/src/modules/eterm/src/eterm/terminal/windowserrors.hpp +++ b/src/modules/eterm/src/eterm/terminal/windowserrors.hpp @@ -22,16 +22,20 @@ // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER // DEALINGS IN THE SOFTWARE. #ifdef _WIN32 +#include +using namespace EE::System; + #define NTDDI_VERSION NTDDI_WIN10_RS5 #include #include #include #include -static void PrintErrorResult( HRESULT hr ) { +inline void PrintErrorResult( HRESULT hr ) { _com_error err( hr ); LPCTSTR errMsg = err.ErrorMessage(); std::cerr << "ERROR: " << errMsg << std::endl; + Log::error( "ERROR: %s", errMsg ); } static void PrintWinApiError( DWORD error ) { @@ -48,9 +52,10 @@ static void PrintWinApiError( DWORD error ) { LocalFree( messageBuffer ); std::cerr << "ERROR WinAPI: " << message << std::endl; + Log::error( "ERROR WinAPI: %s", message ); } -static void PrintLastWinApiError( void ) { +inline void PrintLastWinApiError( void ) { PrintWinApiError( GetLastError() ); } diff --git a/src/tools/eterm/eterm.cpp b/src/tools/eterm/eterm.cpp index 36e7e5753..c8522315f 100644 --- a/src/tools/eterm/eterm.cpp +++ b/src/tools/eterm/eterm.cpp @@ -95,7 +95,24 @@ EE_MAIN_FUNC int main( int, char*[] ) { #endif DisplayManager* displayManager = Engine::instance()->getDisplayManager(); Display* currentDisplay = displayManager->getDisplayIndex( 0 ); - FileSystem::changeWorkingDirectory( Sys::getProcessPath() ); + + std::string resPath = Sys::getProcessPath(); +#if EE_PLATFORM == EE_PLATFORM_MACOSX + if ( String::contains( resPath, "ecode.app" ) ) { + resPath = FileSystem::getCurrentWorkingDirectory(); + FileSystem::dirAddSlashAtEnd( resPath ); + mIsBundledApp = true; + } +#elif EE_PLATFORM == EE_PLATFORM_LINUX + if ( String::contains( resPath, ".mount_" ) ) { + resPath = FileSystem::getCurrentWorkingDirectory(); + FileSystem::dirAddSlashAtEnd( resPath ); + } +#elif EE_PLATFORM == EE_PLATFORM_EMSCRIPTEN + resPath += "eterm/"; +#endif + resPath += "assets"; + FileSystem::dirAddSlashAtEnd( resPath ); displayManager->enableScreenSaver(); displayManager->enableMouseFocusClickThrough(); @@ -104,7 +121,7 @@ EE_MAIN_FUNC int main( int, char*[] ) { Sizei winSize( 1280, 720 ); win = Engine::instance()->createWindow( WindowSettings( winSize.getWidth(), winSize.getHeight(), "eterm", WindowStyle::Default, - WindowBackend::Default, 32, "assets/icon/ee.png", + WindowBackend::Default, 32, resPath + "icon/ee.png", currentDisplay->getPixelDensity() ), ContextSettings( true ) ); @@ -112,13 +129,15 @@ EE_MAIN_FUNC int main( int, char*[] ) { win->setClearColor( RGB( 0, 0, 0 ) ); FontTrueType* fontMono = FontTrueType::New( "monospace" ); - fontMono->loadFromFile( "assets/fonts/DejaVuSansMonoNerdFontComplete.ttf" ); + fontMono->loadFromFile( resPath + "fonts/DejaVuSansMonoNerdFontComplete.ttf" ); fontMono->setEnableEmojiFallback( false ); - if ( FileSystem::fileExists( "assets/fonts/NotoColorEmoji.ttf" ) ) { - FontTrueType::New( "emoji-color" )->loadFromFile( "assets/fonts/NotoColorEmoji.ttf" ); - } else if ( FileSystem::fileExists( "assets/fonts/NotoEmoji-Regular.ttf" ) ) { - FontTrueType::New( "emoji-font" )->loadFromFile( "assets/fonts/NotoEmoji-Regular.ttf" ); + if ( FileSystem::fileExists( resPath + "fonts/NotoColorEmoji.ttf" ) ) { + FontTrueType::New( "emoji-color" ) + ->loadFromFile( resPath + "fonts/NotoColorEmoji.ttf" ); + } else if ( FileSystem::fileExists( resPath + "fonts/NotoEmoji-Regular.ttf" ) ) { + FontTrueType::New( "emoji-font" ) + ->loadFromFile( resPath + "fonts/NotoEmoji-Regular.ttf" ); } if ( !terminal || terminal->hasTerminated() ) {