mirror of
https://github.com/SpartanJ/eepp.git
synced 2026-10-01 02:30:25 +03:00
eepp: add reusable UISettingsPanel
- add the generic settings model and panel to EE::UI::Tools - support category navigation, filtering, and lazy materialization - add UISettingsPanel model and filtering tests ecode: migrate settings to UISettingsPanel - replace the application-specific settings model - use the generic settings panel implementation - add monitor refresh rate as a frame limit option - normalize UI labels and translations eterm: add persistent configuration and settings panel - persist application preferences and window state - use saved values as defaults for command-line options - persist command-line overrides - add graphical settings with live application - expose renderer, terminal behavior, appearance, font, and scale options
This commit is contained in:
+273
-180
@@ -1,116 +1,21 @@
|
||||
#include <args/args.hxx>
|
||||
#include <eepp/core/small_vector.hpp>
|
||||
#include <eepp/ee.hpp>
|
||||
#include <eepp/ui/iconmanager.hpp>
|
||||
#include <eepp/ui/tools/uitabwidgetsplitter.hpp>
|
||||
#include <eepp/ui/tools/uiwidgetinspector.hpp>
|
||||
#include <eepp/ui/uiapplication.hpp>
|
||||
#include <eepp/ui/uilinearlayout.hpp>
|
||||
#include <eepp/ui/uimessagebox.hpp>
|
||||
#include <eterm/ui/uiterminal.hpp>
|
||||
#include "eterm.hpp"
|
||||
#include "settingspanel.hpp"
|
||||
|
||||
#include <algorithm>
|
||||
#include <iostream>
|
||||
#include <iterator>
|
||||
#include <map>
|
||||
#include <unordered_map>
|
||||
|
||||
using namespace EE;
|
||||
using namespace EE::Graphics;
|
||||
using namespace EE::Scene;
|
||||
using namespace EE::System;
|
||||
using namespace EE::UI;
|
||||
using namespace EE::UI::Tools;
|
||||
using namespace EE::Window;
|
||||
using namespace eterm::Terminal;
|
||||
using namespace eterm::UI;
|
||||
namespace eterm {
|
||||
|
||||
namespace {
|
||||
|
||||
struct TerminalLaunchConfig {
|
||||
std::string program;
|
||||
std::vector<std::string> arguments;
|
||||
std::string workingDirectory;
|
||||
std::string executeInShell;
|
||||
size_t historySize{ 10000 };
|
||||
TerminalCursorMode cursorStyle{ TerminalCursorMode::SteadyUnderline };
|
||||
FontHinting fontHinting{ FontHinting::Full };
|
||||
FontAntialiasing fontAntialiasing{ FontAntialiasing::Grayscale };
|
||||
bool useFrameBuffer{ false };
|
||||
bool keepAlive{ true };
|
||||
bool closeOnExit{ false };
|
||||
};
|
||||
|
||||
class EtermApp {
|
||||
public:
|
||||
int run( int argc, char* argv[] );
|
||||
|
||||
class TerminalSplitterClient : public UITabWidgetSplitter::Client {
|
||||
public:
|
||||
explicit TerminalSplitterClient( EtermApp& app ) : mApp( app ) {}
|
||||
|
||||
void onTabCreated( UITab* tab, UIWidget* ) override;
|
||||
void onWidgetFocusChange( UIWidget* ) override;
|
||||
|
||||
private:
|
||||
EtermApp& mApp;
|
||||
};
|
||||
|
||||
private:
|
||||
std::string getResourcePath() const;
|
||||
String i18n( const std::string& key, const String& defaultValue ) const;
|
||||
void loadColorSchemes( const std::string& resPath );
|
||||
static UITerminal* terminalFromTab( UITab* tab );
|
||||
void updateWindowTitle();
|
||||
bool hasTerminals() const;
|
||||
static bool hasRunningChildren( UITab* tab );
|
||||
void closeTab( UITab* tab );
|
||||
void queueExitCloseTab( UITab* tab );
|
||||
void queueExitedTabs();
|
||||
void requestCloseTab( UITab* tab );
|
||||
void renameSession( UITerminal* terminal );
|
||||
void maximizeTabWidget( UITabWidget* tabWidget );
|
||||
void restoreMaximizedTabWidget();
|
||||
void configureTab( UITab* tab );
|
||||
UITerminal* createTerminal( UITabWidget* target = nullptr );
|
||||
UITerminal* createTerminalSplit( SplitDirection direction, UITerminal* terminal );
|
||||
void addTabKeyBindings( UITerminal* terminal );
|
||||
bool closeWindow( EE::Window::Window* );
|
||||
|
||||
EE::Window::Window* appWindow{ nullptr };
|
||||
UISceneNode* scene{ nullptr };
|
||||
UILinearLayout* mainLayout{ nullptr };
|
||||
UITabWidgetSplitter* tabSplitter{ nullptr };
|
||||
FontTrueType* terminalFont{ nullptr };
|
||||
UIIcon* terminalIcon{ nullptr };
|
||||
UIMessageBox* closeDialog{ nullptr };
|
||||
UIWidget* closeDialogWidget{ nullptr };
|
||||
UIWindow* maximizedTabWidgetWindow{ nullptr };
|
||||
UITabWidget* maximizedTabWidget{ nullptr };
|
||||
UINodeLink* maximizedTabWidgetLink{ nullptr };
|
||||
TerminalLaunchConfig terminalConfig;
|
||||
std::map<std::string, TerminalColorScheme> terminalColorSchemes;
|
||||
const TerminalColorScheme* selectedColorScheme{ nullptr };
|
||||
Float terminalFontSize{ 12 };
|
||||
bool warnBeforeClose{ false };
|
||||
bool closeApproved{ false };
|
||||
bool benchmarkMode{ false };
|
||||
Clock secondsCounter;
|
||||
SmallVector<UITab*, 8> pendingExitCloseTabs;
|
||||
TerminalSplitterClient splitterClient{ *this };
|
||||
};
|
||||
|
||||
void EtermApp::TerminalSplitterClient::onTabCreated( UITab* tab, UIWidget* ) {
|
||||
void App::TerminalSplitterClient::onTabCreated( UITab* tab, UIWidget* ) {
|
||||
if ( mApp.terminalIcon )
|
||||
tab->setIcon( mApp.terminalIcon->createDrawable( PixelDensity::dpToPxI( 12 ) ) );
|
||||
mApp.configureTab( tab );
|
||||
}
|
||||
|
||||
void EtermApp::TerminalSplitterClient::onWidgetFocusChange( UIWidget* ) {
|
||||
void App::TerminalSplitterClient::onWidgetFocusChange( UIWidget* ) {
|
||||
mApp.updateWindowTitle();
|
||||
}
|
||||
|
||||
std::string EtermApp::getResourcePath() const {
|
||||
std::string App::getResourcePath() const {
|
||||
std::string resPath = Sys::getProcessPath();
|
||||
#if EE_PLATFORM == EE_PLATFORM_MACOS
|
||||
if ( String::contains( resPath, "ecode.app" ) ) {
|
||||
@@ -130,11 +35,11 @@ std::string EtermApp::getResourcePath() const {
|
||||
return resPath;
|
||||
}
|
||||
|
||||
String EtermApp::i18n( const std::string& key, const String& defaultValue ) const {
|
||||
String App::i18n( const std::string& key, const String& defaultValue ) const {
|
||||
return scene ? scene->i18n( key, defaultValue ) : defaultValue;
|
||||
}
|
||||
|
||||
void EtermApp::loadColorSchemes( const std::string& resPath ) {
|
||||
void App::loadColorSchemes( const std::string& resPath ) {
|
||||
auto colorSchemes =
|
||||
TerminalColorScheme::loadFromFile( resPath + "colorschemes/terminalcolorschemes.conf" );
|
||||
const std::string configColorSchemesPath =
|
||||
@@ -153,13 +58,106 @@ void EtermApp::loadColorSchemes( const std::string& resPath ) {
|
||||
}
|
||||
}
|
||||
|
||||
UITerminal* EtermApp::terminalFromTab( UITab* tab ) {
|
||||
UITerminal* App::terminalFromTab( UITab* tab ) {
|
||||
return tab && tab->getOwnedWidget() && tab->getOwnedWidget()->isType( UI_TYPE_TERMINAL )
|
||||
? tab->getOwnedWidget()->asType<UITerminal>()
|
||||
: nullptr;
|
||||
}
|
||||
|
||||
void EtermApp::updateWindowTitle() {
|
||||
void App::savePreferences() {
|
||||
if ( config && !config->savePreferences() )
|
||||
Log::error( "Could not save eterm configuration to %s", config->getConfigPath() );
|
||||
}
|
||||
|
||||
void App::forEachTerminal( const std::function<void( UITerminal* )>& fn ) {
|
||||
if ( !tabSplitter )
|
||||
return;
|
||||
tabSplitter->forEachWidgetType(
|
||||
UI_TYPE_TERMINAL, [&fn]( UIWidget* widget ) { fn( widget->asType<UITerminal>() ); } );
|
||||
}
|
||||
|
||||
void App::createNewTerminal() {
|
||||
auto* current = tabSplitter ? tabSplitter->getCurWidget() : nullptr;
|
||||
auto* terminal =
|
||||
current && current->isType( UI_TYPE_TERMINAL ) ? current->asType<UITerminal>() : nullptr;
|
||||
switch ( config->terminal.newTerminalBehavior ) {
|
||||
case NewTerminalBehavior::VerticalSplit:
|
||||
createTerminalSplit( SplitDirection::Right, terminal );
|
||||
break;
|
||||
case NewTerminalBehavior::HorizontalSplit:
|
||||
createTerminalSplit( SplitDirection::Bottom, terminal );
|
||||
break;
|
||||
default:
|
||||
createTerminal();
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
void App::openFontPicker( bool uiFont, bool fallbackFont ) {
|
||||
const Uint32 flags = UIFontPickerDialog::ShowStyle |
|
||||
( fallbackFont ? 0 : UIFontPickerDialog::ShowSize ) |
|
||||
( !uiFont && !fallbackFont ? UIFontPickerDialog::MonospaceOnly : 0 );
|
||||
auto* dialog = UIFontPickerDialog::New( flags );
|
||||
dialog->setTitle( i18n( "select_font", "Select Font" ) );
|
||||
dialog->setCloseShortcut( KEY_ESCAPE );
|
||||
std::string currentPath = uiFont ? config->font.uiPath
|
||||
: fallbackFont ? config->font.fallbackPath
|
||||
: config->font.path;
|
||||
if ( !currentPath.empty() )
|
||||
dialog->setSelectedFont( currentPath );
|
||||
if ( !fallbackFont ) {
|
||||
auto selection = dialog->getSelection();
|
||||
selection.size = static_cast<Uint32>( uiFont ? config->font.uiSize : config->font.size );
|
||||
dialog->setSelection( selection );
|
||||
}
|
||||
dialog->setOnFontPicked( [this, uiFont, fallbackFont]( const UIFontSelection& selection ) {
|
||||
if ( selection.font.path.empty() )
|
||||
return;
|
||||
auto& resourceScope = *scene->getResourceScope();
|
||||
if ( uiFont ) {
|
||||
auto font = FontTrueType::New( "eterm-ui-font", resourceScope );
|
||||
if ( font->loadFromFile( selection.font.path ) ) {
|
||||
config->font.uiPath = selection.font.path;
|
||||
config->font.uiSize = selection.size;
|
||||
scene->getUIThemeManager()->setDefaultFont( font.get() );
|
||||
scene->getUIThemeManager()->setDefaultFontSize( config->font.uiSize );
|
||||
scene->getRoot()->reloadStyle( true, true, true, true, true );
|
||||
}
|
||||
} else if ( fallbackFont ) {
|
||||
auto font = FontTrueType::New( "eterm-fallback-font", resourceScope );
|
||||
if ( font->loadFromFile( selection.font.path ) ) {
|
||||
config->font.fallbackPath = selection.font.path;
|
||||
resourceScope.getFontService().addFallbackFont( std::move( font ) );
|
||||
}
|
||||
} else {
|
||||
auto font = FontTrueType::New( "eterm-monospace", resourceScope );
|
||||
if ( font->loadFromFile( selection.font.path ) ) {
|
||||
config->font.path = selection.font.path;
|
||||
config->font.size = selection.size;
|
||||
terminalFont = font.get();
|
||||
terminalFontSize = PixelDensity::dpToPx( config->font.size );
|
||||
FontFamily::loadFromRegular( terminalFont );
|
||||
forEachTerminal( [this]( UITerminal* terminal ) {
|
||||
terminal->setFont( terminalFont );
|
||||
terminal->setFontSize( terminalFontSize );
|
||||
} );
|
||||
}
|
||||
}
|
||||
savePreferences();
|
||||
} );
|
||||
dialog->show();
|
||||
}
|
||||
|
||||
void App::showSettings() {
|
||||
if ( settingsWindow ) {
|
||||
settingsWindow->show();
|
||||
settingsWindow->toFront();
|
||||
return;
|
||||
}
|
||||
settingsWindow = eterm::SettingsPanel::create( *this );
|
||||
}
|
||||
|
||||
void App::updateWindowTitle() {
|
||||
if ( !appWindow )
|
||||
return;
|
||||
String title{ "eterm" };
|
||||
@@ -181,7 +179,7 @@ void EtermApp::updateWindowTitle() {
|
||||
appWindow->setTitle( title );
|
||||
}
|
||||
|
||||
bool EtermApp::hasTerminals() const {
|
||||
bool App::hasTerminals() const {
|
||||
bool found = false;
|
||||
if ( tabSplitter )
|
||||
tabSplitter->forEachWidgetStoppable( [&found]( UIWidget* ) {
|
||||
@@ -191,27 +189,27 @@ bool EtermApp::hasTerminals() const {
|
||||
return found;
|
||||
}
|
||||
|
||||
bool EtermApp::hasRunningChildren( UITab* tab ) {
|
||||
bool App::hasRunningChildren( UITab* tab ) {
|
||||
auto* terminal = terminalFromTab( tab );
|
||||
return terminal && terminal->getTerm() &&
|
||||
Sys::processHasChildren( terminal->getTerm()->getProcessId() );
|
||||
}
|
||||
|
||||
void EtermApp::closeTab( UITab* tab ) {
|
||||
void App::closeTab( UITab* tab ) {
|
||||
if ( !tabSplitter || !tab || !tab->getOwnedWidget() )
|
||||
return;
|
||||
tabSplitter->closeTab( tab->getOwnedWidget()->asType<UIWidget>(),
|
||||
UITabWidget::FocusTabBehavior::Default );
|
||||
}
|
||||
|
||||
void EtermApp::queueExitCloseTab( UITab* tab ) {
|
||||
void App::queueExitCloseTab( UITab* tab ) {
|
||||
if ( tab && std::find( pendingExitCloseTabs.begin(), pendingExitCloseTabs.end(), tab ) ==
|
||||
pendingExitCloseTabs.end() ) {
|
||||
pendingExitCloseTabs.emplace_back( tab );
|
||||
}
|
||||
}
|
||||
|
||||
void EtermApp::queueExitedTabs() {
|
||||
void App::queueExitedTabs() {
|
||||
if ( !terminalConfig.closeOnExit )
|
||||
return;
|
||||
tabSplitter->forEachTab( [this]( UITab* tab ) {
|
||||
@@ -225,7 +223,7 @@ void EtermApp::queueExitedTabs() {
|
||||
} );
|
||||
}
|
||||
|
||||
void EtermApp::requestCloseTab( UITab* tab ) {
|
||||
void App::requestCloseTab( UITab* tab ) {
|
||||
if ( !warnBeforeClose || !hasRunningChildren( tab ) ) {
|
||||
closeTab( tab );
|
||||
return;
|
||||
@@ -250,7 +248,7 @@ void EtermApp::requestCloseTab( UITab* tab ) {
|
||||
closeDialog->showWhenReady();
|
||||
}
|
||||
|
||||
void EtermApp::renameSession( UITerminal* terminal ) {
|
||||
void App::renameSession( UITerminal* terminal ) {
|
||||
if ( !terminal )
|
||||
return;
|
||||
auto* msgBox =
|
||||
@@ -266,7 +264,7 @@ void EtermApp::renameSession( UITerminal* terminal ) {
|
||||
msgBox->showWhenReady();
|
||||
}
|
||||
|
||||
void EtermApp::maximizeTabWidget( UITabWidget* tabWidget ) {
|
||||
void App::maximizeTabWidget( UITabWidget* tabWidget ) {
|
||||
if ( !tabWidget || scene->getRoot()->hasChild( "detached_tab_widget_win" ) )
|
||||
return;
|
||||
|
||||
@@ -284,7 +282,7 @@ void EtermApp::maximizeTabWidget( UITabWidget* tabWidget ) {
|
||||
win->setKeyBindingCommand( "close-maximized-tab-widget",
|
||||
[this] { restoreMaximizedTabWidget(); } );
|
||||
win->getKeyBindings().addKeybind( { KEY_ESCAPE }, "close-maximized-tab-widget" );
|
||||
win->setCheckEphemeralCloseFn( [this]( Node* focusNode ) {
|
||||
win->setCheckEphemeralCloseFn( []( Node* focusNode ) {
|
||||
if ( focusNode->isType( UI_TYPE_POPUPMENU ) )
|
||||
return false;
|
||||
if ( focusNode->getSceneNode()->isUISceneNode() ) {
|
||||
@@ -335,7 +333,7 @@ void EtermApp::maximizeTabWidget( UITabWidget* tabWidget ) {
|
||||
} );
|
||||
}
|
||||
|
||||
void EtermApp::restoreMaximizedTabWidget() {
|
||||
void App::restoreMaximizedTabWidget() {
|
||||
if ( !scene || !SceneManager::isActive() )
|
||||
return;
|
||||
if ( !maximizedTabWidgetLink || !maximizedTabWidget )
|
||||
@@ -359,7 +357,7 @@ void EtermApp::restoreMaximizedTabWidget() {
|
||||
win->close();
|
||||
}
|
||||
|
||||
void EtermApp::configureTab( UITab* tab ) {
|
||||
void App::configureTab( UITab* tab ) {
|
||||
tab->on( Event::OnCreateContextMenu, [this]( const Event* event ) {
|
||||
const auto* menuEvent = static_cast<const ContextMenuEvent*>( event );
|
||||
auto* menu = menuEvent->getMenu();
|
||||
@@ -392,6 +390,7 @@ void EtermApp::configureTab( UITab* tab ) {
|
||||
terminal->getExclusiveMode() );
|
||||
exclusiveMode->setId( UITerminal::getExclusiveModeToggleCommandName() );
|
||||
addItem( i18n( "rename_session", "Rename Session" ), "", "terminal-rename" );
|
||||
addItem( i18n( "settings", "Settings" ), "settings", "open-settings" );
|
||||
|
||||
menu->addSeparator();
|
||||
const bool canMove = clickedTab->getTabWidget()->getTabCount() > 1;
|
||||
@@ -427,6 +426,8 @@ void EtermApp::configureTab( UITab* tab ) {
|
||||
maximizeTabWidget( clickedTab->getTabWidget() );
|
||||
} else if ( command == "restore-maximized-tab-widget" ) {
|
||||
restoreMaximizedTabWidget();
|
||||
} else if ( command == "open-settings" ) {
|
||||
showSettings();
|
||||
} else {
|
||||
terminal->execute( command );
|
||||
}
|
||||
@@ -437,7 +438,7 @@ void EtermApp::configureTab( UITab* tab ) {
|
||||
} );
|
||||
}
|
||||
|
||||
UITerminal* EtermApp::createTerminal( UITabWidget* target ) {
|
||||
UITerminal* App::createTerminal( UITabWidget* target ) {
|
||||
if ( !target && tabSplitter ) {
|
||||
auto* current = tabSplitter->getCurWidget();
|
||||
target = current ? tabSplitter->tabWidgetFromWidget( current )
|
||||
@@ -464,6 +465,9 @@ UITerminal* EtermApp::createTerminal( UITabWidget* target ) {
|
||||
terminal->getTerm()->setCursorMode( terminalConfig.cursorStyle );
|
||||
terminal->getTerm()->setFontHinting( terminalConfig.fontHinting );
|
||||
terminal->getTerm()->setFontAntialiasing( terminalConfig.fontAntialiasing );
|
||||
terminal->setExclusiveMode( config->terminal.exclusiveMode );
|
||||
terminal->setScrollViewType( config->terminal.scrollBarType );
|
||||
terminal->setVerticalScrollMode( config->terminal.scrollBarMode );
|
||||
if ( selectedColorScheme )
|
||||
terminal->setColorScheme( *selectedColorScheme );
|
||||
|
||||
@@ -481,6 +485,30 @@ UITerminal* EtermApp::createTerminal( UITabWidget* target ) {
|
||||
if ( terminalConfig.closeOnExit && event.type == TerminalDisplay::EventType::PROCESS_EXIT )
|
||||
queueExitCloseTab( tab );
|
||||
} );
|
||||
terminal->on( Event::OnCreateContextMenu, [this, terminal]( const Event* event ) {
|
||||
auto menu = static_cast<const ContextMenuEvent*>( event )->getMenu();
|
||||
const auto addItem = [this, menu]( const String& text, const std::string& icon,
|
||||
const std::string& command ) {
|
||||
DrawablePtr drawable;
|
||||
if ( auto* menuIcon = scene->findIcon( icon ) )
|
||||
drawable = menuIcon->createDrawable( PixelDensity::dpToPxI( 12 ) );
|
||||
auto* item = menu->add( text, std::move( drawable ) );
|
||||
item->setId( command );
|
||||
return item;
|
||||
};
|
||||
menu->addSeparator();
|
||||
addItem( i18n( "settings", "Settings" ), "settings", "open-settings" );
|
||||
menu->on( Event::OnItemClicked, [this, terminal]( const Event* itemEvent ) {
|
||||
if ( !itemEvent->getNode()->isType( UI_TYPE_MENUITEM ) )
|
||||
return;
|
||||
const auto& command = itemEvent->getNode()->getId();
|
||||
auto* previous = tabSplitter->getCurWidget();
|
||||
tabSplitter->setCurrentWidget( terminal );
|
||||
terminal->execute( command );
|
||||
if ( previous && tabSplitter->ownedWidgetExists( previous ) )
|
||||
tabSplitter->setCurrentWidget( previous );
|
||||
} );
|
||||
} );
|
||||
tabSplitter->setCurrentWidget( terminal );
|
||||
if ( !terminalConfig.executeInShell.empty() )
|
||||
terminal->executeFile( terminalConfig.executeInShell );
|
||||
@@ -489,15 +517,16 @@ UITerminal* EtermApp::createTerminal( UITabWidget* target ) {
|
||||
return terminal;
|
||||
}
|
||||
|
||||
UITerminal* EtermApp::createTerminalSplit( SplitDirection direction, UITerminal* terminal ) {
|
||||
UITerminal* App::createTerminalSplit( SplitDirection direction, UITerminal* terminal ) {
|
||||
auto* source = terminal ? tabSplitter->tabWidgetFromWidget( terminal ) : nullptr;
|
||||
auto* target = source ? tabSplitter->splitTabWidget( direction, source ) : nullptr;
|
||||
return target ? createTerminal( target ) : nullptr;
|
||||
}
|
||||
|
||||
void EtermApp::addTabKeyBindings( UITerminal* terminal ) {
|
||||
void App::addTabKeyBindings( UITerminal* terminal ) {
|
||||
tabSplitter->registerSplitterCommands( *terminal );
|
||||
terminal->setCommand( "create-new-terminal", [this] { createTerminal(); } );
|
||||
terminal->setCommand( "create-new-terminal", [this] { createNewTerminal(); } );
|
||||
terminal->setCommand( "open-settings", [this] { showSettings(); } );
|
||||
terminal->setCommand( "debug-widget-tree-view",
|
||||
[this] { UIWidgetInspector::create( scene ); } );
|
||||
terminal->setCommand( "terminal-rename", [this, terminal] { renameSession( terminal ); } );
|
||||
@@ -528,6 +557,7 @@ void EtermApp::addTabKeyBindings( UITerminal* terminal ) {
|
||||
[this, terminal] { tabSplitter->switchNextSplit( terminal ); } );
|
||||
terminal->addKeyBinding( { KEY_T, KeyMod::getDefaultModifier() | KEYMOD_SHIFT },
|
||||
"create-new-terminal" );
|
||||
terminal->addKeyBinding( { KEY_COMMA, KeyMod::getDefaultModifier() }, "open-settings" );
|
||||
terminal->addKeyBinding( { KEY_W, KeyMod::getDefaultModifier() | KEYMOD_SHIFT }, "close-tab" );
|
||||
terminal->addKeyBinding( { KEY_F11, KeyMod::getDefaultModifier() | KEYMOD_SHIFT },
|
||||
"debug-widget-tree-view" );
|
||||
@@ -551,7 +581,7 @@ void EtermApp::addTabKeyBindings( UITerminal* terminal ) {
|
||||
"switch-to-next-split" );
|
||||
}
|
||||
|
||||
bool EtermApp::closeWindow( EE::Window::Window* ) {
|
||||
bool App::closeWindow( EE::Window::Window* ) {
|
||||
if ( closeApproved || !warnBeforeClose )
|
||||
return true;
|
||||
bool running = false;
|
||||
@@ -578,25 +608,30 @@ bool EtermApp::closeWindow( EE::Window::Window* ) {
|
||||
return false;
|
||||
}
|
||||
|
||||
int EtermApp::run( int argc, char* argv[] ) {
|
||||
int App::run( int argc, char* argv[] ) {
|
||||
#ifdef EE_DEBUG
|
||||
Log::instance()->setLogToStdOut( !Runtime::isOffscreen() );
|
||||
Log::instance()->setLiveWrite( true );
|
||||
#endif
|
||||
config = std::make_unique<eterm::AppConfig>( Sys::getConfigPath( "eterm" ) );
|
||||
config->load();
|
||||
args::ArgumentParser parser( "eterm" );
|
||||
args::HelpFlag help( parser, "help", "Display this help menu", { 'h', "help" } );
|
||||
args::ValueFlag<std::string> shell( parser, "shell", "Shell name or path", { 's', "shell" },
|
||||
"" );
|
||||
config->terminal.shell );
|
||||
args::ValueFlag<std::string> shellArgs( parser, "shell-args", "Shell command line arguments",
|
||||
{ "shell-args" }, "" );
|
||||
{ "shell-args" }, config->terminal.shellArguments );
|
||||
args::ValueFlag<size_t> historySize( parser, "scrollback", "Maximum history size (lines)",
|
||||
{ 'l', "scrollback" }, 10000 );
|
||||
{ 'l', "scrollback" }, config->terminal.historySize );
|
||||
args::Flag fb( parser, "framebuffer", "Use frame buffer (more memory usage, less CPU usage)",
|
||||
{ "fb", "framebuffer" } );
|
||||
args::ValueFlag<std::string> fontPath( parser, "fontpath", "Font path", { 'f', "font" } );
|
||||
args::ValueFlag<std::string> fontPath( parser, "fontpath", "Font path", { 'f', "font" },
|
||||
config->font.path );
|
||||
args::ValueFlag<std::string> fallbackFontPath( parser, "fallback-fontpath",
|
||||
"Fallback Font path", { "fallback-font" } );
|
||||
args::ValueFlag<Float> fontSize( parser, "fontsize", "Font size (in dp)", { "fontsize" }, 11 );
|
||||
"Fallback Font path", { "fallback-font" },
|
||||
config->font.fallbackPath );
|
||||
args::ValueFlag<Float> fontSize( parser, "fontsize", "Font size (in dp)", { "fontsize" },
|
||||
config->font.size );
|
||||
const std::unordered_map<std::string, FontHinting> fontHintingMap{
|
||||
{ "none", FontHinting::None },
|
||||
{ "slight", FontHinting::Slight },
|
||||
@@ -604,7 +639,7 @@ int EtermApp::run( int argc, char* argv[] ) {
|
||||
};
|
||||
args::MapFlag<std::string, FontHinting> fontHinting(
|
||||
parser, "font-hinting", "Font hinting mode (accepted values: none, slight, full)",
|
||||
{ "font-hinting" }, fontHintingMap, FontHinting::Full );
|
||||
{ "font-hinting" }, fontHintingMap, config->font.hinting );
|
||||
const std::unordered_map<std::string, FontAntialiasing> fontAntialiasingMap{
|
||||
{ "none", FontAntialiasing::None },
|
||||
{ "grayscale", FontAntialiasing::Grayscale },
|
||||
@@ -613,33 +648,35 @@ int EtermApp::run( int argc, char* argv[] ) {
|
||||
args::MapFlag<std::string, FontAntialiasing> fontAntialiasing(
|
||||
parser, "font-antialiasing",
|
||||
"Font antialiasing mode (accepted values: none, grayscale, subpixel)",
|
||||
{ "font-antialiasing" }, fontAntialiasingMap, FontAntialiasing::Grayscale );
|
||||
args::ValueFlag<Float> width( parser, "winwidth", "Window width (in dp)", { "width" }, 1280 );
|
||||
{ "font-antialiasing" }, fontAntialiasingMap, config->font.antialiasing );
|
||||
args::ValueFlag<Float> width( parser, "winwidth", "Window width (in dp)", { "width" },
|
||||
config->windowState.size.getWidth() );
|
||||
args::ValueFlag<Float> height( parser, "winheight", "Window height (in dp)", { "height" },
|
||||
720 );
|
||||
config->windowState.size.getHeight() );
|
||||
args::ValueFlag<Float> pixelDensity( parser, "pixel-density",
|
||||
"Set default application pixel density",
|
||||
{ 'd', "pixel-density" } );
|
||||
args::Positional<std::string> wd( parser, "wording-dir", "Working Directory / executable" );
|
||||
args::Flag closeOnExit( parser, "close-on-exit",
|
||||
"close the application when the executable exits", { 'c', "close" } );
|
||||
args::ValueFlag<std::string> executeInShell(
|
||||
parser, "execute-in-shell", "execute program in shell", { 'e', "execute" }, "" );
|
||||
args::ValueFlag<std::string> executeInShell( parser, "execute-in-shell",
|
||||
"execute program in shell", { 'e', "execute" },
|
||||
config->terminal.executeInShell );
|
||||
args::Flag vsync( parser, "vsync", "Enable vsync", { "vsync" } );
|
||||
args::ValueFlag<std::string> colorScheme( parser, "color-scheme", "Load color scheme",
|
||||
{ "color-scheme" }, "" );
|
||||
{ "color-scheme" }, config->theme.colorScheme );
|
||||
args::Flag listColorSchemes( parser, "color-schemes", "Lists color schemes",
|
||||
{ "list-color-schemes" } );
|
||||
args::ValueFlag<Uint32> maxFPS( parser, "max-fps",
|
||||
"Maximum rendering frames per second of the terminal. Default "
|
||||
"value will be the refresh rate of the screen.",
|
||||
{ "max-fps" }, 0 );
|
||||
{ "max-fps" }, config->window.maxFPS );
|
||||
args::MapFlag<std::string, TerminalCursorMode> cursorStyle(
|
||||
parser, "cursor-style",
|
||||
"Sets the cursor-style (accepted values: blinking_block, steady_block, blink_underline, "
|
||||
"steady_underline, blink_bar, steady_bar)",
|
||||
{ "cursor-style" }, TerminalCursorHelper::getTerminalCursorModeMap(),
|
||||
TerminalCursorMode::SteadyUnderline );
|
||||
config->terminal.cursorStyle );
|
||||
args::Flag benchmarkModeFlag(
|
||||
parser, "benchmark-mode",
|
||||
"Render as much as possible to measure the rendering performance.", { "benchmark-mode" } );
|
||||
@@ -651,7 +688,7 @@ int EtermApp::run( int argc, char* argv[] ) {
|
||||
"Always show the tab bar, even with a single tab.",
|
||||
{ "always-show-tab-bar" } );
|
||||
args::ValueFlag<size_t> initialTabs( parser, "tabs", "Number of initial terminal tabs",
|
||||
{ "tabs" }, 1 );
|
||||
{ "tabs" }, config->terminal.initialTabs );
|
||||
|
||||
try {
|
||||
parser.ParseCLI( argc, argv );
|
||||
@@ -667,56 +704,105 @@ int EtermApp::run( int argc, char* argv[] ) {
|
||||
std::cerr << parser;
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
if ( !config->savePreferences() )
|
||||
Log::error( "Could not save eterm configuration to %s", config->getConfigPath() );
|
||||
|
||||
config->terminal.shell = shell.Get();
|
||||
config->terminal.shellArguments = shellArgs.Get();
|
||||
config->terminal.historySize = historySize.Get();
|
||||
config->font.path = fontPath.Get();
|
||||
config->font.fallbackPath = fallbackFontPath.Get();
|
||||
config->font.size = fontSize.Get();
|
||||
config->font.hinting = fontHinting.Get();
|
||||
config->font.antialiasing = fontAntialiasing.Get();
|
||||
config->windowState.size = { static_cast<int>( width.Get() ),
|
||||
static_cast<int>( height.Get() ) };
|
||||
if ( pixelDensity )
|
||||
config->window.pixelDensity = pixelDensity.Get();
|
||||
if ( wd )
|
||||
config->terminal.workingDirectory = wd.Get();
|
||||
config->terminal.executeInShell = executeInShell.Get();
|
||||
config->theme.colorScheme = colorScheme.Get();
|
||||
config->window.maxFPS = maxFPS.Get();
|
||||
config->terminal.cursorStyle = cursorStyle.Get();
|
||||
config->terminal.initialTabs = initialTabs.Get();
|
||||
config->terminal.useFrameBuffer |= fb.Get();
|
||||
config->terminal.closeOnExit |= closeOnExit.Get();
|
||||
config->window.vsync |= vsync.Get();
|
||||
config->window.benchmarkMode |= benchmarkModeFlag.Get();
|
||||
config->window.warnBeforeClose |= warnBeforeCloseFlag.Get();
|
||||
config->window.alwaysShowTabBar |= alwaysShowTabBar.Get();
|
||||
|
||||
const std::string initialWorkingDirectory = FileSystem::getCurrentWorkingDirectory();
|
||||
const std::string resPath = getResourcePath();
|
||||
if ( listColorSchemes.Get() || colorScheme )
|
||||
loadColorSchemes( resPath );
|
||||
loadColorSchemes( resPath );
|
||||
if ( listColorSchemes.Get() ) {
|
||||
std::cout << "Color schemes:\n";
|
||||
for ( const auto& colorSchemeEntry : terminalColorSchemes )
|
||||
std::cout << "\t" << colorSchemeEntry.first << "\n";
|
||||
return EXIT_SUCCESS;
|
||||
}
|
||||
if ( colorScheme ) {
|
||||
auto colorSchemeIt = terminalColorSchemes.find( colorScheme.Get() );
|
||||
if ( !config->theme.colorScheme.empty() ) {
|
||||
auto colorSchemeIt = terminalColorSchemes.find( config->theme.colorScheme );
|
||||
if ( colorSchemeIt != terminalColorSchemes.end() )
|
||||
selectedColorScheme = &colorSchemeIt->second;
|
||||
}
|
||||
|
||||
DisplayManager* displayManager = Engine::instance()->getDisplayManager();
|
||||
Display* currentDisplay = displayManager->getDisplayIndex( 0 );
|
||||
Display* currentDisplay = displayManager->getDisplayIndex(
|
||||
config->windowState.displayIndex >= 0 &&
|
||||
config->windowState.displayIndex < displayManager->getDisplayCount()
|
||||
? config->windowState.displayIndex
|
||||
: 0 );
|
||||
if ( !currentDisplay ) {
|
||||
std::cerr << "Display not found, exiting" << std::endl;
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
|
||||
Sizei windowSize( width.Get(), height.Get() );
|
||||
Sizei windowSize( config->windowState.size );
|
||||
const auto displaySize = currentDisplay->getUsableBounds().getSize();
|
||||
if ( displaySize.getWidth() > 0 && windowSize.getWidth() >= displaySize.getWidth() )
|
||||
windowSize.setWidth( static_cast<int>( displaySize.getWidth() * 0.8f ) );
|
||||
if ( displaySize.getHeight() > 0 && windowSize.getHeight() >= displaySize.getHeight() )
|
||||
windowSize.setHeight( static_cast<int>( displaySize.getHeight() * 0.75f ) );
|
||||
|
||||
FontTrueTypePtr uiFont;
|
||||
if ( !config->font.uiPath.empty() && FileSystem::fileExists( config->font.uiPath ) ) {
|
||||
uiFont = FontTrueType::New( "eterm-ui-font" );
|
||||
if ( !uiFont->loadFromFile( config->font.uiPath ) )
|
||||
uiFont.reset();
|
||||
}
|
||||
UIApplication::Settings appSettings;
|
||||
appSettings.basePath = FileSystem::removeLastFolderFromPath( resPath );
|
||||
appSettings.pixelDensity =
|
||||
pixelDensity ? pixelDensity.Get() : currentDisplay->getPixelDensity();
|
||||
appSettings.fontHinting = fontHinting.Get();
|
||||
appSettings.fontAntialiasing = fontAntialiasing.Get();
|
||||
appSettings.pixelDensity = config->window.pixelDensity > 0 ? config->window.pixelDensity
|
||||
: currentDisplay->getPixelDensity();
|
||||
appSettings.fontHinting = config->font.hinting;
|
||||
appSettings.fontAntialiasing = config->font.antialiasing;
|
||||
appSettings.baseFont = uiFont.get();
|
||||
const Int32 frameRateLimit =
|
||||
benchmarkModeFlag.Get()
|
||||
? 0
|
||||
: static_cast<Int32>( maxFPS.Get() ? maxFPS.Get() : currentDisplay->getRefreshRate() );
|
||||
UIApplication app( WindowSettings( windowSize.getWidth(), windowSize.getHeight(), "eterm",
|
||||
WindowStyle::Default, WindowBackend::Default, 32,
|
||||
resPath + "icon/eterm.png",
|
||||
appSettings.pixelDensity.value() ),
|
||||
appSettings, ContextSettings( vsync.Get(), frameRateLimit ) );
|
||||
config->window.benchmarkMode ? 0 : static_cast<Int32>( config->window.maxFPS );
|
||||
UIApplication app(
|
||||
WindowSettings( windowSize.getWidth(), windowSize.getHeight(), "eterm",
|
||||
WindowStyle::Default, WindowBackend::Default, 32,
|
||||
resPath + "icon/eterm.png", appSettings.pixelDensity.value() ),
|
||||
appSettings,
|
||||
ContextSettings( config->window.vsync, frameRateLimit, config->window.multisamples,
|
||||
config->window.rendererVersion ) );
|
||||
appWindow = app.getWindow();
|
||||
scene = app.getUI();
|
||||
if ( !appWindow || !appWindow->isOpen() || !scene )
|
||||
return EXIT_FAILURE;
|
||||
scene->setColorSchemePreference( config->theme.uiColorScheme );
|
||||
scene->getUIThemeManager()->setDefaultFontSize( config->font.uiSize );
|
||||
if ( config->windowState.position != Vector2i( -1, -1 ) ) {
|
||||
appWindow->setPosition( config->windowState.position.x +
|
||||
( config->windowState.maximized ? -1 : 0 ),
|
||||
config->windowState.position.y );
|
||||
}
|
||||
#if EE_PLATFORM != EE_PLATFORM_EMSCRIPTEN && EE_PLATFORM != EE_PLATFORM_MACOS
|
||||
if ( config->windowState.maximized )
|
||||
appWindow->maximize();
|
||||
#endif
|
||||
FileSystem::changeWorkingDirectory( initialWorkingDirectory );
|
||||
appWindow->setClearColor( RGB( 0, 0, 0 ) );
|
||||
scene->getUIThemeManager()->setDefaultEffectsEnabled( false );
|
||||
@@ -748,9 +834,9 @@ int EtermApp::run( int argc, char* argv[] ) {
|
||||
"eterm", remixIconFont.get(), noniconsFont.get(), codIconFont.get() ) );
|
||||
terminalIcon = scene->findIcon( "terminal" );
|
||||
}
|
||||
if ( fontPath && FileSystem::fileExists( fontPath.Get() ) ) {
|
||||
if ( !config->font.path.empty() && FileSystem::fileExists( config->font.path ) ) {
|
||||
terminalFont = FontTrueType::New( "eterm-monospace", resourceScope ).get();
|
||||
if ( terminalFont->loadFromFile( fontPath.Get() ) )
|
||||
if ( terminalFont->loadFromFile( config->font.path ) )
|
||||
FontFamily::loadFromRegular( terminalFont );
|
||||
else
|
||||
terminalFont = nullptr;
|
||||
@@ -764,34 +850,37 @@ int EtermApp::run( int argc, char* argv[] ) {
|
||||
FontFamily::loadFromRegular( terminalFont, "DejaVuSansMono" );
|
||||
}
|
||||
|
||||
if ( fallbackFontPath ) {
|
||||
if ( FileSystem::fileExists( fallbackFontPath.Get() ) ) {
|
||||
if ( !config->font.fallbackPath.empty() ) {
|
||||
if ( FileSystem::fileExists( config->font.fallbackPath ) ) {
|
||||
auto fallback = FontTrueType::New( "eterm-fallback-font", resourceScope );
|
||||
if ( fallback->loadFromFile( fallbackFontPath.Get() ) )
|
||||
if ( fallback->loadFromFile( config->font.fallbackPath ) )
|
||||
resourceScope.getFontService().addFallbackFont( std::move( fallback ) );
|
||||
}
|
||||
} else if ( auto fallback = resourceScope.findFont( "DroidSansFallbackFull" ) ) {
|
||||
resourceScope.getFontService().addFallbackFont( std::move( fallback ) );
|
||||
}
|
||||
|
||||
const std::string launchPath = wd ? wd.Get() : initialWorkingDirectory;
|
||||
const std::string launchPath = config->terminal.workingDirectory.empty()
|
||||
? initialWorkingDirectory
|
||||
: config->terminal.workingDirectory;
|
||||
FileInfo launchFile( launchPath );
|
||||
const bool launchExecutable = launchFile.isRegularFile() && launchFile.isExecutable();
|
||||
terminalConfig.program = launchExecutable ? launchFile.getFilepath() : shell.Get();
|
||||
terminalConfig.arguments =
|
||||
shellArgs ? String::split( shellArgs.Get() ) : std::vector<std::string>{};
|
||||
terminalConfig.program = launchExecutable ? launchFile.getFilepath() : config->terminal.shell;
|
||||
terminalConfig.arguments = config->terminal.shellArguments.empty()
|
||||
? std::vector<std::string>{}
|
||||
: String::split( config->terminal.shellArguments );
|
||||
terminalConfig.workingDirectory = launchFile.getDirectoryPath();
|
||||
terminalConfig.executeInShell = executeInShell.Get();
|
||||
terminalConfig.historySize = historySize.Get();
|
||||
terminalConfig.cursorStyle = cursorStyle.Get();
|
||||
terminalConfig.fontHinting = fontHinting.Get();
|
||||
terminalConfig.fontAntialiasing = fontAntialiasing.Get();
|
||||
terminalConfig.useFrameBuffer = fb.Get();
|
||||
terminalConfig.keepAlive = !launchExecutable && !shell;
|
||||
terminalConfig.closeOnExit = closeOnExit.Get();
|
||||
warnBeforeClose = warnBeforeCloseFlag.Get();
|
||||
benchmarkMode = benchmarkModeFlag.Get();
|
||||
terminalFontSize = PixelDensity::dpToPx( fontSize.Get() );
|
||||
terminalConfig.executeInShell = config->terminal.executeInShell;
|
||||
terminalConfig.historySize = config->terminal.historySize;
|
||||
terminalConfig.cursorStyle = config->terminal.cursorStyle;
|
||||
terminalConfig.fontHinting = config->font.hinting;
|
||||
terminalConfig.fontAntialiasing = config->font.antialiasing;
|
||||
terminalConfig.useFrameBuffer = config->terminal.useFrameBuffer;
|
||||
terminalConfig.keepAlive = !launchExecutable && config->terminal.shell.empty();
|
||||
terminalConfig.closeOnExit = config->terminal.closeOnExit;
|
||||
warnBeforeClose = config->window.warnBeforeClose;
|
||||
benchmarkMode = config->window.benchmarkMode;
|
||||
terminalFontSize = PixelDensity::dpToPx( config->font.size );
|
||||
|
||||
mainLayout = UILinearLayout::NewVertical();
|
||||
mainLayout->setParent( scene->getRoot() );
|
||||
@@ -799,7 +888,7 @@ int EtermApp::run( int argc, char* argv[] ) {
|
||||
mainLayout->setPixelsSize( appWindow->getSize().asFloat() );
|
||||
|
||||
tabSplitter = UITabWidgetSplitter::New( &splitterClient, scene );
|
||||
tabSplitter->setHideTabBarOnSingleTab( !alwaysShowTabBar.Get() );
|
||||
tabSplitter->setHideTabBarOnSingleTab( !config->window.alwaysShowTabBar );
|
||||
tabSplitter->setCanCreateSplitFn( [this]( SplitDirection, UIWidget* ) {
|
||||
restoreMaximizedTabWidget();
|
||||
return true;
|
||||
@@ -841,7 +930,8 @@ int EtermApp::run( int argc, char* argv[] ) {
|
||||
}
|
||||
mainLayout->updateLayout();
|
||||
|
||||
for ( size_t tab = 0; tab < eemax( static_cast<size_t>( 1 ), initialTabs.Get() ); ++tab ) {
|
||||
for ( size_t tab = 0; tab < eemax( static_cast<size_t>( 1 ), config->terminal.initialTabs );
|
||||
++tab ) {
|
||||
if ( !createTerminal( tabs ) ) {
|
||||
appWindow->showMessageBox(
|
||||
EE::Window::Window::MessageBoxType::Error, "eterm",
|
||||
@@ -878,12 +968,15 @@ int EtermApp::run( int argc, char* argv[] ) {
|
||||
secondsCounter.restart();
|
||||
}
|
||||
} );
|
||||
config->captureWindowState( appWindow );
|
||||
if ( !config->saveWindowState() )
|
||||
Log::error( "Could not save eterm window state to %s", config->getConfigPath() );
|
||||
return EXIT_SUCCESS;
|
||||
}
|
||||
|
||||
} // namespace
|
||||
} // namespace eterm
|
||||
|
||||
EE_MAIN_FUNC int main( int argc, char* argv[] ) {
|
||||
EtermApp app;
|
||||
App app;
|
||||
return app.run( argc, argv );
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user