From 33f69b8423b500b01e29f4ec4aff45dafcae5a32 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mart=C3=ADn=20Lucas=20Golini?= Date: Mon, 6 Feb 2023 04:51:06 -0300 Subject: [PATCH] Minor changes in terminal. Fixed Sys::parseArguments for emscripten. --- premake4.lua | 2 +- src/eepp/system/sys.cpp | 1 - .../eterm/terminal/terminaldisplay.hpp | 2 +- .../src/eterm/terminal/terminaldisplay.cpp | 20 +++++++++++++------ src/tools/eterm/eterm.cpp | 7 ++++++- src/tools/uieditor/uieditor.cpp | 3 +-- 6 files changed, 23 insertions(+), 12 deletions(-) diff --git a/premake4.lua b/premake4.lua index 92e20b6ff..5456ce636 100644 --- a/premake4.lua +++ b/premake4.lua @@ -558,7 +558,7 @@ function build_link_configuration( package_name, use_ee_icon ) end if os.is_real("emscripten") then - linkoptions{ "--profiling --profiling-funcs -s DEMANGLE_SUPPORT=1" } + linkoptions{ "--profiling --profiling-funcs -s DEMANGLE_SUPPORT=1 -s NO_DISABLE_EXCEPTION_CATCHING" } end fix_shared_lib_linking_path( package_name, "libeepp-debug" ) diff --git a/src/eepp/system/sys.cpp b/src/eepp/system/sys.cpp index dafc2dd0f..48fb686db 100644 --- a/src/eepp/system/sys.cpp +++ b/src/eepp/system/sys.cpp @@ -888,7 +888,6 @@ std::vector Sys::parseArguments( int argc, char* argv[] ) { if ( argc < 1 ) return {}; std::vector args; - args.emplace_back( argv[0] ); for ( int i = 1; i < argc; i++ ) { auto split = String::split( std::string( argv[i] ), '=' ); if ( split.size() == 2 ) { diff --git a/src/modules/eterm/include/eterm/terminal/terminaldisplay.hpp b/src/modules/eterm/include/eterm/terminal/terminaldisplay.hpp index 2e8f5f3f3..693ee882a 100644 --- a/src/modules/eterm/include/eterm/terminal/terminaldisplay.hpp +++ b/src/modules/eterm/include/eterm/terminal/terminaldisplay.hpp @@ -152,7 +152,7 @@ class TerminalDisplay : public ITerminalDisplay { static std::shared_ptr create( EE::Window::Window* window, Font* font, const Float& fontSize, const Sizef& pixelsSize, - std::string program = "", const std::vector& args = {}, + std::string program = "", std::vector args = {}, const std::string& workingDir = "", const size_t& historySize = 10000, IProcessFactory* processFactory = nullptr, const bool& useFrameBuffer = false, const bool& keepAlive = true ); diff --git a/src/modules/eterm/src/eterm/terminal/terminaldisplay.cpp b/src/modules/eterm/src/eterm/terminal/terminaldisplay.cpp index 87fbcc886..fab4ee164 100644 --- a/src/modules/eterm/src/eterm/terminal/terminaldisplay.cpp +++ b/src/modules/eterm/src/eterm/terminal/terminaldisplay.cpp @@ -387,14 +387,14 @@ static Sizei gridSizeFromTermDimensions( Font* font, const Float& fontSize, std::shared_ptr TerminalDisplay::create( EE::Window::Window* window, Font* font, const Float& fontSize, const Sizef& pixelsSize, std::string program, - const std::vector& args, const std::string& workingDir, + std::vector args, const std::string& workingDir, const size_t& historySize, IProcessFactory* processFactory, const bool& useFrameBuffer, const bool& keepAlive ) { if ( program.empty() ) { -#ifdef _WIN32 - program = "cmd.exe"; -#else const char* shellenv = getenv( "SHELL" ); +#ifdef _WIN32 + program = shellenv != nullptr ? shellenv : "cmd.exe"; +#else #if EE_PLATFORM == EE_PLATFORM_ANDROID program = shellenv != nullptr ? shellenv : "/bin/sh"; #else @@ -404,15 +404,23 @@ TerminalDisplay::create( EE::Window::Window* window, Font* font, const Float& fo #endif } + if ( program.find_first_of( ' ' ) != std::string::npos ) { + auto programSplit = String::split( program, ' ' ); + if ( !programSplit.empty() ) { + program = programSplit[0]; + for ( size_t i = 1; i < programSplit.size(); ++i ) + args.push_back( programSplit[i] ); + } + } + bool freeProcessFactory = processFactory == nullptr; if ( processFactory == nullptr ) processFactory = eeNew( ProcessFactory, () ); Sizei termSize( gridSizeFromTermDimensions( font, fontSize, pixelsSize ) ); std::unique_ptr pseudoTerminal = nullptr; - std::vector argsV( args.begin(), args.end() ); auto process = processFactory->createWithPseudoTerminal( - program, argsV, workingDir, termSize.getWidth(), termSize.getHeight(), pseudoTerminal ); + program, args, workingDir, termSize.getWidth(), termSize.getHeight(), pseudoTerminal ); if ( !pseudoTerminal ) { fprintf( stderr, "Failed to create pseudo terminal\n" ); diff --git a/src/tools/eterm/eterm.cpp b/src/tools/eterm/eterm.cpp index 7af3a6ae6..5a2cb1fd7 100644 --- a/src/tools/eterm/eterm.cpp +++ b/src/tools/eterm/eterm.cpp @@ -131,6 +131,8 @@ EE_MAIN_FUNC int main( int argc, char* argv[] ) { args::HelpFlag help( parser, "help", "Display this help menu", { 'h', "help" } ); args::ValueFlag shell( parser, "shell", "Shell name or path", { 's', "shell" }, "" ); + args::ValueFlag shellArgs( parser, "shell-args", "Shell command line arguments", + { "shell-args" }, "" ); args::ValueFlag historySize( parser, "scrollback", "Maximum history size (lines)", { 'l', "scrollback" }, 10000 ); args::Flag fb( parser, "framebuffer", "Use frame buffer (more memory usage, less CPU usage)", @@ -261,7 +263,8 @@ EE_MAIN_FUNC int main( int argc, char* argv[] ) { FileInfo file( wd ? wd.Get() : FileSystem::getCurrentWorkingDirectory() ); terminal = TerminalDisplay::create( win, fontMono, PixelDensity::dpToPx( fontSize.Get() ), win->getSize().asFloat(), - file.isRegularFile() && file.isExecutable() ? file.getFilepath() : shell.Get(), {}, + file.isRegularFile() && file.isExecutable() ? file.getFilepath() : shell.Get(), + shellArgs ? String::split( shellArgs.Get() ) : std::vector(), file.getDirectoryPath(), historySize.Get(), nullptr, fb.Get(), !( file.isRegularFile() && file.isExecutable() ) ); terminal->getTerminal()->setAllowMemoryTrimnming( true ); @@ -274,6 +277,8 @@ EE_MAIN_FUNC int main( int argc, char* argv[] ) { win->close(); } } ); + if ( shell ) + terminal->setKeepAlive( false ); if ( colorScheme ) { auto selColorScheme = terminalColorSchemes.find( colorScheme.Get() ); diff --git a/src/tools/uieditor/uieditor.cpp b/src/tools/uieditor/uieditor.cpp index 6ec266efd..1bca4d5f8 100644 --- a/src/tools/uieditor/uieditor.cpp +++ b/src/tools/uieditor/uieditor.cpp @@ -859,8 +859,7 @@ bool App::onCloseRequestCallback( EE::Window::Window* ) { UIMessageBox::OK_CANCEL, "Do you really want to close the current file?\nAll changes will be lost." ); mMsgBox->setTheme( mTheme ); - mMsgBox->addEventListener( Event::OnConfirm, - [&]( const Event* ) { mWindow->close(); } ); + mMsgBox->addEventListener( Event::OnConfirm, [&]( const Event* ) { mWindow->close(); } ); mMsgBox->addEventListener( Event::OnClose, [&]( const Event* ) { mMsgBox = NULL; } ); mMsgBox->setTitle( "Close Editor?" ); mMsgBox->center();