From f077d7a354f8df7559294ef50d291e5a7bbf7ad1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mart=C3=ADn=20Lucas=20Golini?= Date: Sun, 8 Jan 2023 22:01:19 -0300 Subject: [PATCH] eterm: Allow support for custom color schemes. --- src/tools/eterm/eterm.cpp | 38 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 38 insertions(+) diff --git a/src/tools/eterm/eterm.cpp b/src/tools/eterm/eterm.cpp index 8560e5ef5..f50fa221a 100644 --- a/src/tools/eterm/eterm.cpp +++ b/src/tools/eterm/eterm.cpp @@ -9,6 +9,24 @@ Clock secondsCounter; Time frameTime{ Time::Zero }; bool benchmarkMode{ false }; std::string windowStringData; +std::map terminalColorSchemes; + +void loadColorSchemes( const std::string& resPath ) { + auto configPath = Sys::getConfigPath( "eterm" ); + auto colorSchemes = + TerminalColorScheme::loadFromFile( resPath + "colorschemes/terminalcolorschemes.conf" ); + auto colorSchemesPath = configPath + FileSystem::getOSSlash() + "colorschemes"; + if ( FileSystem::isDirectory( colorSchemesPath ) ) { + auto colorSchemesFiles = FileSystem::filesGetInPath( colorSchemesPath ); + for ( auto& file : colorSchemesFiles ) { + auto colorSchemesInFile = TerminalColorScheme::loadFromFile( file ); + for ( auto& coloScheme : colorSchemesInFile ) + colorSchemes.emplace_back( coloScheme ); + } + } + for ( auto colorScheme : colorSchemes ) + terminalColorSchemes.insert( { colorScheme.getName(), colorScheme } ); +} void inputCallback( InputEvent* event ) { if ( !terminal || event->Type == InputEvent::EventsSent ) @@ -134,6 +152,10 @@ EE_MAIN_FUNC int main( int argc, char* argv[] ) { args::ValueFlag executeInShell( parser, "execute-in-shell", "execute program in shell", { 'e', "execute" }, "" ); args::Flag vsync( parser, "vsync", "Enable vsync", { "vsync" } ); + args::ValueFlag colorScheme( parser, "color-scheme", "Load color scheme", + { "color-scheme" }, "" ); + args::Flag listColorSchemes( parser, "color-schemes", "Lists color schemes", + { "list-color-schemes" } ); args::ValueFlag maxFPS( parser, "max-fps", "Maximum rendering frames per second of the terminal. Default " "value will be the refresh rate of the screen.", @@ -177,6 +199,16 @@ EE_MAIN_FUNC int main( int argc, char* argv[] ) { resPath += "assets"; FileSystem::dirAddSlashAtEnd( resPath ); + if ( listColorSchemes.Get() || colorScheme ) + loadColorSchemes( resPath ); + + if ( listColorSchemes.Get() ) { + std::cout << "Color schemes:\n"; + for ( auto colorScheme : terminalColorSchemes ) + std::cout << "\t" << colorScheme.first << "\n"; + return EXIT_SUCCESS; + } + displayManager->enableScreenSaver(); displayManager->enableMouseFocusClickThrough(); displayManager->disableBypassCompositor(); @@ -244,6 +276,12 @@ EE_MAIN_FUNC int main( int argc, char* argv[] ) { } } ); + if ( colorScheme ) { + auto selColorScheme = terminalColorSchemes.find( colorScheme.Get() ); + if ( selColorScheme != terminalColorSchemes.end() ) + terminal->setColorScheme( selColorScheme->second ); + } + if ( !executeInShell.Get().empty() ) terminal->executeFile( executeInShell.Get() );