Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include "hci1.h"
- #include <boost/filesystem.hpp>
- #include <boost/filesystem/fstream.hpp>
- #include "magic.h"
- #include "gitpp5.h"
- const unsigned limit=10;
- const char spacebar=32;
- const char escape=0x1b;
- /////////////////////////////////CONFIG CLASSES/////////////////////////////////
- class EDIT_CONFIG : public HCI_APPLICATION {
- public:
- EDIT_CONFIG(GITPP::CONFIG::ITEM &config)
- : HCI_APPLICATION(config.name()),
- _config(config)
- {
- }
- private:
- void show() {
- std::string temp;
- std::cout << "Enter changes: ";
- std::cin >> temp;
- auto c = _repo.config();
- c.create(_config.name());
- c[_config.name()] = temp;
- std::cout << _config.name();
- }
- private:
- GITPP::REPO _repo;
- GITPP::CONFIG::ITEM _config;
- };
- class CONFIG_MENU : public HCI_MENU {
- public:
- explicit CONFIG_MENU(HCI_APPLICATION& ctx)
- : HCI_MENU(ctx),
- _ctx(ctx) {}
- ~CONFIG_MENU() override {
- clear();
- }
- void populate() {
- purge();
- int configno = 0;
- for(auto i : _repo.config()){
- add(char ('a'+configno), new EDIT_CONFIG(i));
- ++configno;
- }
- add('q', &hci_quit);
- add(escape, &hci_quit); //Quits since there isn't a menu prior to menu. ///////////////////////needs changing
- }
- public:
- void enter() {
- while(true) {
- try {
- HCI_MENU::enter();
- break;
- }
- catch(const HCI_LEAVE& e) {
- continue;
- }
- }
- }
- void show() {
- populate();
- std::cout << "Configure Menu. Select an element to edit" << "\n" << std::endl;
- HCI_MENU::show();
- std::cout << "\n";
- }
- private:
- HCI_APPLICATION& _ctx;
- GITPP::REPO _repo;
- };
- class CONFIG : public HCI_APPLICATION {
- public:
- CONFIG()
- : HCI_APPLICATION("Configure repository"), _config(*this) {}
- public:
- void show() override {
- while(true) {
- try {
- _config.enter();
- }
- catch(const HCI_ESCAPE& e) {
- break;
- }
- }
- }
- private:
- CONFIG_MENU _config;
- };
- class CONFIG_SHOWER : public HCI_MENU {
- public:
- explicit CONFIG_SHOWER(HCI_APPLICATION& ctx)
- : HCI_MENU(ctx),
- _ctx(ctx) {}
- ~CONFIG_SHOWER() override {
- clear();
- }
- void populate() {
- purge();
- for(auto i : _repo.config()){
- std::cout << i.name() << ": " << i.value() << std::endl;
- }
- add('q', &hci_quit);
- add(escape, &hci_quit); //Quits since there isn't a menu prior to menu. ///////////////////////needs changing
- }
- public:
- void enter() {
- while(true) {
- try {
- HCI_MENU::enter();
- break;
- }
- catch(const HCI_LEAVE& e) {
- continue;
- }
- }
- }
- void show() {
- populate();
- std::cout << "Configure Menu. Choose " << "\n" << std::endl;
- HCI_MENU::show();
- std::cout << "\n";
- }
- private:
- HCI_APPLICATION& _ctx;
- GITPP::REPO _repo;
- };
- class LIST_CONFIG : public HCI_APPLICATION {
- public:
- LIST_CONFIG()
- : HCI_APPLICATION("Config List"), _config(*this) {}
- public:
- void show() override {
- while(true) {
- try {
- _config.enter();
- }
- catch(const HCI_ESCAPE& e) {
- break;
- }
- }
- }
- private:
- CONFIG_SHOWER _config;
- };
- ///////////////////////////////CONFIG CLASSES END///////////////////////////////
- /////////////////////////////////COMMIT CLASSES/////////////////////////////////
- class COMMIT_SHOWER : public HCI_MENU {
- public:
- explicit COMMIT_SHOWER(HCI_APPLICATION& ctx)
- : HCI_MENU(ctx),
- _ctx(ctx) {}
- ~COMMIT_SHOWER() override {
- clear();
- }
- void populate() {
- purge();
- int counter = 1;
- for(auto i : _repo.commits()){
- std::cout << counter << ": " << i << " " << i.signature().name() << " " << i.message() << "\n";
- ++counter;
- }
- add('q', &hci_quit);
- add(escape, &hci_quit); //Quits since there isn't a menu prior to menu. ////////////////////needs changing
- }
- public:
- void enter() {
- while(true) {
- try {
- HCI_MENU::enter();
- break;
- }
- catch(const HCI_LEAVE& e) {
- continue;
- }
- }
- }
- void show() {
- populate();
- std::cout << "Commit List " << "\n" << std::endl;
- HCI_MENU::show();
- std::cout << "\n";
- }
- private:
- HCI_APPLICATION& _ctx;
- GITPP::REPO _repo;
- };
- class LIST_COMMITS : public HCI_APPLICATION {
- public:
- LIST_COMMITS()
- : HCI_APPLICATION("Commit List"), _commit(*this) {}
- public:
- void show() override {
- while(true) {
- try {
- _commit.enter();
- }
- catch(const HCI_ESCAPE& e) {
- break;
- }
- }
- }
- private:
- COMMIT_SHOWER _commit;
- };
- class MAIN_MENU : public HCI_MENU {
- public:
- explicit MAIN_MENU(HCI_APPLICATION& ctx)
- : HCI_MENU(ctx),
- _ctx(ctx) {}
- ~MAIN_MENU() override {
- clear();
- }
- void populate() {
- purge();
- add('c', new LIST_CONFIG());
- add('e', new CONFIG()); //Creates new objects based on option.
- add('l', new LIST_COMMITS());
- add('q', &hci_quit);
- add(escape, &hci_quit); //Quits since there isn't a menu prior to menu.
- }
- public:
- void enter() {
- while(true) {
- try {
- HCI_MENU::enter();
- break;
- }
- catch(const HCI_LEAVE& e) {
- continue;
- }
- }
- }
- void show() {
- populate();
- std::cout << "Main menu" << "\n" << std::endl;
- HCI_MENU::show();
- std::cout << "\n";
- }
- private:
- HCI_APPLICATION& _ctx;
- };
- class MAIN : public HCI_APPLICATION {
- public:
- MAIN(int argc, char const *argv[])
- : HCI_APPLICATION("Main menu"), _main_menu(*this) {}
- public:
- void show() override {
- while(true) {
- try {
- _main_menu.enter();
- }
- catch(const HCI_ESCAPE& e) {
- break;
- }
- }
- }
- private:
- MAIN_MENU _main_menu;
- };
- ///////////////////////////////COMMIT CLASSES END///////////////////////////////
- /////////////////////////////////CREATE CLASSES/////////////////////////////////
- class CREATE_REPO : public HCI_APPLICATION {
- public:
- explicit CREATE_REPO() {}
- ~CREATE_REPO() override {
- clear();
- }
- public:
- void show() override {
- std::string base_path = ".";
- GITPP::REPO repo(GITPP::REPO::_create, base_path);
- }
- };
- ///////////////////////////////CREATE CLASSES END///////////////////////////////
- /////////////////////////////////SETUPS CLASSES/////////////////////////////////
- class SETUP_MENU : public HCI_MENU {
- public:
- explicit SETUP_MENU(HCI_APPLICATION& ctx)
- : HCI_MENU(ctx),
- _ctx(ctx) {}
- ~SETUP_MENU() override {
- clear();
- }
- void populate() {
- purge();
- add('y', new CREATE_REPO());
- add('n', &hci_quit);
- add(escape, &hci_quit); //Quits since there isn't a menu prior to menu. //////////////////needs changing
- }
- public:
- void enter() {
- while(true) {
- try {
- HCI_MENU::enter();
- break;
- }
- catch(const HCI_LEAVE& e) {
- continue;
- }
- }
- }
- void show() {
- populate();
- std::cout << "Setup Menu" << "\n" << std::endl;
- HCI_MENU::show();
- std::cout << "\n";
- }
- private:
- HCI_APPLICATION& _ctx;
- };
- class SETUP : public HCI_APPLICATION {
- public:
- SETUP()
- : HCI_APPLICATION("Commit List"), _setup(*this) {}
- public:
- void show() override {
- while(true) {
- try {
- _setup.enter();
- }
- catch(const HCI_ESCAPE& e) {
- break;
- }
- }
- }
- private:
- SETUP_MENU _setup;
- };
- ///////////////////////////////SETUPS CLASSES END///////////////////////////////
- // the program starts here.
- int main(int argc, char const *argv[]) {
- std::string base_path = ".";
- try {
- GITPP::REPO repo(base_path); //Check for existing repo and store in repo object
- std::cout << ".git folder found" << std::endl; // let user know repo found
- MAIN caller(argc, argv); //Enters main menu.
- caller.exec();
- }
- catch(const GITPP::EXCEPTION_CANT_FIND& e){
- SETUP setup_caller;
- setup_caller.exec();
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement