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
Branches
Aucune étiquette associée trouvée
Aucune requête de fusion associée trouvée
#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,6 +68,19 @@ VivyApplication::exec() noexcept ...@@ -62,6 +68,19 @@ VivyApplication::exec() noexcept
// Cursor blinking // Cursor blinking
setCursorFlashTime(0); setCursorFlashTime(0);
switch (selectedType) {
case ApplicationType::CLI: {
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;
}
case ApplicationType::GUI: {
// Show the main window // Show the main window
mainWindowPtr = std::make_shared<MainWindow>(); mainWindowPtr = std::make_shared<MainWindow>();
mainWindowPtr->show(); mainWindowPtr->show();
...@@ -72,6 +91,8 @@ VivyApplication::exec() noexcept ...@@ -72,6 +91,8 @@ VivyApplication::exec() noexcept
flushLogSink(); flushLogSink();
return QApplication::exec(); return QApplication::exec();
} }
}
}
QFont QFont
VivyApplication::getApplicationFont(Font id) const noexcept VivyApplication::getApplicationFont(Font id) const noexcept
......
...@@ -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.
Veuillez vous inscrire ou vous pour commenter