From 638c3ac10003f66ef4af43f50ee365c9036da0fe Mon Sep 17 00:00:00 2001 From: BossCode45 Date: Sat, 24 Jun 2023 20:26:29 +1200 Subject: feat: Added ; as a command separator --- commands.cpp | 65 ++++++++++++++++++++++++++++++++++++++++++++--- commands.h | 5 +++- keybinds.cpp | 11 +++++--- readme.html | 82 ++++++++++++++++++++++++++++++------------------------------ 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& split, const CommandA void CommandsModule::runCommand(string command) { vector split = splitCommand(command); + vector::const_iterator start = split.begin(); + int count = 0; + for(string s : split) + { + if(s == ";") + { + vector::const_iterator end = start + count; + vector partialCmd(start, end); + runCommand(partialCmd); + count = 0; + start = end + 1; + } + else + { + count++; + } + } + if(start != split.end()) + { + vector partialCmd(start, (vector::const_iterator)split.end()); + runCommand(partialCmd); + } +} +void CommandsModule::runCommand(vector 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 CommandsModule::checkCommand(string command) { + vector errs; vector split = splitCommand(command); + vector::const_iterator start = split.begin(); + int count = 0; + for(string s : split) + { + if(s == ";") + { + vector::const_iterator end = start + count; + vector partialCmd(start, end); + errs.push_back(checkCommand(partialCmd)); + count = 0; + start = end + 1; + } + else + { + count++; + } + } + if(start != split.end()) + { + vector partialCmd(start, (vector::const_iterator)split.end()); + errs.push_back(checkCommand(partialCmd)); + } + return errs; +} + +Err CommandsModule::checkCommand(vector 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 { diff --git a/commands.h b/commands.h index d7f2351..af4a4a0 100644 --- a/commands.h +++ b/commands.h @@ -51,6 +51,7 @@ 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(); @@ -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 split); + std::vector checkCommand(std::string command); + Err checkCommand(std::vector 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 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 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"> - + YATwm @@ -200,36 +200,36 @@

Table of Contents

-
-

1. This config is best read in Emacs!

+
+

1. This config is best read in Emacs!

-
-

2. Disclaimer: This is still very much in beta

+
+

2. Disclaimer: This is still very much in beta

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).
@@ -237,16 +237,16 @@ This only just works, multiple monitors aren't supported and floating windows ca

-
-

3. Usage instructions

+
+

3. Usage instructions

-
-

3.1. Installation

+
+

3.1. Installation

-
-

3.1.1. Pre reqs

+
+

3.1.1. Pre reqs

  • Xlib and g++ and libnotify to build the program
  • @@ -258,8 +258,8 @@ This only just works, multiple monitors aren't supported and floating windows ca
-
-

3.1.2. Installing and removing

+
+

3.1.2. Installing and removing

  • make i or make install to install
  • @@ -269,23 +269,23 @@ This only just works, multiple monitors aren't supported and floating windows ca
-
-

3.2. Config

+
+

3.2. Config

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.

-
-

3.2.1. Syntax

+
+

3.2.1. 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").

    -
  1. Command arg types
    +
  2. Command arg types
    • String: this is just some text, this can be wrapped in quotes if you want a space in it.
    • @@ -302,7 +302,7 @@ The config file is a list of commands. Each command should be on a new line. For
  3. -
  4. List of commands
    +
  5. List of commands
    • exit: shuts down YATwm
    • @@ -368,8 +368,8 @@ The config file is a list of commands. Each command should be on a new line. For
-
-

3.2.2. General

+
+

3.2.2. General

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).
@@ -379,8 +379,8 @@ YATwm also keeps a log file, the location of this file can be changed with the c

-
-

3.2.3. Workspaces

+
+

3.2.3. Workspaces

You can add workspace with the command addworkspace in the config file.
@@ -406,8 +406,8 @@ Defaults workspace are listed below (these are the args for the addworkspace com

-
-

3.2.4. Keybinds

+
+

3.2.4. Keybinds

Current keybinds (these can all be edited):
@@ -451,8 +451,8 @@ Commands are executed going down the list and multiple commands with the same ke

-
-

4. Credits

+
+

4. Credits

Catwm (https://github.com/pyknite/catwm)
@@ -465,7 +465,7 @@ basicwm (https://github

diff --git a/readme.org b/readme.org index 9a41662..82863b9 100644 --- a/readme.org +++ b/readme.org @@ -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. -- cgit v1.2.3