From 530c869a02201738fe4d83ad380df1810ea856d7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mart=C3=ADn=20Lucas=20Golini?= Date: Tue, 14 Apr 2026 18:32:14 -0300 Subject: [PATCH] Added TERM_PROGRAM and TERM_PROGRAM_VERSION environment variables to the new terminal instances (SpartanJ/ecode#878). --- include/eepp/version.hpp | 2 +- src/eepp/core/version.cpp | 5 ++- .../eterm/src/eterm/system/process.cpp | 43 +++++++++++-------- 3 files changed, 29 insertions(+), 21 deletions(-) diff --git a/include/eepp/version.hpp b/include/eepp/version.hpp index 9f75a4156..6fe91c64e 100644 --- a/include/eepp/version.hpp +++ b/include/eepp/version.hpp @@ -39,7 +39,7 @@ class EE_API Version { static Uint32 getVersionNum(); /** @return The library version name: "eepp version major.minor.patch" */ - static std::string getVersionName(); + static std::string getVersionName( bool fullName = true ); /** @return The version codename */ static std::string getCodename(); diff --git a/src/eepp/core/version.cpp b/src/eepp/core/version.cpp index 280665a32..7336fc325 100644 --- a/src/eepp/core/version.cpp +++ b/src/eepp/core/version.cpp @@ -14,9 +14,10 @@ Uint32 Version::getVersionNum() { return EEPP_VERSIONNUM( ver.major, ver.minor, ver.patch ); } -std::string Version::getVersionName() { +std::string Version::getVersionName( bool fullName ) { Version ver = getVersion(); - return String::format( "eepp version %d.%d.%d", ver.major, ver.minor, ver.patch ); + return fullName ? String::format( "eepp version %d.%d.%d", ver.major, ver.minor, ver.patch ) + : String::format( "%d.%d.%d", ver.major, ver.minor, ver.patch ); } std::string Version::getCodename() { diff --git a/src/modules/eterm/src/eterm/system/process.cpp b/src/modules/eterm/src/eterm/system/process.cpp index b003b7458..fdaf270bb 100644 --- a/src/modules/eterm/src/eterm/system/process.cpp +++ b/src/modules/eterm/src/eterm/system/process.cpp @@ -23,6 +23,7 @@ #ifndef _WIN32 #include #include +#include #include #include #include @@ -140,6 +141,8 @@ static void execshell( const char* cmd, const char* const* args, std::string wor setenv( "SHELL", sh, 1 ); setenv( "HOME", pw->pw_dir, 1 ); setenv( "TERM", "xterm-256color", 1 ); + setenv( "TERM_PROGRAM", "eterm", 1 ); + setenv( "TERM_PROGRAM_VERSION", EE::Version::getVersionName( false ).c_str(), 1 ); setenv( "COLORTERM", "24bit", 1 ); for ( const auto& e : env ) @@ -213,6 +216,7 @@ Process::createWithPseudoTerminal( const std::string& program, const std::vector #else #include +#include #include #include #include @@ -357,9 +361,9 @@ std::unique_ptr Process::createWithPipe( const std::string& program, oss << ' ' << arg; } std::wstring commandLine = stringToWideString( oss.str() ); - - std::vector cmdLineMutable(commandLine.begin(), commandLine.end()); - cmdLineMutable.push_back(0); + + std::vector cmdLineMutable( commandLine.begin(), commandLine.end() ); + cmdLineMutable.push_back( 0 ); std::wstring workingDir = stringToWideString( workingDirectory ); @@ -390,6 +394,8 @@ Process::createWithPseudoTerminal( const std::string& program, const std::vector SetEnvironmentVariableA( "WSLENV", "TERM/u" ); SetEnvironmentVariableA( "TERM", "xterm-256color" ); SetEnvironmentVariableA( "COLORTERM", "24bit" ); + SetEnvironmentVariableA( "TERM_PROGRAM", "eterm" ); + SetEnvironmentVariableA( "TERM_PROGRAM_VERSION", EE::Version::getVersionName( false ).c_str() ); for ( const auto& e : env ) SetEnvironmentVariableA( e.first.c_str(), e.second.c_str() ); @@ -401,7 +407,7 @@ Process::createWithPseudoTerminal( const std::string& program, const std::vector STARTUPINFOEXW startupInfo{}; startupInfo.StartupInfo.cb = sizeof( STARTUPINFOEXW ); - startupInfo.StartupInfo.dwFlags = STARTF_USESTDHANDLES; + startupInfo.StartupInfo.dwFlags = STARTF_USESTDHANDLES; startupInfo.StartupInfo.hStdInput = INVALID_HANDLE_VALUE; startupInfo.StartupInfo.hStdOutput = INVALID_HANDLE_VALUE; startupInfo.StartupInfo.hStdError = INVALID_HANDLE_VALUE; @@ -432,23 +438,24 @@ Process::createWithPseudoTerminal( const std::string& program, const std::vector goto fail; } - if ( !UpdateProcThreadAttribute( startupInfo.lpAttributeList, 0, PROC_THREAD_ATTRIBUTE_PSEUDOCONSOLE, - pseudoTerminal.mPHPC, sizeof( HPCON ), NULL, NULL ) ) { + if ( !UpdateProcThreadAttribute( startupInfo.lpAttributeList, 0, + PROC_THREAD_ATTRIBUTE_PSEUDOCONSOLE, pseudoTerminal.mPHPC, + sizeof( HPCON ), NULL, NULL ) ) { Log::error( "UpdateProcThreadAttribute failed." ); goto fail; } - hr = CreateProcessW( NULL, // No module name - use Command Line - commandLine.data(), // Must be a mutable buffer to prevent ERROR_INSUFFICIENT_BUFFER - NULL, // Process handle not inheritable - NULL, // Thread handle not inheritable - FALSE, // Inherit handles - EXTENDED_STARTUPINFO_PRESENT, // Creation flags - NULL, // Use parent's environment block - workingDir.empty() ? NULL - : workingDir.c_str(), // Use parent's starting directory - &startupInfo.StartupInfo, // Pointer to STARTUPINFO - &piClient ) // Pointer to PROCESS_INFORMATION + hr = CreateProcessW( + NULL, // No module name - use Command Line + commandLine.data(), // Must be a mutable buffer to prevent ERROR_INSUFFICIENT_BUFFER + NULL, // Process handle not inheritable + NULL, // Thread handle not inheritable + FALSE, // Inherit handles + EXTENDED_STARTUPINFO_PRESENT, // Creation flags + NULL, // Use parent's environment block + workingDir.empty() ? NULL : workingDir.c_str(), // Use parent's starting directory + &startupInfo.StartupInfo, // Pointer to STARTUPINFO + &piClient ) // Pointer to PROCESS_INFORMATION ? S_OK : HANDLE_WIN_ERR( GetLastError() ); @@ -478,4 +485,4 @@ int Process::pid() { }} // namespace eterm::System -#endif \ No newline at end of file +#endif