From 0924b715eeb095cdbc252a22a010206bebd3e498 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mart=C3=ADn=20Lucas=20Golini?= Date: Wed, 24 Aug 2022 03:04:21 -0300 Subject: [PATCH] Some minor fixes in ecode. --- src/eepp/system/sys.cpp | 10 ++++++++- src/tools/ecode/docsearchcontroller.cpp | 2 +- src/tools/ecode/ecode.cpp | 6 +++--- src/tools/ecode/ecode.hpp | 2 +- src/tools/ecode/terminalmanager.cpp | 2 +- src/tools/ecode/uitreeviewglobalsearch.cpp | 11 +++++----- src/tools/eterm/eterm.cpp | 25 ++++++++++++++++------ 7 files changed, 39 insertions(+), 19 deletions(-) diff --git a/src/eepp/system/sys.cpp b/src/eepp/system/sys.cpp index a35275cc7..ab97763a0 100644 --- a/src/eepp/system/sys.cpp +++ b/src/eepp/system/sys.cpp @@ -53,6 +53,10 @@ #include #endif +#ifndef PATH_MAX +#define PATH_MAX 4096 +#endif + namespace EE { namespace System { #if EE_PLATFORM == EE_PLATFORM_WIN @@ -176,7 +180,11 @@ static std::string GetWindowsVersion() { if ( osvi.dwMajorVersion == 10 ) { if ( osvi.dwMinorVersion == 0 ) { if ( osvi.wProductType == VER_NT_WORKSTATION ) { - os += "Windows 10"; + if ( osvi.dwBuildNumber >= 22000 ) { + os += "Windows 11"; + } else { + os += "Windows 10"; + } } else { os += "Windows Server 2016"; } diff --git a/src/tools/ecode/docsearchcontroller.cpp b/src/tools/ecode/docsearchcontroller.cpp index b44592798..3a16b95c6 100644 --- a/src/tools/ecode/docsearchcontroller.cpp +++ b/src/tools/ecode/docsearchcontroller.cpp @@ -139,7 +139,7 @@ void DocSearchController::initSearchBar( mSearchBarLayout->addCommand( "toggle-lua-pattern", [&, luaPatternChk] { luaPatternChk->setChecked( !luaPatternChk->isChecked() ); } ); - mSearchBarLayout->addCommand( "open-global-search", [&] { mApp->showGlobalSearch(); } ); + mSearchBarLayout->addCommand( "open-global-search", [&] { mApp->showGlobalSearch( false ); } ); addReturnListener( findInput, "repeat-find" ); addReturnListener( replaceInput, "find-and-replace" ); diff --git a/src/tools/ecode/ecode.cpp b/src/tools/ecode/ecode.cpp index 62937f8f1..4f90b4210 100644 --- a/src/tools/ecode/ecode.cpp +++ b/src/tools/ecode/ecode.cpp @@ -2156,8 +2156,8 @@ void App::fullscreenToggle() { ->setActive( !mWindow->isWindowed() ); } -void App::showGlobalSearch() { - mGlobalSearchController->showGlobalSearch(); +void App::showGlobalSearch( bool searchAndReplace ) { + mGlobalSearchController->showGlobalSearch( searchAndReplace ); } void App::showFindView() { @@ -2207,7 +2207,7 @@ void App::onCodeEditorCreated( UICodeEditor* editor, TextDocument& doc ) { } ); doc.setCommand( "save-all", [&] { saveAll(); } ); doc.setCommand( "find-replace", [&] { showFindView(); } ); - doc.setCommand( "open-global-search", [&] { showGlobalSearch(); } ); + doc.setCommand( "open-global-search", [&] { showGlobalSearch( false ); } ); doc.setCommand( "open-locatebar", [&] { mFileLocator->showLocateBar(); } ); doc.setCommand( "repeat-find", [&] { mDocSearchController->findNextText( mDocSearchController->getSearchState() ); diff --git a/src/tools/ecode/ecode.hpp b/src/tools/ecode/ecode.hpp index 937a69b52..025fbe3a7 100644 --- a/src/tools/ecode/ecode.hpp +++ b/src/tools/ecode/ecode.hpp @@ -87,7 +87,7 @@ class App : public UICodeEditorSplitter::Client { void downloadFileWebDialog(); - void showGlobalSearch(); + void showGlobalSearch( bool searchAndReplace ); void showFindView(); diff --git a/src/tools/ecode/terminalmanager.cpp b/src/tools/ecode/terminalmanager.cpp index d7c192ff1..aa32de38a 100644 --- a/src/tools/ecode/terminalmanager.cpp +++ b/src/tools/ecode/terminalmanager.cpp @@ -321,7 +321,7 @@ UITerminal* TerminalManager::createNewTerminal( const std::string& title, UITabW term->setCommand( "open-folder", [&] { mApp->openFolderDialog(); } ); term->setCommand( "console-toggle", [&] { mApp->consoleToggle(); } ); term->setCommand( "menu-toggle", [&] { mApp->toggleSettingsMenu(); } ); - term->setCommand( "open-global-search", [&] { mApp->showGlobalSearch(); } ); + term->setCommand( "open-global-search", [&] { mApp->showGlobalSearch( false ); } ); term->setCommand( "open-locatebar", [&] { mApp->getFileLocator()->showLocateBar(); } ); term->setCommand( "download-file-web", [&] { mApp->downloadFileWebDialog(); } ); diff --git a/src/tools/ecode/uitreeviewglobalsearch.cpp b/src/tools/ecode/uitreeviewglobalsearch.cpp index 986ce9116..39366e7ba 100644 --- a/src/tools/ecode/uitreeviewglobalsearch.cpp +++ b/src/tools/ecode/uitreeviewglobalsearch.cpp @@ -146,8 +146,8 @@ UIPushButton* UITreeViewCellGlobalSearch::updateText( const std::string& text ) const String& txt = mTextBox->getText(); if ( mSearchStrPos.second < txt.size() ) { - mResultStr = - txt.substr( mSearchStrPos.first, mSearchStrPos.second - mSearchStrPos.first ); + mResultStr = String( txt.toUtf8().substr( + mSearchStrPos.first, mSearchStrPos.second - mSearchStrPos.first ) ); } else { mResultStr = ""; } @@ -157,9 +157,10 @@ UIPushButton* UITreeViewCellGlobalSearch::updateText( const std::string& text ) size_t start = to; for ( auto& token : tokens ) { + size_t strSize = String::fromUtf8( token.text ).size(); mTextBox->setFontFillColor( pp->getColorScheme().getSyntaxStyle( token.type ).color, - start, start + token.text.size() ); - start += token.text.size(); + start, start + strSize ); + start += strSize; } } return this; @@ -224,4 +225,4 @@ void UITreeViewCellGlobalSearch::updateCell( Model* ) { } } -} +} // namespace ecode diff --git a/src/tools/eterm/eterm.cpp b/src/tools/eterm/eterm.cpp index 14e7c552f..c17a63295 100644 --- a/src/tools/eterm/eterm.cpp +++ b/src/tools/eterm/eterm.cpp @@ -5,7 +5,10 @@ EE::Window::Window* win = NULL; std::shared_ptr terminal = nullptr; Clock lastRender; +Clock secondsCounter; Time frameTime{ Time::Zero }; +bool benchmarkMode{ false }; +std::string windowStringData; void inputCallback( InputEvent* event ) { if ( !terminal || event->Type == InputEvent::EventsSent ) @@ -83,16 +86,19 @@ void mainLoop() { if ( terminal ) termNeedsUpdate = !terminal->update(); - if ( terminal && terminal->isDirty() && !termNeedsUpdate ) { + if ( terminal && ( benchmarkMode || terminal->isDirty() ) && !termNeedsUpdate ) { if ( lastRender.getElapsedTime() >= frameTime ) { lastRender.restart(); win->clear(); terminal->draw(); win->display(); } - } else if ( !termNeedsUpdate ) { + } else if ( !benchmarkMode && !termNeedsUpdate ) { win->getInput()->waitEvent( Milliseconds( win->hasFocus() ? 16 : 100 ) ); } + + if ( benchmarkMode && secondsCounter.getElapsedTime() >= Seconds( 1 ) ) + win->setTitle( "eterm - " + windowStringData + " - " + String::toString( win->getFPS() ) ); } EE_MAIN_FUNC int main( int argc, char* argv[] ) { @@ -126,6 +132,8 @@ EE_MAIN_FUNC int main( int argc, char* argv[] ) { args::ValueFlag maxFPS( parser, "max-fps", "Maximum rendering frames per second of the terminal", { "--max-fps" }, 60 ); + args::Flag benchmarkModeFlag( parser, "benchmark-mode", "Render as much as possible.", + { "benchmark-mode" } ); try { parser.ParseCLI( argc, argv ); @@ -177,6 +185,8 @@ EE_MAIN_FUNC int main( int argc, char* argv[] ) { if ( win->isOpen() ) { win->setClearColor( RGB( 0, 0, 0 ) ); + benchmarkMode = benchmarkModeFlag.Get(); + FontTrueType* fontMono = nullptr; if ( fontPath && FileSystem::fileExists( fontPath.Get() ) ) { FileInfo file( fontPath.Get() ); @@ -198,7 +208,7 @@ EE_MAIN_FUNC int main( int argc, char* argv[] ) { ->loadFromFile( resPath + "fonts/NotoEmoji-Regular.ttf" ); } - frameTime = Milliseconds( 1000.f / (Float)maxFPS.Get() ); + frameTime = benchmarkMode ? Time::Zero : Milliseconds( 1000.f / (Float)maxFPS.Get() ); if ( !terminal || terminal->hasTerminated() ) { FileInfo file( wd ? wd.Get() : FileSystem::getCurrentWorkingDirectory() ); @@ -208,10 +218,11 @@ EE_MAIN_FUNC int main( int argc, char* argv[] ) { file.getDirectoryPath(), historySize.Get(), nullptr, fb.Get(), !( file.isRegularFile() && file.isExecutable() ) ); terminal->pushEventCallback( [&]( const TerminalDisplay::Event& event ) { - if ( event.type == TerminalDisplay::EventType::TITLE ) - win->setTitle( "eterm - " + event.eventData ); - else if ( event.type == TerminalDisplay::EventType::PROCESS_EXIT && - closeOnExit.Get() ) { + if ( event.type == TerminalDisplay::EventType::TITLE ) { + windowStringData = event.eventData; + win->setTitle( "eterm - " + windowStringData ); + } else if ( event.type == TerminalDisplay::EventType::PROCESS_EXIT && + closeOnExit.Get() ) { win->close(); } } );