Skip to content
Extraits de code Groupes Projets
Vérifiée Valider fcc86722 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 6f2598e3
Aucune branche associée trouvée
Aucune étiquette associée trouvée
1 requête de fusion!21Add clean logs support + dependent MR
#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();
}
......@@ -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
......
......@@ -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);
......
#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