diff --git a/src/Main.cc b/src/Main.cc index 7fb3b3ff18a661594cab1def4edf71ebc839162a..1fcc24a12a4beb33e5f79e3135b0eeb6894b3ebb 100644 --- a/src/Main.cc +++ b/src/Main.cc @@ -1,10 +1,7 @@ #include "VivyApplication.hh" -#include "VivyCli.hh" -#include "Lib/Script/LuaContext.hh" int main(int argc, char **argv) noexcept { - return (argc >= 2) ? (Vivy::VivyCli(argc, argv).exec()) - : (Vivy::VivyApplication(argc, argv).exec()); + return Vivy::VivyApplication(argc, argv).exec(); } diff --git a/src/VivyApplication.cc b/src/VivyApplication.cc index 8f7e46d9f507e8c0b348ce4110d0efa9a07de33b..50b8648280244aba73b8025501014616736c17df 100644 --- a/src/VivyApplication.cc +++ b/src/VivyApplication.cc @@ -11,6 +11,12 @@ VivyApplication::VivyApplication(int &argc, char **argv) documentStore = std::make_shared<VivyDocumentStore>(); scriptStore = std::make_shared<ScriptStore>(); VIVY_LOG_CTOR() << "Construction is OK"; + + if (argc >= 2) { + selectedDoc = scriptStore->loadDocument(QString::fromUtf8(argv[1])); + selectedType = ApplicationType::CLI; + VIVY_LOG_CTOR() << "Select the ApplicationType::CLI"; + } } void @@ -62,15 +68,30 @@ VivyApplication::exec() noexcept // Cursor blinking setCursorFlashTime(0); - // Show the main window - mainWindowPtr = std::make_shared<MainWindow>(); - mainWindowPtr->show(); + switch (selectedType) { + case ApplicationType::CLI: { + if ((selectedDoc == nullptr) || (!scriptStore->executeScript(selectedDoc->getUuid()))) + return 1; - logInfo() << "Entering the main event loop"; + for (const auto &str : scriptStore->getLoadedModules()) { + std::cout << "Module " << str << " was loaded!\n"; + [[maybe_unused]] const auto *mod = scriptStore->getModule(str); + } + return 0; + } - // Main loop - flushLogSink(); - return QApplication::exec(); + case ApplicationType::GUI: { + // Show the main window + mainWindowPtr = std::make_shared<MainWindow>(); + mainWindowPtr->show(); + + logInfo() << "Entering the main event loop"; + + // Main loop + flushLogSink(); + return QApplication::exec(); + } + } } QFont diff --git a/src/VivyApplication.hh b/src/VivyApplication.hh index 9ac75fed021016596743e7466e10c089b1009196..543ce040d094965db4fc60185bc4ac60f2dae540 100644 --- a/src/VivyApplication.hh +++ b/src/VivyApplication.hh @@ -37,6 +37,7 @@ class MainWindow; class ScriptStore; class VivyDocumentStore; class AbstractDocument; +class ScriptDocument; // Vivy application class class VivyApplication : public QApplication { @@ -45,6 +46,8 @@ class VivyApplication : public QApplication { VIVY_DCL_LOG_DISPATCH(logSink, stderrLogDispathcer, StderrLogSinkDispatcher) VIVY_LOGGABLE_OBJECT(logSink, APPLICATION, logger) + enum class ApplicationType { GUI, CLI }; + public: std::shared_ptr<VivyDocumentStore> documentStore; std::shared_ptr<ScriptStore> scriptStore; @@ -70,6 +73,10 @@ private: std::shared_ptr<MainWindow> mainWindowPtr{ nullptr }; bool useFakeVim{ false }; + ApplicationType selectedType{ ApplicationType::GUI }; + + // ApplicationType::CLI Only! + std::shared_ptr<ScriptDocument> selectedDoc{ nullptr }; public: VivyApplication(int &argc, char **argv); diff --git a/src/VivyCli.cc b/src/VivyCli.cc deleted file mode 100644 index 0dedba63eb20d103bb628c7a8ad915dfa44ce38d..0000000000000000000000000000000000000000 --- a/src/VivyCli.cc +++ /dev/null @@ -1,27 +0,0 @@ -#include "VivyCli.hh" -#include <iostream> -#include <QTextCodec> - -using namespace Vivy; - -VivyCli::VivyCli(int &argc, char **argv) noexcept -{ - if (argc >= 2) { - selectedDoc = scriptStore.loadDocument(QString::fromUtf8(argv[1])); - } -} - -int -VivyCli::exec() noexcept -{ - QTextCodec::setCodecForLocale(QTextCodec::codecForName("UTF-8")); - - if ((selectedDoc == nullptr) || (!scriptStore.executeScript(selectedDoc->getUuid()))) - return 1; - - for (const auto &str : scriptStore.getLoadedModules()) { - std::cout << "Module " << str << " was loaded!\n"; - [[maybe_unused]] const auto *mod = scriptStore.getModule(str); - } - return 0; -} diff --git a/src/VivyCli.hh b/src/VivyCli.hh deleted file mode 100644 index 9ceef273fa57a52fb9d2e0d2bfbf7eb31aefb037..0000000000000000000000000000000000000000 --- a/src/VivyCli.hh +++ /dev/null @@ -1,19 +0,0 @@ -#pragma once - -#ifndef __cplusplus -#error "This is a C++ header" -#endif - -#include "Lib/Script/ScriptStore.hh" - -namespace Vivy -{ -class VivyCli final { - ScriptStore scriptStore{}; - std::shared_ptr<ScriptDocument> selectedDoc{ nullptr }; - -public: - VivyCli(int &argc, char **argv) noexcept; - int exec() noexcept; -}; -}