Skip to content
Extraits de code Groupes Projets
Vérifiée Valider 064c56e0 rédigé par Kubat's avatar Kubat
Parcourir les fichiers

MISC: Get ride of VivyCli and everything is placed in VivyApplication (because...

MISC: Get ride of VivyCli and everything is placed in VivyApplication (because of the way to get the log sink)
parent 478cc5cf
Aucune branche associée trouvée
Aucune étiquette associée trouvée
Aucune requête de fusion associée trouvée
Ce commit fait partie de la requête de fusion !21. Les commentaires créés ici seront créés dans le contexte de cette requête de fusion.
#include "VivyApplication.hh" #include "VivyApplication.hh"
#include "VivyCli.hh"
#include "Lib/Script/LuaContext.hh"
int int
main(int argc, char **argv) noexcept main(int argc, char **argv) noexcept
{ {
return (argc >= 2) ? (Vivy::VivyCli(argc, argv).exec()) return Vivy::VivyApplication(argc, argv).exec();
: (Vivy::VivyApplication(argc, argv).exec());
} }
...@@ -11,6 +11,12 @@ VivyApplication::VivyApplication(int &argc, char **argv) ...@@ -11,6 +11,12 @@ VivyApplication::VivyApplication(int &argc, char **argv)
documentStore = std::make_shared<VivyDocumentStore>(); documentStore = std::make_shared<VivyDocumentStore>();
scriptStore = std::make_shared<ScriptStore>(); scriptStore = std::make_shared<ScriptStore>();
VIVY_LOG_CTOR() << "Construction is OK"; 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 void
...@@ -62,15 +68,30 @@ VivyApplication::exec() noexcept ...@@ -62,15 +68,30 @@ VivyApplication::exec() noexcept
// Cursor blinking // Cursor blinking
setCursorFlashTime(0); setCursorFlashTime(0);
// Show the main window switch (selectedType) {
mainWindowPtr = std::make_shared<MainWindow>(); case ApplicationType::CLI: {
mainWindowPtr->show(); 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 case ApplicationType::GUI: {
flushLogSink(); // Show the main window
return QApplication::exec(); mainWindowPtr = std::make_shared<MainWindow>();
mainWindowPtr->show();
logInfo() << "Entering the main event loop";
// Main loop
flushLogSink();
return QApplication::exec();
}
}
} }
QFont QFont
......
...@@ -37,6 +37,7 @@ class MainWindow; ...@@ -37,6 +37,7 @@ class MainWindow;
class ScriptStore; class ScriptStore;
class VivyDocumentStore; class VivyDocumentStore;
class AbstractDocument; class AbstractDocument;
class ScriptDocument;
// Vivy application class // Vivy application class
class VivyApplication : public QApplication { class VivyApplication : public QApplication {
...@@ -45,6 +46,8 @@ class VivyApplication : public QApplication { ...@@ -45,6 +46,8 @@ class VivyApplication : public QApplication {
VIVY_DCL_LOG_DISPATCH(logSink, stderrLogDispathcer, StderrLogSinkDispatcher) VIVY_DCL_LOG_DISPATCH(logSink, stderrLogDispathcer, StderrLogSinkDispatcher)
VIVY_LOGGABLE_OBJECT(logSink, APPLICATION, logger) VIVY_LOGGABLE_OBJECT(logSink, APPLICATION, logger)
enum class ApplicationType { GUI, CLI };
public: public:
std::shared_ptr<VivyDocumentStore> documentStore; std::shared_ptr<VivyDocumentStore> documentStore;
std::shared_ptr<ScriptStore> scriptStore; std::shared_ptr<ScriptStore> scriptStore;
...@@ -70,6 +73,10 @@ private: ...@@ -70,6 +73,10 @@ private:
std::shared_ptr<MainWindow> mainWindowPtr{ nullptr }; std::shared_ptr<MainWindow> mainWindowPtr{ nullptr };
bool useFakeVim{ false }; bool useFakeVim{ false };
ApplicationType selectedType{ ApplicationType::GUI };
// ApplicationType::CLI Only!
std::shared_ptr<ScriptDocument> selectedDoc{ nullptr };
public: public:
VivyApplication(int &argc, char **argv); VivyApplication(int &argc, char **argv);
......
#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;
}
#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;
};
}
0% Chargement en cours ou .
You are about to add 0 people to the discussion. Proceed with caution.
Terminez d'abord l'édition de ce message.
Veuillez vous inscrire ou vous pour commenter