diff options
| author | BossCode45 <human.cyborg42@gmail.com> | 2023-06-24 20:26:29 +1200 |
|---|---|---|
| committer | BossCode45 <human.cyborg42@gmail.com> | 2023-06-24 20:26:29 +1200 |
| commit | 638c3ac10003f66ef4af43f50ee365c9036da0fe (patch) | |
| tree | a2e17e4693761e92a6be2d84b12d763e48bb48eb | |
| parent | 87b7f6c47d8eab8bfe7f126652a88939aac58a6a (diff) | |
| download | YATwm-638c3ac10003f66ef4af43f50ee365c9036da0fe.tar.gz YATwm-638c3ac10003f66ef4af43f50ee365c9036da0fe.zip | |
feat: Added ; as a command separator
| -rw-r--r-- | commands.cpp | 65 | ||||
| -rw-r--r-- | commands.h | 5 | ||||
| -rw-r--r-- | keybinds.cpp | 11 | ||||
| -rw-r--r-- | readme.html | 82 | ||||
| -rw-r--r-- | readme.org | 2 |
5 files changed, 115 insertions, 50 deletions
diff --git a/commands.cpp b/commands.cpp index de7d81e..af523ad 100644 --- a/commands.cpp +++ b/commands.cpp @@ -13,8 +13,14 @@ using std::cout, std::endl, std::string, std::vector, std::tolower; +const void CommandsModule::echo(const CommandArg* argv) +{ + cout << argv[0].str << endl; +} + CommandsModule::CommandsModule() { + addCommand("echo", &CommandsModule::echo, 1, {STR_REST}, this); } CommandsModule::~CommandsModule() { @@ -215,11 +221,36 @@ CommandArg* CommandsModule::getCommandArgs(vector<string>& split, const CommandA void CommandsModule::runCommand(string command) { vector<string> split = splitCommand(command); + vector<string>::const_iterator start = split.begin(); + int count = 0; + for(string s : split) + { + if(s == ";") + { + vector<string>::const_iterator end = start + count; + vector<string> partialCmd(start, end); + runCommand(partialCmd); + count = 0; + start = end + 1; + } + else + { + count++; + } + } + if(start != split.end()) + { + vector<string> partialCmd(start, (vector<string>::const_iterator)split.end()); + runCommand(partialCmd); + } +} +void CommandsModule::runCommand(vector<string> split) +{ Command* cmd = lookupCommand(split[0]); if(cmd == nullptr) throw Err(CMD_ERR_NOT_FOUND, split[0] + " is not a valid command name"); if(cmd->argc > split.size() - 1) - throw Err(CMD_ERR_WRONG_ARGS, command + " is the wrong args"); + throw Err(CMD_ERR_WRONG_ARGS, "wrong number of arguments"); CommandArg* args; try { @@ -254,14 +285,42 @@ void CommandsModule::runCommand(string command) delete[] args; } -Err CommandsModule::checkCommand(string command) +vector<Err> CommandsModule::checkCommand(string command) { + vector<Err> errs; vector<string> split = splitCommand(command); + vector<string>::const_iterator start = split.begin(); + int count = 0; + for(string s : split) + { + if(s == ";") + { + vector<string>::const_iterator end = start + count; + vector<string> partialCmd(start, end); + errs.push_back(checkCommand(partialCmd)); + count = 0; + start = end + 1; + } + else + { + count++; + } + } + if(start != split.end()) + { + vector<string> partialCmd(start, (vector<string>::const_iterator)split.end()); + errs.push_back(checkCommand(partialCmd)); + } + return errs; +} + +Err CommandsModule::checkCommand(vector<string> split) +{ Command* cmd = lookupCommand(split[0]); if(cmd == nullptr) return Err(CMD_ERR_NOT_FOUND, split[0] + " is not a valid command name"); if(cmd->argc > split.size()) - return Err(CMD_ERR_WRONG_ARGS, command + " is the wrong args"); + return Err(CMD_ERR_WRONG_ARGS, "wrong number of arguments"); CommandArg* args; try { @@ -51,6 +51,7 @@ private: std::vector<Command> commandList; std::vector<std::string> splitCommand(std::string command); CommandArg* getCommandArgs(std::vector<std::string>& args, const CommandArgType* argTypes, const int argc); + const void echo(const CommandArg* argv); public: CommandsModule(); ~CommandsModule(); @@ -63,7 +64,9 @@ public: void addCommand(Command c); Command* lookupCommand(std::string name); void runCommand(std::string command); - Err checkCommand(std::string command); + void runCommand(std::vector<std::string> split); + std::vector<Err> checkCommand(std::string command); + Err checkCommand(std::vector<std::string> split); }; // YES I KNOW THIS IS BAD diff --git a/keybinds.cpp b/keybinds.cpp index 64d3fc8..8448eed 100644 --- a/keybinds.cpp +++ b/keybinds.cpp @@ -39,11 +39,14 @@ const void KeybindsModule::handleKeypress(XKeyEvent e) const void KeybindsModule::bind(const CommandArg* argv) { - Err e = commandsModule.checkCommand(argv[1].str); - if(e.code != NOERR) + std::vector<Err> errs = commandsModule.checkCommand(argv[1].str); + for(Err e : errs) { - e.message = "Binding fail - " + e.message; - throw e; + if(e.code != NOERR) + { + e.message = "Binding fail - " + e.message; + throw e; + } } std::vector<string> keys = split(argv[0].str, '+'); Keybind bind; diff --git a/readme.html b/readme.html index 1040470..1914ed8 100644 --- a/readme.html +++ b/readme.html @@ -3,7 +3,7 @@ "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> <html xmlns="http://www.w3.org/1999/xhtml" lang="en" xml:lang="en"> <head> -<!-- 2023-06-21 Wed 20:26 --> +<!-- 2023-06-24 Sat 20:26 --> <meta http-equiv="Content-Type" content="text/html;charset=utf-8" /> <meta name="viewport" content="width=device-width, initial-scale=1" /> <title>YATwm</title> @@ -200,36 +200,36 @@ <h2>Table of Contents</h2> <div id="text-table-of-contents" role="doc-toc"> <ul> -<li><a href="#orge9be048">1. This config is best read in Emacs!</a></li> -<li><a href="#org90a4bc0">2. Disclaimer: This is still very much in beta</a></li> -<li><a href="#org5eaba64">3. Usage instructions</a> +<li><a href="#org22f6a6a">1. This config is best read in Emacs!</a></li> +<li><a href="#orgb99665d">2. Disclaimer: This is still very much in beta</a></li> +<li><a href="#org765f587">3. Usage instructions</a> <ul> -<li><a href="#org41321d1">3.1. Installation</a> +<li><a href="#org828f089">3.1. Installation</a> <ul> -<li><a href="#org318ad8e">3.1.1. Pre reqs</a></li> -<li><a href="#orgf06bf1e">3.1.2. Installing and removing</a></li> +<li><a href="#org40fd04a">3.1.1. Pre reqs</a></li> +<li><a href="#orgd4b9c62">3.1.2. Installing and removing</a></li> </ul> </li> -<li><a href="#org3c09ef5">3.2. Config</a> +<li><a href="#org13802bc">3.2. Config</a> <ul> -<li><a href="#org43f17c0">3.2.1. Syntax</a></li> -<li><a href="#org384a204">3.2.2. General</a></li> -<li><a href="#orga3a5f0e">3.2.3. Workspaces</a></li> -<li><a href="#orgee481dd">3.2.4. Keybinds</a></li> +<li><a href="#org2559804">3.2.1. Syntax</a></li> +<li><a href="#org0576586">3.2.2. General</a></li> +<li><a href="#orgea29f86">3.2.3. Workspaces</a></li> +<li><a href="#orgc571a3e">3.2.4. Keybinds</a></li> </ul> </li> </ul> </li> -<li><a href="#orgd9a91f5">4. Credits</a></li> +<li><a href="#orgc1db949">4. Credits</a></li> </ul> </div> </div> -<div id="outline-container-orge9be048" class="outline-2"> -<h2 id="orge9be048"><span class="section-number-2">1.</span> This config is best read in Emacs!</h2> +<div id="outline-container-org22f6a6a" class="outline-2"> +<h2 id="org22f6a6a"><span class="section-number-2">1.</span> This config is best read in Emacs!</h2> </div> -<div id="outline-container-org90a4bc0" class="outline-2"> -<h2 id="org90a4bc0"><span class="section-number-2">2.</span> Disclaimer: This is still very much in beta</h2> +<div id="outline-container-orgb99665d" class="outline-2"> +<h2 id="orgb99665d"><span class="section-number-2">2.</span> Disclaimer: This is still very much in beta</h2> <div class="outline-text-2" id="text-2"> <p> This only just works, multiple monitors aren't supported and floating windows cannot move and there is no resizing. Many features are just hacked together and are likely to break. However, it is just about usable so if you really want to try then go for it! (feel free to make an issue if you have any questions).<br /> @@ -237,16 +237,16 @@ This only just works, multiple monitors aren't supported and floating windows ca </div> </div> -<div id="outline-container-org5eaba64" class="outline-2"> -<h2 id="org5eaba64"><span class="section-number-2">3.</span> Usage instructions</h2> +<div id="outline-container-org765f587" class="outline-2"> +<h2 id="org765f587"><span class="section-number-2">3.</span> Usage instructions</h2> <div class="outline-text-2" id="text-3"> </div> -<div id="outline-container-org41321d1" class="outline-3"> -<h3 id="org41321d1"><span class="section-number-3">3.1.</span> Installation</h3> +<div id="outline-container-org828f089" class="outline-3"> +<h3 id="org828f089"><span class="section-number-3">3.1.</span> Installation</h3> <div class="outline-text-3" id="text-3-1"> </div> -<div id="outline-container-org318ad8e" class="outline-4"> -<h4 id="org318ad8e"><span class="section-number-4">3.1.1.</span> Pre reqs</h4> +<div id="outline-container-org40fd04a" class="outline-4"> +<h4 id="org40fd04a"><span class="section-number-4">3.1.1.</span> Pre reqs</h4> <div class="outline-text-4" id="text-3-1-1"> <ul class="org-ul"> <li><code>Xlib</code> and <code>g++</code> and <code>libnotify</code> to build the program<br /></li> @@ -258,8 +258,8 @@ This only just works, multiple monitors aren't supported and floating windows ca </ul> </div> </div> -<div id="outline-container-orgf06bf1e" class="outline-4"> -<h4 id="orgf06bf1e"><span class="section-number-4">3.1.2.</span> Installing and removing</h4> +<div id="outline-container-orgd4b9c62" class="outline-4"> +<h4 id="orgd4b9c62"><span class="section-number-4">3.1.2.</span> Installing and removing</h4> <div class="outline-text-4" id="text-3-1-2"> <ul class="org-ul"> <li><code>make i</code> or <code>make install</code> to install<br /></li> @@ -269,23 +269,23 @@ This only just works, multiple monitors aren't supported and floating windows ca </div> </div> </div> -<div id="outline-container-org3c09ef5" class="outline-3"> -<h3 id="org3c09ef5"><span class="section-number-3">3.2.</span> Config</h3> +<div id="outline-container-org13802bc" class="outline-3"> +<h3 id="org13802bc"><span class="section-number-3">3.2.</span> Config</h3> <div class="outline-text-3" id="text-3-2"> <p> You can configure YATwm with the config file in <code>$HOME/.config/YATwm/config</code> or <code>$XDG_CONFIG_HOME/YATwm/config</code> if you have that set. I have provided an example config file in the project dir that has all the variables set to their defaults (this will also be installed to <code>/etc/YATwm/config</code>.<br /> It should alert you with a notification if you have an error, and put the error your log file. If the whole file is missing then it will use the default in <code>/etc/YATwm/config</code>.<br /> </p> </div> -<div id="outline-container-org43f17c0" class="outline-4"> -<h4 id="org43f17c0"><span class="section-number-4">3.2.1.</span> Syntax</h4> +<div id="outline-container-org2559804" class="outline-4"> +<h4 id="org2559804"><span class="section-number-4">3.2.1.</span> Syntax</h4> <div class="outline-text-4" id="text-3-2-1"> <p> -The config file is a list of commands. Each command should be on a new line. For example, to set the gaps you would use the <code>gaps</code> command like this <code>gaps 10</code> (make sure this is all there is on that line). This says to call the command <code>gaps</code> with the arguments of <code>10</code>. Commands can have multiple arguments and these should be separated with a space, if you want a space in one of the arguments then wrap the arg in quotes, e.g. <code>addWorkspace "1: A" 1</code>, here the arguments are <code>1: A</code> and <code>1</code>. If you want to have a quote in your argument then make sure that arg is wrapped in quotes or escape it with <code>\</code> (e.g. <code>\'</code>), to insert <code>\</code> then use <code>\\</code>.<br /> +The config file is a list of commands. Each command should be on a new line. For example, to set the gaps you would use the <code>gaps</code> command like this <code>gaps 10</code> (make sure this is all there is on that line). This says to call the command <code>gaps</code> with the arguments of <code>10</code>. Commands can have multiple arguments and these should be separated with a space, if you want a space in one of the arguments then wrap the arg in quotes, e.g. <code>addWorkspace "1: A" 1</code>, here the arguments are <code>1: A</code> and <code>1</code>. If you want to have a quote in your argument then make sure that arg is wrapped in quotes or escape it with <code>\</code> (e.g. <code>\'</code>), to insert <code>\</code> then use <code>\\</code>. If you want to have multiple commands on the same line, e.g. binding a key to multiple commands, then use <code>;</code> as an argument on its own to separate them (tip: if you are using this for keybinds then enclose <b>all</b> the keybind commands in quotes, e.g. <code>bind mod+l "spawn i3lock ; spawn systemctl suspend"</code>).<br /> </p> </div> <ol class="org-ol"> -<li><a id="orgd79f7a9"></a>Command arg types<br /> +<li><a id="org2387d9b"></a>Command arg types<br /> <div class="outline-text-5" id="text-3-2-1-1"> <ul class="org-ul"> <li>String: this is just some text, this can be wrapped in quotes if you want a space in it.<br /></li> @@ -302,7 +302,7 @@ The config file is a list of commands. Each command should be on a new line. For </ul> </div> </li> -<li><a id="org948d88f"></a>List of commands<br /> +<li><a id="org64c9926"></a>List of commands<br /> <div class="outline-text-5" id="text-3-2-1-2"> <ul class="org-ul"> <li>exit: shuts down YATwm<br /></li> @@ -368,8 +368,8 @@ The config file is a list of commands. Each command should be on a new line. For </li> </ol> </div> -<div id="outline-container-org384a204" class="outline-4"> -<h4 id="org384a204"><span class="section-number-4">3.2.2.</span> General</h4> +<div id="outline-container-org0576586" class="outline-4"> +<h4 id="org0576586"><span class="section-number-4">3.2.2.</span> General</h4> <div class="outline-text-4" id="text-3-2-2"> <p> You can change either the inner gaps (padding around each window - so double it for space between windows), or the outer gaps (padding around the display - add to inner gaps to get space between window and screen edges).<br /> @@ -379,8 +379,8 @@ YATwm also keeps a log file, the location of this file can be changed with the c </div> </div> -<div id="outline-container-orga3a5f0e" class="outline-4"> -<h4 id="orga3a5f0e"><span class="section-number-4">3.2.3.</span> Workspaces</h4> +<div id="outline-container-orgea29f86" class="outline-4"> +<h4 id="orgea29f86"><span class="section-number-4">3.2.3.</span> Workspaces</h4> <div class="outline-text-4" id="text-3-2-3"> <p> You can add workspace with the command <code>addworkspace</code> in the config file.<br /> @@ -406,8 +406,8 @@ Defaults workspace are listed below (these are the args for the addworkspace com </ol> </div> </div> -<div id="outline-container-orgee481dd" class="outline-4"> -<h4 id="orgee481dd"><span class="section-number-4">3.2.4.</span> Keybinds</h4> +<div id="outline-container-orgc571a3e" class="outline-4"> +<h4 id="orgc571a3e"><span class="section-number-4">3.2.4.</span> Keybinds</h4> <div class="outline-text-4" id="text-3-2-4"> <p> Current keybinds (these can all be edited):<br /> @@ -451,8 +451,8 @@ Commands are executed going down the list and multiple commands with the same ke </div> </div> -<div id="outline-container-orgd9a91f5" class="outline-2"> -<h2 id="orgd9a91f5"><span class="section-number-2">4.</span> Credits</h2> +<div id="outline-container-orgc1db949" class="outline-2"> +<h2 id="orgc1db949"><span class="section-number-2">4.</span> Credits</h2> <div class="outline-text-2" id="text-4"> <p> Catwm (<a href="https://github.com/pyknite/catwm">https://github.com/pyknite/catwm</a>)<br /> @@ -465,7 +465,7 @@ basic<sub>wm</sub> (<a href="https://github.com/jichu4n/basic_wm">https://github </div> </div> <div id="postamble" class="status"> -<p class="date">Created: 2023-06-21 Wed 20:26</p> +<p class="date">Created: 2023-06-24 Sat 20:26</p> <p class="validation"><a href="https://validator.w3.org/check?uri=referer">Validate</a></p> </div> </body> @@ -20,7 +20,7 @@ This only just works, multiple monitors aren't supported and floating windows ca You can configure YATwm with the config file in ~$HOME/.config/YATwm/config~ or ~$XDG_CONFIG_HOME/YATwm/config~ if you have that set. I have provided an example config file in the project dir that has all the variables set to their defaults (this will also be installed to ~/etc/YATwm/config~. It should alert you with a notification if you have an error, and put the error your log file. If the whole file is missing then it will use the default in ~/etc/YATwm/config~. *** Syntax -The config file is a list of commands. Each command should be on a new line. For example, to set the gaps you would use the ~gaps~ command like this ~gaps 10~ (make sure this is all there is on that line). This says to call the command ~gaps~ with the arguments of ~10~. Commands can have multiple arguments and these should be separated with a space, if you want a space in one of the arguments then wrap the arg in quotes, e.g. ~addWorkspace "1: A" 1~, here the arguments are ~1: A~ and ~1~. If you want to have a quote in your argument then make sure that arg is wrapped in quotes or escape it with ~\~ (e.g. ~\'~), to insert ~\~ then use ~\\~. +The config file is a list of commands. Each command should be on a new line. For example, to set the gaps you would use the ~gaps~ command like this ~gaps 10~ (make sure this is all there is on that line). This says to call the command ~gaps~ with the arguments of ~10~. Commands can have multiple arguments and these should be separated with a space, if you want a space in one of the arguments then wrap the arg in quotes, e.g. ~addWorkspace "1: A" 1~, here the arguments are ~1: A~ and ~1~. If you want to have a quote in your argument then make sure that arg is wrapped in quotes or escape it with ~\~ (e.g. ~\'~), to insert ~\~ then use ~\\~. If you want to have multiple commands on the same line, e.g. binding a key to multiple commands, then use ~;~ as an argument on its own to separate them (tip: if you are using this for keybinds then enclose *all* the keybind commands in quotes, e.g. ~bind mod+l "spawn i3lock ; spawn systemctl suspend"~). **** Command arg types - String: this is just some text, this can be wrapped in quotes if you want a space in it. - String rest: This will only ever be the final argument. This just takes the rest of the line as a string, so you can use spaces without needing quotes. |
