From aa1500fea32db04c9e4fe72786ebd7e3479b6a8a Mon Sep 17 00:00:00 2001 From: BossCode45 Date: Sat, 4 Jan 2025 15:14:05 +1300 Subject: feat: Commands restructure + home manager module now makes config Commands module is now a separate libraray that the flake includes. The home manager module will now auto generate the config and has options for different things such as keybinds, gaps, workspaces, etc. --- src/commands.h | 89 ---------------------------------------------------------- 1 file changed, 89 deletions(-) delete mode 100644 src/commands.h (limited to 'src/commands.h') diff --git a/src/commands.h b/src/commands.h deleted file mode 100644 index af4a4a0..0000000 --- a/src/commands.h +++ /dev/null @@ -1,89 +0,0 @@ -#pragma once - -#include "error.h" - -#include -#include -#include -#include - -enum MoveDir - { - UP, - RIGHT, - DOWN, - LEFT - }; -enum CommandArgType - { - STR, - NUM, - MOVDIR, - STR_REST, - NUM_ARR_REST - }; - -struct NumArr -{ - int* arr; - int size; -}; -typedef union -{ - char* str; - int num; - NumArr numArr; - MoveDir dir; -} CommandArg; - -struct Command -{ - const std::string name; - const std::function func; - const std::function staticFunc; - const int argc; - CommandArgType* argTypes; - std::any* module; -}; -class CommandsModule -{ -private: - std::vector commandList; - std::vector splitCommand(std::string command); - CommandArg* getCommandArgs(std::vector& args, const CommandArgType* argTypes, const int argc); - const void echo(const CommandArg* argv); -public: - CommandsModule(); - ~CommandsModule(); - template - void addCommand(std::string name, const void(T::*func)(const CommandArg*), const int argc, CommandArgType* argTypes, T* module); - void addCommand(std::string name, const void(*func)(const CommandArg*), const int argc, CommandArgType* argTypes); - template - void addCommand(std::string name, const void(T::*func)(const CommandArg*), const int argc, std::vector argTypes, T* module); - void addCommand(std::string name, const void(*func)(const CommandArg*), const int argc, std::vector argTypes); - void addCommand(Command c); - Command* lookupCommand(std::string name); - void runCommand(std::string command); - void runCommand(std::vector split); - std::vector checkCommand(std::string command); - Err checkCommand(std::vector split); -}; - -// YES I KNOW THIS IS BAD -// but it needs to be done this way -template -void CommandsModule::addCommand(std::string name, const void(T::*func)(const CommandArg*), const int argc, CommandArgType* argTypes, T* module) -{ - Command c = {name, (const void*(std::any::*)(const CommandArg* argv)) func, nullptr, argc, argTypes, (std::any*)module}; - addCommand(c); -} -template -void CommandsModule::addCommand(std::string name, const void(T::*func)(const CommandArg*), const int argc, std::vector argTypes, T* module) -{ - CommandArgType* argTypesArr = new CommandArgType[argc]; - for(int i = 0; i < argc; i++) - { - argTypesArr[i] = argTypes[i]; - } - addCommand(name, func, argc, argTypesArr, module); -} -- cgit v1.2.3 From e9c351d109439ca27c472f0d8d5f8a530ce24033 Mon Sep 17 00:00:00 2001 From: BossCode45 Date: Sat, 4 Jan 2025 20:28:39 +1300 Subject: revert: Added the commands library back to the source --- src/commands.h | 91 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 91 insertions(+) create mode 100644 src/commands.h (limited to 'src/commands.h') diff --git a/src/commands.h b/src/commands.h new file mode 100644 index 0000000..4825f1c --- /dev/null +++ b/src/commands.h @@ -0,0 +1,91 @@ +#pragma once + +#include "error.h" + +#include +#include +#include +#include + +enum MoveDir + { + UP, + RIGHT, + DOWN, + LEFT + }; +enum CommandArgType + { + STR, + NUM, + MOVDIR, + STR_REST, + NUM_ARR_REST + }; + +struct NumArr +{ + int* arr; + int size; +}; +typedef union +{ + char* str; + int num; + NumArr numArr; + MoveDir dir; +} CommandArg; + +struct Command +{ + const std::string name; + const std::function func; + const std::function staticFunc; + const int argc; + CommandArgType* argTypes; + std::any* module; +}; +class CommandsModule +{ +private: + std::vector commandList; + std::vector splitCommand(std::string command); + CommandArg* getCommandArgs(std::vector& args, const CommandArgType* argTypes, const int argc); + const void echo(const CommandArg* argv); + const void loadFile(const CommandArg* argv); + std::string cwd; +public: + CommandsModule(); + ~CommandsModule(); + template + void addCommand(std::string name, const void(T::*func)(const CommandArg*), const int argc, CommandArgType* argTypes, T* module); + void addCommand(std::string name, const void(*func)(const CommandArg*), const int argc, CommandArgType* argTypes); + template + void addCommand(std::string name, const void(T::*func)(const CommandArg*), const int argc, std::vector argTypes, T* module); + void addCommand(std::string name, const void(*func)(const CommandArg*), const int argc, std::vector argTypes); + void addCommand(Command c); + Command* lookupCommand(std::string name); + void runCommand(std::string command); + void runCommand(std::vector split); + std::vector checkCommand(std::string command); + Err checkCommand(std::vector split); +}; + +// YES I KNOW THIS IS BAD +// but it needs to be done this way +template +void CommandsModule::addCommand(std::string name, const void(T::*func)(const CommandArg*), const int argc, CommandArgType* argTypes, T* module) +{ + Command c = {name, (const void*(std::any::*)(const CommandArg* argv)) func, nullptr, argc, argTypes, (std::any*)module}; + addCommand(c); +} +template +void CommandsModule::addCommand(std::string name, const void(T::*func)(const CommandArg*), const int argc, std::vector argTypes, T* module) +{ + CommandArgType* argTypesArr = new CommandArgType[argc]; + for(int i = 0; i < argc; i++) + { + argTypesArr[i] = argTypes[i]; + } + addCommand(name, func, argc, argTypesArr, module); +} -- cgit v1.2.3