From c9f806d7dbb4a225a4570a45ffd09c302608da1f Mon Sep 17 00:00:00 2001 From: Brando Date: Tue, 7 Jan 2025 18:04:35 -0800 Subject: [PATCH 01/29] Can use ":" but chat isn't good --- external/libs | 2 +- src/command.cpp | 4 +++- src/inputbuffer.cpp | 6 ++---- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/external/libs b/external/libs index 6c2febd..7aea9e8 160000 --- a/external/libs +++ b/external/libs @@ -1 +1 @@ -Subproject commit 6c2febd1758e81cb7600b19c9ba4e7d3300b2e10 +Subproject commit 7aea9e87607418ff993fe62722a99bc2fcab6ea8 diff --git a/src/command.cpp b/src/command.cpp index 14fe4dc..275bc94 100644 --- a/src/command.cpp +++ b/src/command.cpp @@ -33,7 +33,9 @@ Command::~Command() { } String Command::op() const { - return this->argumentAtIndex(0); + String res = this->argumentAtIndex(0); + res.remCharAtIndex(0); + return res; } String Command::operator[](int i) const { diff --git a/src/inputbuffer.cpp b/src/inputbuffer.cpp index 3858e17..d82c20b 100644 --- a/src/inputbuffer.cpp +++ b/src/inputbuffer.cpp @@ -18,14 +18,12 @@ InputBuffer::InputBuffer(const char * str) : String(str) { this->_cursorpos = 0; } -InputBuffer::~InputBuffer() { - -} +InputBuffer::~InputBuffer() { } int InputBuffer::addChar(int ch) { switch (ch) { case '\n': - this->_isready = true; + this->_isready = this->starts_with(":"); break; case KEY_BACKSPACE: case 127: From d2667a43e92d61f6622757ff8cd19a1cd88ca0a4 Mon Sep 17 00:00:00 2001 From: Brando Date: Tue, 7 Jan 2025 23:33:58 -0800 Subject: [PATCH 02/29] making a utils function that determines if the input is ready --- external/libs | 2 +- makefile | 3 ++- src/inputbuffer.cpp | 10 +++++----- src/inputbuffer.hpp | 4 ++-- src/interface.cpp | 11 +++++++---- src/utils.cpp | 13 +++++++++++++ src/utils.hpp | 16 ++++++++++++++++ 7 files changed, 46 insertions(+), 13 deletions(-) create mode 100644 src/utils.cpp create mode 100644 src/utils.hpp diff --git a/external/libs b/external/libs index 7aea9e8..cc6dea4 160000 --- a/external/libs +++ b/external/libs @@ -1 +1 @@ -Subproject commit 7aea9e87607418ff993fe62722a99bc2fcab6ea8 +Subproject commit cc6dea40b5632d6616139180f13b184607baa03a diff --git a/makefile b/makefile index 55003fc..d526e77 100644 --- a/makefile +++ b/makefile @@ -43,7 +43,8 @@ log user inputbuffer office \ chatroom message chatroomserver packet \ agent agentclient agentserver sealedpacket \ chatroomclient interfaceserver interfaceclient command \ -permissions chat +permissions utils\ +chat UNAME_S := $(shell uname -s) ifeq ($(UNAME_S),Darwin) diff --git a/src/inputbuffer.cpp b/src/inputbuffer.cpp index d82c20b..e6ee818 100644 --- a/src/inputbuffer.cpp +++ b/src/inputbuffer.cpp @@ -14,7 +14,7 @@ using namespace BF; InputBuffer::InputBuffer() : InputBuffer("") {} InputBuffer::InputBuffer(const char * str) : String(str) { - this->_isready = false; + this->_enterPressed = false; this->_cursorpos = 0; } @@ -23,7 +23,7 @@ InputBuffer::~InputBuffer() { } int InputBuffer::addChar(int ch) { switch (ch) { case '\n': - this->_isready = this->starts_with(":"); + this->_enterPressed = true; break; case KEY_BACKSPACE: case 127: @@ -53,7 +53,7 @@ int InputBuffer::addChar(int ch) { int InputBuffer::reset() { this->_cursorpos = 0; - this->_isready = false; + this->_enterPressed = false; return this->String::clear(); } @@ -61,7 +61,7 @@ size_t InputBuffer::cursorPosition() { return this->_cursorpos; } -bool InputBuffer::isready() { - return this->_isready; +bool InputBuffer::enterPressed() { + return this->_enterPressed; } diff --git a/src/inputbuffer.hpp b/src/inputbuffer.hpp index 3d214a5..a51bdf0 100644 --- a/src/inputbuffer.hpp +++ b/src/inputbuffer.hpp @@ -23,7 +23,7 @@ class InputBuffer : public BF::String { /** * when the buffer is ready to be sent */ - bool isready(); + bool enterPressed(); /** * clears buffer and resets the cursor position @@ -37,7 +37,7 @@ class InputBuffer : public BF::String { private: - bool _isready; + bool _enterPressed; /** * current cursor position diff --git a/src/interface.cpp b/src/interface.cpp index edb1c00..47e095b 100644 --- a/src/interface.cpp +++ b/src/interface.cpp @@ -20,6 +20,7 @@ #include "agentclient.hpp" #include "command.hpp" #include "permissions.hpp" +#include "utils.hpp" extern "C" { #include @@ -604,7 +605,8 @@ Chatroom * _InterfaceGetChatroomAtIndex(int i) { } int Interface::processinputStateLobby(InputBuffer & userInput) { - if (userInput.isready()) { + //if (userInput.isready()) { + if (Utils::inputReady(userInput)) { Command cmd(userInput); if (!cmd.op().compareString(INTERFACE_COMMAND_QUIT)) { // quit Office::quitApplication(this->_user.get()); @@ -656,7 +658,8 @@ int Interface::processinputStateLobby(InputBuffer & userInput) { } int Interface::processinputStateChatroom(InputBuffer & userInput) { - if (userInput.isready()) { + //if (userInput.isready()) { + if (Utils::inputReady(userInput)) { Command cmd(userInput); if (!cmd.op().compareString(INTERFACE_COMMAND_LEAVE)) { // leave // tell chat room we are leaving @@ -683,8 +686,8 @@ int Interface::processinputStateChatroom(InputBuffer & userInput) { } int Interface::processinputStateDraft(InputBuffer & userInput) { - if (userInput.isready()) { - // send buf + //if (userInput.isready()) { // send buf + if (Utils::inputReady(userInput)) { // send buf this->_chatroom.get()->sendBuffer(userInput); this->_state = kInterfaceStateChatroom; diff --git a/src/utils.cpp b/src/utils.cpp new file mode 100644 index 0000000..21b4dcc --- /dev/null +++ b/src/utils.cpp @@ -0,0 +1,13 @@ +/** + * author: brando + * date: 1/7/24 + */ + +#include "utils.hpp" +#include "inputbuffer.hpp" +#include "interface.hpp" + +bool Utils::inputReady(InputBuffer & buf) { + return buf.enterPressed() && (Interface::current()->currstate() == kInterfaceStateDraft || buf.starts_with(":")); +} + diff --git a/src/utils.hpp b/src/utils.hpp new file mode 100644 index 0000000..d2556cb --- /dev/null +++ b/src/utils.hpp @@ -0,0 +1,16 @@ +/** + * author: brando + * date: 1/7/24 + */ + +#ifndef UTILS_HPP +#define UTILS_HPP + +class InputBuffer; + +namespace Utils { +bool inputReady(InputBuffer & buf); +} + +#endif // UTILS_HPP + From 4b811e8fcea07352f47e5f524551825a7f6d0bda Mon Sep 17 00:00:00 2001 From: Brando Date: Tue, 7 Jan 2025 23:35:06 -0800 Subject: [PATCH 03/29] update todo --- todo.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/todo.md b/todo.md index 20972e7..29ff1a2 100644 --- a/todo.md +++ b/todo.md @@ -9,6 +9,8 @@ x.x 0.3 - [ ] improved controls (easier commands or guidance) + - [x] use of ":" for long commands + - [ ] single key commands - [ ] chat configuration implemented in ncurses - [ ] user typing - [x] update build and test process From 8ba976d7c619c175dd14581ad8b9a11075733f78 Mon Sep 17 00:00:00 2001 From: Brando Date: Tue, 7 Jan 2025 23:35:45 -0800 Subject: [PATCH 04/29] update todo --- todo.md | 1 + 1 file changed, 1 insertion(+) diff --git a/todo.md b/todo.md index 29ff1a2..91ee960 100644 --- a/todo.md +++ b/todo.md @@ -16,6 +16,7 @@ x.x - [x] update build and test process - [x] move package logic to libs - [ ] host vs server (allow user to run this application as a service) +- [ ] allow "localhost" for `-ip4` argument 0.2.1 - [x] issue with sending messages between two machines that are on macos and linux From 780a05bbdee763433aed2ad766f7be933e705a2f Mon Sep 17 00:00:00 2001 From: Brando Date: Thu, 9 Jan 2025 07:37:11 -0800 Subject: [PATCH 05/29] clean up --- src/interface.cpp | 3 --- 1 file changed, 3 deletions(-) diff --git a/src/interface.cpp b/src/interface.cpp index 47e095b..15a2aff 100644 --- a/src/interface.cpp +++ b/src/interface.cpp @@ -605,7 +605,6 @@ Chatroom * _InterfaceGetChatroomAtIndex(int i) { } int Interface::processinputStateLobby(InputBuffer & userInput) { - //if (userInput.isready()) { if (Utils::inputReady(userInput)) { Command cmd(userInput); if (!cmd.op().compareString(INTERFACE_COMMAND_QUIT)) { // quit @@ -658,7 +657,6 @@ int Interface::processinputStateLobby(InputBuffer & userInput) { } int Interface::processinputStateChatroom(InputBuffer & userInput) { - //if (userInput.isready()) { if (Utils::inputReady(userInput)) { Command cmd(userInput); if (!cmd.op().compareString(INTERFACE_COMMAND_LEAVE)) { // leave @@ -686,7 +684,6 @@ int Interface::processinputStateChatroom(InputBuffer & userInput) { } int Interface::processinputStateDraft(InputBuffer & userInput) { - //if (userInput.isready()) { // send buf if (Utils::inputReady(userInput)) { // send buf this->_chatroom.get()->sendBuffer(userInput); From 3a162d314794c16a7e33eabf833dbe0289cd6ae4 Mon Sep 17 00:00:00 2001 From: Brando Date: Thu, 9 Jan 2025 07:48:34 -0800 Subject: [PATCH 06/29] init operand that will handle the short and long version of a command's operand --- makefile | 2 +- src/command.cpp | 4 +++- src/operand.cpp | 17 +++++++++++++++++ src/operand.hpp | 22 ++++++++++++++++++++++ testbench/inputbuffer_tests.hpp | 2 +- testbench/operand_tests.hpp | 30 ++++++++++++++++++++++++++++++ testbench/tests.cpp | 2 ++ 7 files changed, 76 insertions(+), 3 deletions(-) create mode 100644 src/operand.cpp create mode 100644 src/operand.hpp create mode 100644 testbench/operand_tests.hpp diff --git a/makefile b/makefile index d526e77..5806f4f 100644 --- a/makefile +++ b/makefile @@ -43,7 +43,7 @@ log user inputbuffer office \ chatroom message chatroomserver packet \ agent agentclient agentserver sealedpacket \ chatroomclient interfaceserver interfaceclient command \ -permissions utils\ +permissions utils operand\ chat UNAME_S := $(shell uname -s) diff --git a/src/command.cpp b/src/command.cpp index 275bc94..4fae6b6 100644 --- a/src/command.cpp +++ b/src/command.cpp @@ -34,7 +34,9 @@ Command::~Command() { String Command::op() const { String res = this->argumentAtIndex(0); - res.remCharAtIndex(0); + if (res.starts_with(":")) { + res.remCharAtIndex(0); + } return res; } diff --git a/src/operand.cpp b/src/operand.cpp new file mode 100644 index 0000000..6025804 --- /dev/null +++ b/src/operand.cpp @@ -0,0 +1,17 @@ +/** + * author: brando + * date: 1/9/25 + */ + +#include "operand.hpp" +#include + +Operand::Operand(const char * vlong, char vshort) { + strcpy(this->_long, vlong); + this->_short = vshort; +} + +Operand::~Operand() { + +} + diff --git a/src/operand.hpp b/src/operand.hpp new file mode 100644 index 0000000..8538d43 --- /dev/null +++ b/src/operand.hpp @@ -0,0 +1,22 @@ +/** + * author: brando + * date: 1/9/25 + */ + +#ifndef OPERAND_HPP +#define OPERAND_HPP + +#include + +class Operand : public BF::Object { +public: + Operand(const char * vlong, char vshort); + virtual ~Operand(); + +private: + char _long[32]; + char _short; +}; + +#endif // OPERAND_HPP + diff --git a/testbench/inputbuffer_tests.hpp b/testbench/inputbuffer_tests.hpp index d993fe3..4f0b846 100644 --- a/testbench/inputbuffer_tests.hpp +++ b/testbench/inputbuffer_tests.hpp @@ -66,7 +66,7 @@ BFTEST_UNIT_FUNC(test_commandandarg, 2<<10, { buf.addChar('\n'); - if (!buf.isready()) { + if (!buf.enterPressed()) { result = max; } }) diff --git a/testbench/operand_tests.hpp b/testbench/operand_tests.hpp new file mode 100644 index 0000000..57e4520 --- /dev/null +++ b/testbench/operand_tests.hpp @@ -0,0 +1,30 @@ +/** + * author: Brando + * date: 1/9/25 + */ + +#ifndef OPERAND_TESTS_HPP +#define OPERAND_TESTS_HPP + +#define ASSERT_PUBLIC_MEMBER_ACCESS + +#include +#include "operand.hpp" + +extern "C" { +#include +#include +} + +using namespace BF; + +BFTEST_UNIT_FUNC(test_operandinit, 2<<10, { + Operand op("draft", 'i'); +}) + +BFTEST_COVERAGE_FUNC(operand_tests, { + BFTEST_LAUNCH(test_operandinit); +}) + +#endif // OPERAND_TESTS_HPP + diff --git a/testbench/tests.cpp b/testbench/tests.cpp index f8d97f8..4d6fd65 100644 --- a/testbench/tests.cpp +++ b/testbench/tests.cpp @@ -8,6 +8,7 @@ #include "message_tests.hpp" #include "packet_tests.hpp" #include "command_tests.hpp" +#include "operand_tests.hpp" #include "agent_tests.hpp" #include "ciphersymmetric_tests.hpp" #include "cipherasymmetric_tests.hpp" @@ -22,5 +23,6 @@ BFTEST_SUITE_FUNC({ BFTEST_SUITE_LAUNCH(agent_tests); BFTEST_SUITE_LAUNCH(ciphersymmetric_tests); BFTEST_SUITE_LAUNCH(cipherasymmetric_tests); + BFTEST_SUITE_LAUNCH(operand_tests); }) From fa9540be3a5bc2be55eb7dfb40a26bd351348cc7 Mon Sep 17 00:00:00 2001 From: Brando Date: Thu, 9 Jan 2025 07:50:50 -0800 Subject: [PATCH 07/29] adding notes --- src/operand.hpp | 4 ++++ testbench/operand_tests.hpp | 3 ++- 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/src/operand.hpp b/src/operand.hpp index 8538d43..e565b0f 100644 --- a/src/operand.hpp +++ b/src/operand.hpp @@ -8,6 +8,10 @@ #include +/** + * I want the user to be able to pass '?' or ":help" in the + * command prompt to get the help menu + */ class Operand : public BF::Object { public: Operand(const char * vlong, char vshort); diff --git a/testbench/operand_tests.hpp b/testbench/operand_tests.hpp index 57e4520..d391ad8 100644 --- a/testbench/operand_tests.hpp +++ b/testbench/operand_tests.hpp @@ -19,7 +19,8 @@ extern "C" { using namespace BF; BFTEST_UNIT_FUNC(test_operandinit, 2<<10, { - Operand op("draft", 'i'); + Operand op0("draft", 'i'); + Operand op1("help", '?'); }) BFTEST_COVERAGE_FUNC(operand_tests, { From 5ea71cd4ae39422b03c3f89e43200896c7c4ad53 Mon Sep 17 00:00:00 2001 From: Brando Date: Mon, 20 Jan 2025 09:40:32 -0800 Subject: [PATCH 08/29] adding simple constructors and compare ops --- src/operand.cpp | 16 +++++++++++++++- src/operand.hpp | 8 ++++++++ testbench/operand_tests.hpp | 18 ++++++++++++++++-- 3 files changed, 39 insertions(+), 3 deletions(-) diff --git a/src/operand.cpp b/src/operand.cpp index 6025804..19f42aa 100644 --- a/src/operand.cpp +++ b/src/operand.cpp @@ -11,7 +11,21 @@ Operand::Operand(const char * vlong, char vshort) { this->_short = vshort; } -Operand::~Operand() { +Operand::Operand(const char * vlong) : Operand(vlong, 0) { } +Operand::Operand(char vshort) : Operand("", vshort) { } + +Operand::~Operand() { } + +bool Operand::compare(const Operand & op) { + return !strcmp(this->_long, op._long) || this->_short == op._short; +} + +bool Operand::operator==(const Operand & op) { + return this->compare(op); +} + +bool Operand::operator!=(const Operand & op) { + return !this->compare(op); } diff --git a/src/operand.hpp b/src/operand.hpp index e565b0f..9c53fe8 100644 --- a/src/operand.hpp +++ b/src/operand.hpp @@ -15,11 +15,19 @@ class Operand : public BF::Object { public: Operand(const char * vlong, char vshort); + Operand(const char * vlong); + Operand(char vshort); virtual ~Operand(); + bool compare(const Operand & op); + private: char _long[32]; char _short; + +public: + bool operator==(const Operand & op); + bool operator!=(const Operand & op); }; #endif // OPERAND_HPP diff --git a/testbench/operand_tests.hpp b/testbench/operand_tests.hpp index d391ad8..cd72eef 100644 --- a/testbench/operand_tests.hpp +++ b/testbench/operand_tests.hpp @@ -19,12 +19,26 @@ extern "C" { using namespace BF; BFTEST_UNIT_FUNC(test_operandinit, 2<<10, { - Operand op0("draft", 'i'); - Operand op1("help", '?'); + Operand OP_DRAFT("draft", 'i'); + Operand OP_HELP("help", '?'); +}) + +BFTEST_UNIT_FUNC(test_operandcompare, 2<<10, { + Operand OP_DRAFT("draft", 'i'); + Operand OP_HELP("help", '?'); + + Operand op_draft_long("draft"); + Operand op_draft_short('i'); + BF_ASSERT(op_draft_long == OP_DRAFT); + BF_ASSERT(op_draft_short == OP_DRAFT); + BF_ASSERT(op_draft_long != OP_HELP); + BF_ASSERT(op_draft_short != OP_HELP); }) BFTEST_COVERAGE_FUNC(operand_tests, { BFTEST_LAUNCH(test_operandinit); + BFTEST_LAUNCH(test_operandcompare); + }) #endif // OPERAND_TESTS_HPP From 2b14a81c0f01cdef5a0ab778ce86bf4828b36df7 Mon Sep 17 00:00:00 2001 From: Brando Date: Mon, 20 Jan 2025 13:03:20 -0800 Subject: [PATCH 09/29] stable implementation of Operand --- src/command.cpp | 12 +++++++----- src/command.hpp | 3 ++- src/interface.cpp | 19 ++++++++++--------- src/operand.cpp | 13 +++++++++++++ src/operand.hpp | 10 ++++++++++ testbench/command_tests.hpp | 22 +++++++--------------- testbench/operand_tests.hpp | 16 ++++++++-------- todo.md | 1 + 8 files changed, 58 insertions(+), 38 deletions(-) diff --git a/src/command.cpp b/src/command.cpp index 4fae6b6..0223d51 100644 --- a/src/command.cpp +++ b/src/command.cpp @@ -5,6 +5,7 @@ #include "command.hpp" #include "inputbuffer.hpp" +#include "operand.hpp" #include extern "C" { @@ -32,12 +33,13 @@ Command::~Command() { } -String Command::op() const { - String res = this->argumentAtIndex(0); - if (res.starts_with(":")) { - res.remCharAtIndex(0); +Operand Command::op() const { + String arg = this->argumentAtIndex(0); + if (arg.starts_with(":")) { + arg.remCharAtIndex(0); } - return res; + + return Operand(arg); } String Command::operator[](int i) const { diff --git a/src/command.hpp b/src/command.hpp index 35aab59..e618f9f 100644 --- a/src/command.hpp +++ b/src/command.hpp @@ -11,6 +11,7 @@ #include class InputBuffer; +class Operand; class Command : public BF::Object { public: @@ -22,7 +23,7 @@ class Command : public BF::Object { * * this is the first word in the buf */ - BF::String op() const; + Operand op() const; BF::String argumentAtIndex(int i) const; diff --git a/src/interface.cpp b/src/interface.cpp index 15a2aff..d07c274 100644 --- a/src/interface.cpp +++ b/src/interface.cpp @@ -21,6 +21,7 @@ #include "command.hpp" #include "permissions.hpp" #include "utils.hpp" +#include "operand.hpp" extern "C" { #include @@ -607,13 +608,13 @@ Chatroom * _InterfaceGetChatroomAtIndex(int i) { int Interface::processinputStateLobby(InputBuffer & userInput) { if (Utils::inputReady(userInput)) { Command cmd(userInput); - if (!cmd.op().compareString(INTERFACE_COMMAND_QUIT)) { // quit + if (cmd.op() == OP_QUIT) { // quit Office::quitApplication(this->_user.get()); this->_state = kInterfaceStateQuit; - } else if (!cmd.op().compareString(INTERFACE_COMMAND_HELP)) { // help + } else if (cmd.op() == OP_HELP) { // help this->_returnfromhelpstate = this->_state; this->_state = kInterfaceStateHelp; - } else if (!cmd.op().compareString(INTERFACE_COMMAND_CREATE)) { // create + } else if (cmd.op() == OP_CREATE) { // create if (!Permissions::CanCreateChatroom()) { String errmsg("not permitted: you are not allowd to create a chatroom"); this->setErrorMessage(errmsg); @@ -633,7 +634,7 @@ int Interface::processinputStateLobby(InputBuffer & userInput) { Chatroom * cr = ChatroomServer::create(chatroomname); BFRelease(cr); } - } else if (!cmd.op().compareString(INTERFACE_COMMAND_JOIN)) { // join + } else if (cmd.op() == OP_JOIN) { // join int index = String::toi(cmd[1]) - 1; if ((index >= 0) && (index < Chatroom::getChatroomsCount())) { this->_chatroom = _InterfaceGetChatroomAtIndex(index); @@ -647,7 +648,7 @@ int Interface::processinputStateLobby(InputBuffer & userInput) { } } } else { - String errmsg("unknown command: %s", cmd.op().cString()); + String errmsg("unknown command: %s", cmd.op().description().cString()); this->setErrorMessage(errmsg); } userInput.reset(); @@ -659,7 +660,7 @@ int Interface::processinputStateLobby(InputBuffer & userInput) { int Interface::processinputStateChatroom(InputBuffer & userInput) { if (Utils::inputReady(userInput)) { Command cmd(userInput); - if (!cmd.op().compareString(INTERFACE_COMMAND_LEAVE)) { // leave + if (cmd.op() == OP_LEAVE) { // leave // tell chat room we are leaving this->_chatroom.get()->resign(this->_user); @@ -667,14 +668,14 @@ int Interface::processinputStateChatroom(InputBuffer & userInput) { this->_chatroom = NULL; this->_state = kInterfaceStateLobby; - } else if (!cmd.op().compareString(INTERFACE_COMMAND_HELP)) { // help + } else if (cmd.op() == OP_HELP) { // help this->_returnfromhelpstate = this->_state; this->_state = kInterfaceStateHelp; - } else if (!cmd.op().compareString(INTERFACE_COMMAND_DRAFT)) { // draft + } else if (cmd.op() == OP_DRAFT) { // draft this->_state = kInterfaceStateDraft; this->converstaionHasChanged(); } else { - String errmsg("unknown command: %s", cmd.op().cString()); + String errmsg("unknown command: %s", cmd.op().description().cString()); this->setErrorMessage(*errmsg); } diff --git a/src/operand.cpp b/src/operand.cpp index 19f42aa..53806d4 100644 --- a/src/operand.cpp +++ b/src/operand.cpp @@ -6,6 +6,15 @@ #include "operand.hpp" #include +using namespace BF; + +const Operand OP_HELP("help", '?'); +const Operand OP_CREATE("create"); +const Operand OP_JOIN("join"); +const Operand OP_LEAVE("leave"); +const Operand OP_DRAFT("draft", 'i'); +const Operand OP_QUIT("quit", 'q'); + Operand::Operand(const char * vlong, char vshort) { strcpy(this->_long, vlong); this->_short = vshort; @@ -29,3 +38,7 @@ bool Operand::operator!=(const Operand & op) { return !this->compare(op); } +String Operand::description() const { + return String("%s - %c", this->_long, this->_short); +} + diff --git a/src/operand.hpp b/src/operand.hpp index 9c53fe8..a865e25 100644 --- a/src/operand.hpp +++ b/src/operand.hpp @@ -7,6 +7,7 @@ #define OPERAND_HPP #include +#include /** * I want the user to be able to pass '?' or ":help" in the @@ -21,6 +22,8 @@ class Operand : public BF::Object { bool compare(const Operand & op); + BF::String description() const; + private: char _long[32]; char _short; @@ -30,5 +33,12 @@ class Operand : public BF::Object { bool operator!=(const Operand & op); }; +extern const Operand OP_HELP; +extern const Operand OP_CREATE; +extern const Operand OP_JOIN; +extern const Operand OP_LEAVE; +extern const Operand OP_DRAFT; +extern const Operand OP_QUIT; + #endif // OPERAND_HPP diff --git a/testbench/command_tests.hpp b/testbench/command_tests.hpp index bfaa7a7..630add9 100644 --- a/testbench/command_tests.hpp +++ b/testbench/command_tests.hpp @@ -10,6 +10,7 @@ #include #include "command.hpp" +#include "operand.hpp" #include "inputbuffer.hpp" extern "C" { @@ -28,33 +29,24 @@ BFTEST_UNIT_FUNC(test_commandop, 2<<10, { InputBuffer buf("command subcommand arg0 arg1"); Command c(buf); - if (strcmp(c.op(), "command")) { - result = 1; - } + BF_ASSERT(c.op() == Operand("command")); }) BFTEST_UNIT_FUNC(test_commandargs, 2<<10, { InputBuffer buf("command subcommand arg0 arg1"); Command c(buf); - if (strcmp(c.op(), "command")) { - result = 1; - } else if (strcmp(c[1], "subcommand")) { - result = 2; - } else if (strcmp(c[2], "arg0")) { - result = 3; - } else if (strcmp(c[3], "arg1")) { - result = 4; - } + BF_ASSERT(c.op() == Operand("command")); + BF_ASSERT(!strcmp(c[1], "subcommand")); + BF_ASSERT(!strcmp(c[2], "arg0")); + BF_ASSERT(!strcmp(c[3], "arg1")); }) BFTEST_UNIT_FUNC(test_commandargscount, 2<<10, { InputBuffer buf("command subcommand arg0 arg1"); Command c(buf); - if (c.count() == 0) { - result = max; - } + BF_ASSERT(c.count() > 0); }) BFTEST_COVERAGE_FUNC(command_tests, { diff --git a/testbench/operand_tests.hpp b/testbench/operand_tests.hpp index cd72eef..1bfb0b3 100644 --- a/testbench/operand_tests.hpp +++ b/testbench/operand_tests.hpp @@ -19,20 +19,20 @@ extern "C" { using namespace BF; BFTEST_UNIT_FUNC(test_operandinit, 2<<10, { - Operand OP_DRAFT("draft", 'i'); - Operand OP_HELP("help", '?'); + Operand op_draft("draft", 'i'); + Operand op_help("help", '?'); }) BFTEST_UNIT_FUNC(test_operandcompare, 2<<10, { - Operand OP_DRAFT("draft", 'i'); - Operand OP_HELP("help", '?'); + Operand op_draft("draft", 'i'); + Operand op_help("help", '?'); Operand op_draft_long("draft"); Operand op_draft_short('i'); - BF_ASSERT(op_draft_long == OP_DRAFT); - BF_ASSERT(op_draft_short == OP_DRAFT); - BF_ASSERT(op_draft_long != OP_HELP); - BF_ASSERT(op_draft_short != OP_HELP); + BF_ASSERT(op_draft_long == op_draft); + BF_ASSERT(op_draft_short == op_draft); + BF_ASSERT(op_draft_long != op_help); + BF_ASSERT(op_draft_short != op_help); }) BFTEST_COVERAGE_FUNC(operand_tests, { diff --git a/todo.md b/todo.md index 91ee960..46ebed8 100644 --- a/todo.md +++ b/todo.md @@ -11,6 +11,7 @@ x.x - [ ] improved controls (easier commands or guidance) - [x] use of ":" for long commands - [ ] single key commands + - [ ] make operand constants - [ ] chat configuration implemented in ncurses - [ ] user typing - [x] update build and test process From 450d2e29932d521b79bbb157323921a52f11dd7c Mon Sep 17 00:00:00 2001 From: Brando Date: Mon, 20 Jan 2025 13:41:10 -0800 Subject: [PATCH 10/29] making sure we do not compare empty var --- src/operand.cpp | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/operand.cpp b/src/operand.cpp index 53806d4..59da6f3 100644 --- a/src/operand.cpp +++ b/src/operand.cpp @@ -27,7 +27,9 @@ Operand::Operand(char vshort) : Operand("", vshort) { } Operand::~Operand() { } bool Operand::compare(const Operand & op) { - return !strcmp(this->_long, op._long) || this->_short == op._short; + bool long_mask = strlen(this->_long) > 0 && strlen(op._long) > 0 && !strcmp(this->_long, op._long); + bool short_mask = this->_short != 0 && op._short != 0 && this->_short == op._short; + return long_mask || short_mask; } bool Operand::operator==(const Operand & op) { From 72b08dc598ea96f6bd130e82511966de07506d0d Mon Sep 17 00:00:00 2001 From: Brando Date: Wed, 22 Jan 2025 08:40:40 -0800 Subject: [PATCH 11/29] testing utils --- src/interface.cpp | 6 +++--- src/utils.cpp | 7 +++++-- src/utils.hpp | 4 +++- testbench/tests.cpp | 2 ++ testbench/utils_tests.hpp | 38 ++++++++++++++++++++++++++++++++++++++ todo.md | 2 +- 6 files changed, 52 insertions(+), 7 deletions(-) create mode 100644 testbench/utils_tests.hpp diff --git a/src/interface.cpp b/src/interface.cpp index d07c274..5257695 100644 --- a/src/interface.cpp +++ b/src/interface.cpp @@ -606,7 +606,7 @@ Chatroom * _InterfaceGetChatroomAtIndex(int i) { } int Interface::processinputStateLobby(InputBuffer & userInput) { - if (Utils::inputReady(userInput)) { + if (Utils::inputReady(userInput, this->_state)) { Command cmd(userInput); if (cmd.op() == OP_QUIT) { // quit Office::quitApplication(this->_user.get()); @@ -658,7 +658,7 @@ int Interface::processinputStateLobby(InputBuffer & userInput) { } int Interface::processinputStateChatroom(InputBuffer & userInput) { - if (Utils::inputReady(userInput)) { + if (Utils::inputReady(userInput, this->_state)) { Command cmd(userInput); if (cmd.op() == OP_LEAVE) { // leave // tell chat room we are leaving @@ -685,7 +685,7 @@ int Interface::processinputStateChatroom(InputBuffer & userInput) { } int Interface::processinputStateDraft(InputBuffer & userInput) { - if (Utils::inputReady(userInput)) { // send buf + if (Utils::inputReady(userInput, this->_state)) { // send buf this->_chatroom.get()->sendBuffer(userInput); this->_state = kInterfaceStateChatroom; diff --git a/src/utils.cpp b/src/utils.cpp index 21b4dcc..df48a24 100644 --- a/src/utils.cpp +++ b/src/utils.cpp @@ -7,7 +7,10 @@ #include "inputbuffer.hpp" #include "interface.hpp" -bool Utils::inputReady(InputBuffer & buf) { - return buf.enterPressed() && (Interface::current()->currstate() == kInterfaceStateDraft || buf.starts_with(":")); +bool Utils::inputReady(InputBuffer & buf, InterfaceState state) { + return (buf.enterPressed() && (state == kInterfaceStateDraft || buf.starts_with(":"))) + || + (buf.length() == 1) && !buf.starts_with(":") + ; } diff --git a/src/utils.hpp b/src/utils.hpp index d2556cb..5a60e3d 100644 --- a/src/utils.hpp +++ b/src/utils.hpp @@ -6,10 +6,12 @@ #ifndef UTILS_HPP #define UTILS_HPP +#include "typeinterfacestate.hpp" + class InputBuffer; namespace Utils { -bool inputReady(InputBuffer & buf); +bool inputReady(InputBuffer & buf, InterfaceState state); } #endif // UTILS_HPP diff --git a/testbench/tests.cpp b/testbench/tests.cpp index 4d6fd65..a74b17a 100644 --- a/testbench/tests.cpp +++ b/testbench/tests.cpp @@ -12,6 +12,7 @@ #include "agent_tests.hpp" #include "ciphersymmetric_tests.hpp" #include "cipherasymmetric_tests.hpp" +#include "utils_tests.hpp" #include "log.hpp" BFTEST_SUITE_FUNC({ @@ -24,5 +25,6 @@ BFTEST_SUITE_FUNC({ BFTEST_SUITE_LAUNCH(ciphersymmetric_tests); BFTEST_SUITE_LAUNCH(cipherasymmetric_tests); BFTEST_SUITE_LAUNCH(operand_tests); + BFTEST_SUITE_LAUNCH(utils_tests); }) diff --git a/testbench/utils_tests.hpp b/testbench/utils_tests.hpp new file mode 100644 index 0000000..157b992 --- /dev/null +++ b/testbench/utils_tests.hpp @@ -0,0 +1,38 @@ +/** + * author: Brando + * date: 1/21/25 + */ + +#ifndef UTILS_TESTS_HPP +#define UTILS_TESTS_HPP + +#define ASSERT_PUBLIC_MEMBER_ACCESS + +#include +#include "utils.hpp" +#include "inputbuffer.hpp" + +extern "C" { +#include +#include +} + +using namespace BF; + +BFTEST_UNIT_FUNC(test_utilsIsReady, 2<<10, { + InputBuffer b0("i"); + BF_ASSERT(Utils::inputReady(b0, kInterfaceStateDraft)); + InputBuffer b1("asdf"); + BF_ASSERT(!Utils::inputReady(b1, kInterfaceStateDraft)); + InputBuffer b2("asdf"); + b2.addChar('\n'); + BF_ASSERT(Utils::inputReady(b2, kInterfaceStateDraft)); + +}) + +BFTEST_COVERAGE_FUNC(utils_tests, { + BFTEST_LAUNCH(test_utilsIsReady); +}) + +#endif // UTILS_TESTS_HPP + diff --git a/todo.md b/todo.md index 46ebed8..1081f71 100644 --- a/todo.md +++ b/todo.md @@ -11,7 +11,7 @@ x.x - [ ] improved controls (easier commands or guidance) - [x] use of ":" for long commands - [ ] single key commands - - [ ] make operand constants + - [x] make operand constants - [ ] chat configuration implemented in ncurses - [ ] user typing - [x] update build and test process From 5e4d7a2f8ca1a5c0a4022019cae4311886334946 Mon Sep 17 00:00:00 2001 From: Brando Date: Wed, 22 Jan 2025 09:51:07 -0800 Subject: [PATCH 12/29] adjusting makefile --- makefile | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-) diff --git a/makefile b/makefile index 5806f4f..d0ff4f4 100644 --- a/makefile +++ b/makefile @@ -61,11 +61,16 @@ LIBRARIES = external/bin/openssl/libssl.a external/bin/openssl/libcrypto.a OPENSSL_INCLUDE_PATH = -Iexternal/bin/openssl/include endif -ifneq ($(CONFIG),test) # test +ifeq ($(CONFIG),release) # release +LIBRARIES += \ + external/bin/libs/release/bflibc/libbfc.a \ + external/bin/libs/release/bflibcpp/libbfcpp.a \ + external/bin/libs/release/bfnet/libbfnet.a +else LIBRARIES += \ - external/bin/libs/$(CONFIG)/bflibc/libbfc.a \ - external/bin/libs/$(CONFIG)/bflibcpp/libbfcpp.a \ - external/bin/libs/$(CONFIG)/bfnet/libbfnet.a + external/bin/libs/debug/bflibc/libbfc-debug.a \ + external/bin/libs/debug/bflibcpp/libbfcpp-debug.a \ + external/bin/libs/debug/bfnet/libbfnet-debug.a endif LINKS = -lpthread -lncurses $(BF_LIB_C_FLAGS) -ldl @@ -89,11 +94,7 @@ MAIN_FILE = testbench/tests.cpp BIN_NAME = chat-test #ADDR_SANITIZER = -fsanitize=address FLAGS = $(CPPFLAGS) -DDEBUG -DTESTING -g -Isrc/ $(ADDR_SANITIZER) $(CPPSTD) -Iexternal/bin/libs/debug $(OPENSSL_INCLUDE_PATH) -LIBRARIES += \ - external/bin/libs/debug/bflibc/libbfc-debug.a \ - external/bin/libs/debug/bflibcpp/libbfcpp-debug.a \ - external/bin/libs/debug/bfnet/libbfnet-debug.a \ - external/bin/libs/debug/bftest/libbftest-debug.a +LIBRARIES += external/bin/libs/debug/bftest/libbftest-debug.a endif # ($(CONFIG),...) LIBS_MAKEFILES_PATH:=$(CURDIR)/external/libs/makefiles From aa9924eea66f0668ad74656cfa9e6b82fb8ae4ba Mon Sep 17 00:00:00 2001 From: Brando Date: Thu, 23 Jan 2025 15:35:25 -0800 Subject: [PATCH 13/29] saving libs --- external/libs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/external/libs b/external/libs index cc6dea4..bb6bea1 160000 --- a/external/libs +++ b/external/libs @@ -1 +1 @@ -Subproject commit cc6dea40b5632d6616139180f13b184607baa03a +Subproject commit bb6bea1f231ba277cf4f50f5ed0a3b12a1e7cc4d From 9bac2bed173fbc7a66affec61a4f7e955b1ccd0b Mon Sep 17 00:00:00 2001 From: Brando Date: Thu, 23 Jan 2025 15:48:59 -0800 Subject: [PATCH 14/29] stable build but fails tests --- external/libs | 2 +- src/command.cpp | 2 +- src/operand.cpp | 37 +++++++++++++++++++++---------------- src/operand.hpp | 7 ++----- testbench/command_tests.hpp | 4 ++-- testbench/operand_tests.hpp | 12 ++++++------ 6 files changed, 33 insertions(+), 31 deletions(-) diff --git a/external/libs b/external/libs index bb6bea1..bafe45b 160000 --- a/external/libs +++ b/external/libs @@ -1 +1 @@ -Subproject commit bb6bea1f231ba277cf4f50f5ed0a3b12a1e7cc4d +Subproject commit bafe45bbb467891c190b84912038dd7a9ea02251 diff --git a/src/command.cpp b/src/command.cpp index 0223d51..128d3cf 100644 --- a/src/command.cpp +++ b/src/command.cpp @@ -39,7 +39,7 @@ Operand Command::op() const { arg.remCharAtIndex(0); } - return Operand(arg); + return Operand({arg}); } String Command::operator[](int i) const { diff --git a/src/operand.cpp b/src/operand.cpp index 59da6f3..a2cb59e 100644 --- a/src/operand.cpp +++ b/src/operand.cpp @@ -6,30 +6,35 @@ #include "operand.hpp" #include +extern "C" { +#include +} + using namespace BF; -const Operand OP_HELP("help", '?'); -const Operand OP_CREATE("create"); -const Operand OP_JOIN("join"); -const Operand OP_LEAVE("leave"); -const Operand OP_DRAFT("draft", 'i'); -const Operand OP_QUIT("quit", 'q'); +const Operand OP_HELP({"help", "?"}); +const Operand OP_CREATE({"create"}); +const Operand OP_JOIN({"join"}); +const Operand OP_LEAVE({"leave"}); +const Operand OP_DRAFT({"draft", "i"}); +const Operand OP_QUIT({"quit", "q"}); -Operand::Operand(const char * vlong, char vshort) { - strcpy(this->_long, vlong); - this->_short = vshort; +void _OperandAcceptArgsRelease(char * a) { + BFFree(a); } -Operand::Operand(const char * vlong) : Operand(vlong, 0) { } - -Operand::Operand(char vshort) : Operand("", vshort) { } +Operand::Operand(std::initializer_list list) : Object() { + this->_acceptedArgs.setReleaseCallback(_OperandAcceptArgsRelease); + for (const char * arg : list) { + char * buf = BFStringCopyString(arg); + this->_acceptedArgs.add(buf); + } +} Operand::~Operand() { } bool Operand::compare(const Operand & op) { - bool long_mask = strlen(this->_long) > 0 && strlen(op._long) > 0 && !strcmp(this->_long, op._long); - bool short_mask = this->_short != 0 && op._short != 0 && this->_short == op._short; - return long_mask || short_mask; + return false; } bool Operand::operator==(const Operand & op) { @@ -41,6 +46,6 @@ bool Operand::operator!=(const Operand & op) { } String Operand::description() const { - return String("%s - %c", this->_long, this->_short); + return String("unknown"); } diff --git a/src/operand.hpp b/src/operand.hpp index a865e25..b2bbf99 100644 --- a/src/operand.hpp +++ b/src/operand.hpp @@ -15,9 +15,7 @@ */ class Operand : public BF::Object { public: - Operand(const char * vlong, char vshort); - Operand(const char * vlong); - Operand(char vshort); + Operand(std::initializer_list list); virtual ~Operand(); bool compare(const Operand & op); @@ -25,8 +23,7 @@ class Operand : public BF::Object { BF::String description() const; private: - char _long[32]; - char _short; + BF::Array _acceptedArgs; public: bool operator==(const Operand & op); diff --git a/testbench/command_tests.hpp b/testbench/command_tests.hpp index 630add9..aded932 100644 --- a/testbench/command_tests.hpp +++ b/testbench/command_tests.hpp @@ -29,14 +29,14 @@ BFTEST_UNIT_FUNC(test_commandop, 2<<10, { InputBuffer buf("command subcommand arg0 arg1"); Command c(buf); - BF_ASSERT(c.op() == Operand("command")); + BF_ASSERT(c.op() == Operand({"command"})); }) BFTEST_UNIT_FUNC(test_commandargs, 2<<10, { InputBuffer buf("command subcommand arg0 arg1"); Command c(buf); - BF_ASSERT(c.op() == Operand("command")); + BF_ASSERT(c.op() == Operand({"command"})); BF_ASSERT(!strcmp(c[1], "subcommand")); BF_ASSERT(!strcmp(c[2], "arg0")); BF_ASSERT(!strcmp(c[3], "arg1")); diff --git a/testbench/operand_tests.hpp b/testbench/operand_tests.hpp index 1bfb0b3..b9c5814 100644 --- a/testbench/operand_tests.hpp +++ b/testbench/operand_tests.hpp @@ -19,16 +19,16 @@ extern "C" { using namespace BF; BFTEST_UNIT_FUNC(test_operandinit, 2<<10, { - Operand op_draft("draft", 'i'); - Operand op_help("help", '?'); + Operand op_draft({"draft", "i"}); + Operand op_help({"help", "?"}); }) BFTEST_UNIT_FUNC(test_operandcompare, 2<<10, { - Operand op_draft("draft", 'i'); - Operand op_help("help", '?'); + Operand op_draft({"draft", "i"}); + Operand op_help({"help", "?"}); - Operand op_draft_long("draft"); - Operand op_draft_short('i'); + Operand op_draft_long({"draft"}); + Operand op_draft_short({"i"}); BF_ASSERT(op_draft_long == op_draft); BF_ASSERT(op_draft_short == op_draft); BF_ASSERT(op_draft_long != op_help); From 6c26aaaa2e6201ddb336dcae3c3be648b7f8bd71 Mon Sep 17 00:00:00 2001 From: Brando Date: Thu, 23 Jan 2025 16:09:11 -0800 Subject: [PATCH 15/29] stable but buggy --- external/libs | 2 +- src/operand.cpp | 13 ++++++++++++- 2 files changed, 13 insertions(+), 2 deletions(-) diff --git a/external/libs b/external/libs index bafe45b..3b30852 160000 --- a/external/libs +++ b/external/libs @@ -1 +1 @@ -Subproject commit bafe45bbb467891c190b84912038dd7a9ea02251 +Subproject commit 3b308521153fe03300a60728f05020c828c2d6d7 diff --git a/src/operand.cpp b/src/operand.cpp index a2cb59e..08249eb 100644 --- a/src/operand.cpp +++ b/src/operand.cpp @@ -34,6 +34,17 @@ Operand::Operand(std::initializer_list list) : Object() { Operand::~Operand() { } bool Operand::compare(const Operand & op) { + // FIXME: + // this is a poor implementation. time efficiency will decrease + // as more accepted arguments are implmented. I suggested to use + // algorithms as presented here:https://stackoverflow.com/a/245521/12135693 + // + // current implementation for BF::Array doesn't support the scope of those + // algorithms + for (int i = 0; i < this->_acceptedArgs.count(); i++) { + if (op._acceptedArgs.contains(this->_acceptedArgs[i])) + return true; + } return false; } @@ -46,6 +57,6 @@ bool Operand::operator!=(const Operand & op) { } String Operand::description() const { - return String("unknown"); + return String("%s", this->_acceptedArgs[0]); } From 273321aa2ff508a29ed87e6039363d1e6eed823a Mon Sep 17 00:00:00 2001 From: Brando Date: Thu, 23 Jan 2025 16:22:18 -0800 Subject: [PATCH 16/29] can compare operands (test passed) --- external/libs | 2 +- src/interface.cpp | 4 ++-- src/operand.cpp | 5 +++++ 3 files changed, 8 insertions(+), 3 deletions(-) diff --git a/external/libs b/external/libs index 3b30852..dae623c 160000 --- a/external/libs +++ b/external/libs @@ -1 +1 @@ -Subproject commit 3b308521153fe03300a60728f05020c828c2d6d7 +Subproject commit dae623c857cfcb6c56038c71780de27046a7f035 diff --git a/src/interface.cpp b/src/interface.cpp index 5257695..a82a3ad 100644 --- a/src/interface.cpp +++ b/src/interface.cpp @@ -648,7 +648,7 @@ int Interface::processinputStateLobby(InputBuffer & userInput) { } } } else { - String errmsg("unknown command: %s", cmd.op().description().cString()); + String errmsg("unknown command: '%s'", cmd.op().description().cString()); this->setErrorMessage(errmsg); } userInput.reset(); @@ -675,7 +675,7 @@ int Interface::processinputStateChatroom(InputBuffer & userInput) { this->_state = kInterfaceStateDraft; this->converstaionHasChanged(); } else { - String errmsg("unknown command: %s", cmd.op().description().cString()); + String errmsg("unknown command: '%s'", cmd.op().description().cString()); this->setErrorMessage(*errmsg); } diff --git a/src/operand.cpp b/src/operand.cpp index 08249eb..6478828 100644 --- a/src/operand.cpp +++ b/src/operand.cpp @@ -23,12 +23,17 @@ void _OperandAcceptArgsRelease(char * a) { BFFree(a); } +int _OperandAcceptArgsCompare(char * a, char * b) { + return strcmp(a, b); +} + Operand::Operand(std::initializer_list list) : Object() { this->_acceptedArgs.setReleaseCallback(_OperandAcceptArgsRelease); for (const char * arg : list) { char * buf = BFStringCopyString(arg); this->_acceptedArgs.add(buf); } + this->_acceptedArgs.setComparator(_OperandAcceptArgsCompare); } Operand::~Operand() { } From c3228cc50d1b37149646be2d388d52d9d5237bb8 Mon Sep 17 00:00:00 2001 From: Brando Date: Thu, 23 Jan 2025 16:24:28 -0800 Subject: [PATCH 17/29] adding todo --- todo.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/todo.md b/todo.md index 1081f71..04e0ff1 100644 --- a/todo.md +++ b/todo.md @@ -12,6 +12,8 @@ x.x - [x] use of ":" for long commands - [ ] single key commands - [x] make operand constants + - [ ] drafting messages crashes + - [ ] add text at the bottom that says "press '?' or type ":help" to show help" - [ ] chat configuration implemented in ncurses - [ ] user typing - [x] update build and test process From be1d07743b98d81a7ccc7c62bd2d91b07afe087a Mon Sep 17 00:00:00 2001 From: Brando Date: Thu, 23 Jan 2025 18:56:31 -0800 Subject: [PATCH 18/29] can use 'i' to draft a message --- src/utils.cpp | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/src/utils.cpp b/src/utils.cpp index df48a24..9e715f4 100644 --- a/src/utils.cpp +++ b/src/utils.cpp @@ -8,9 +8,12 @@ #include "interface.hpp" bool Utils::inputReady(InputBuffer & buf, InterfaceState state) { - return (buf.enterPressed() && (state == kInterfaceStateDraft || buf.starts_with(":"))) + return + buf.starts_with(":") && (buf.length() > 1) && buf.enterPressed() || - (buf.length() == 1) && !buf.starts_with(":") + !buf.starts_with(":") && (buf.length() == 1) && (state != kInterfaceStateDraft) + || + (state == kInterfaceStateDraft) && buf.enterPressed(); ; } From aecb474d9e9e2fb9b4a36d6fee3323a47f13c402 Mon Sep 17 00:00:00 2001 From: Brando Date: Thu, 23 Jan 2025 18:59:10 -0800 Subject: [PATCH 19/29] removing dereferencing --- src/interface.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/interface.cpp b/src/interface.cpp index a82a3ad..ccbe171 100644 --- a/src/interface.cpp +++ b/src/interface.cpp @@ -676,7 +676,7 @@ int Interface::processinputStateChatroom(InputBuffer & userInput) { this->converstaionHasChanged(); } else { String errmsg("unknown command: '%s'", cmd.op().description().cString()); - this->setErrorMessage(*errmsg); + this->setErrorMessage(errmsg); } userInput.reset(); From 4d849733404e9fd2d19b5684f7cba3c9ea41d931 Mon Sep 17 00:00:00 2001 From: Brando Date: Thu, 23 Jan 2025 18:59:54 -0800 Subject: [PATCH 20/29] update todo --- todo.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/todo.md b/todo.md index 04e0ff1..d856407 100644 --- a/todo.md +++ b/todo.md @@ -10,9 +10,9 @@ x.x 0.3 - [ ] improved controls (easier commands or guidance) - [x] use of ":" for long commands - - [ ] single key commands + - [x] single key commands - [x] make operand constants - - [ ] drafting messages crashes + - [x] drafting messages crashes - [ ] add text at the bottom that says "press '?' or type ":help" to show help" - [ ] chat configuration implemented in ncurses - [ ] user typing From 44cba8f844af0bff7e0c719f27cfea4992b953ea Mon Sep 17 00:00:00 2001 From: Brando Date: Thu, 23 Jan 2025 19:22:31 -0800 Subject: [PATCH 21/29] adding footer for '?' for help --- src/interface.cpp | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/interface.cpp b/src/interface.cpp index ccbe171..1837d42 100644 --- a/src/interface.cpp +++ b/src/interface.cpp @@ -525,7 +525,11 @@ int Interface::windowUpdateInputWindowText(InputBuffer & userInput) { BFLockLock(&this->_winlock); werase(this->_inputWin); if (this->_errorMessage.length() == 0) { - mvwprintw(this->_inputWin, 0, 0, userInput.cString()); + if (userInput.length() == 0) { + mvwprintw(this->_inputWin, 0, 0, "-- '?' for help --"); + } else { + mvwprintw(this->_inputWin, 0, 0, userInput.cString()); + } } else { mvwprintw(this->_inputWin, 0, 0, this->_errorMessage.cString()); this->_errorMessage.clear(); From 88d15bdddbd16a95fa1496689415267880f85010 Mon Sep 17 00:00:00 2001 From: Brando Date: Thu, 23 Jan 2025 19:22:58 -0800 Subject: [PATCH 22/29] update todo --- todo.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/todo.md b/todo.md index d856407..2a05f23 100644 --- a/todo.md +++ b/todo.md @@ -8,12 +8,12 @@ x.x - [ ] ai bot chatroom 0.3 -- [ ] improved controls (easier commands or guidance) +- [x] improved controls (easier commands or guidance) - [x] use of ":" for long commands - [x] single key commands - [x] make operand constants - [x] drafting messages crashes - - [ ] add text at the bottom that says "press '?' or type ":help" to show help" + - [x] add text at the bottom that says "press '?' or type ":help" to show help" - [ ] chat configuration implemented in ncurses - [ ] user typing - [x] update build and test process From bcd57b367d45b5c0d490ab7872226a23b829c59c Mon Sep 17 00:00:00 2001 From: Brando Date: Thu, 23 Jan 2025 19:42:36 -0800 Subject: [PATCH 23/29] updating libs ref --- external/libs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/external/libs b/external/libs index dae623c..9324295 160000 --- a/external/libs +++ b/external/libs @@ -1 +1 @@ -Subproject commit dae623c857cfcb6c56038c71780de27046a7f035 +Subproject commit 9324295e970bd60d9e46d0404b2740f16c7fae12 From c2bf474cde9677f5315adbcae5295088ea0a993d Mon Sep 17 00:00:00 2001 From: Brando Date: Fri, 24 Jan 2025 00:17:31 -0800 Subject: [PATCH 24/29] update yaml --- .github/workflows/test.yml | 2 ++ external/libs | 2 +- 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index b109143..3661c32 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -14,6 +14,8 @@ jobs: with: submodules: recursive token: ${{ secrets.PAT_TOKEN }} + - name: Install uuid-dev + run: sudo apt -y install uuid-dev - name: building libs run: | cd external; diff --git a/external/libs b/external/libs index 9324295..8b86612 160000 --- a/external/libs +++ b/external/libs @@ -1 +1 @@ -Subproject commit 9324295e970bd60d9e46d0404b2740f16c7fae12 +Subproject commit 8b86612c7f35be8ba26a8da4392276bfcf054886 From 166ae66d9abfb7e55b2c0c8d35f45db4e321866e Mon Sep 17 00:00:00 2001 From: Brando Date: Fri, 24 Jan 2025 00:21:44 -0800 Subject: [PATCH 25/29] updating libs --- external/libs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/external/libs b/external/libs index 8b86612..5d6b093 160000 --- a/external/libs +++ b/external/libs @@ -1 +1 @@ -Subproject commit 8b86612c7f35be8ba26a8da4392276bfcf054886 +Subproject commit 5d6b093e11f6f62114d7447be5fda9230ebfc7fb From 69b90a2d6e2ac7bb56bd758d069bf3c86f65f0f2 Mon Sep 17 00:00:00 2001 From: Brandon Fong <55638760+BrandonMFong@users.noreply.github.com> Date: Fri, 24 Jan 2025 00:28:26 -0800 Subject: [PATCH 26/29] Update test.yml --- .github/workflows/test.yml | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 3661c32..eddd976 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -15,7 +15,10 @@ jobs: submodules: recursive token: ${{ secrets.PAT_TOKEN }} - name: Install uuid-dev - run: sudo apt -y install uuid-dev + run: | + sudo apt -y update; + sudo apt -y upgrade; + sudo apt -y install uuid-dev; - name: building libs run: | cd external; From 26d87fd484fe25a70d95cc4550203ebd39c24786 Mon Sep 17 00:00:00 2001 From: Brando Date: Fri, 24 Jan 2025 07:32:14 -0800 Subject: [PATCH 27/29] ping --- .github/workflows/test.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index eddd976..c93a7d7 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -18,7 +18,7 @@ jobs: run: | sudo apt -y update; sudo apt -y upgrade; - sudo apt -y install uuid-dev; + sudo apt -y install uuid-dev; - name: building libs run: | cd external; From f7143858f35a82a8c31ca3485955df0b9ec47d06 Mon Sep 17 00:00:00 2001 From: Brando Date: Fri, 24 Jan 2025 09:19:59 -0800 Subject: [PATCH 28/29] updating libs --- external/libs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/external/libs b/external/libs index 5d6b093..abd76a6 160000 --- a/external/libs +++ b/external/libs @@ -1 +1 @@ -Subproject commit 5d6b093e11f6f62114d7447be5fda9230ebfc7fb +Subproject commit abd76a69a024b31962bb06cec50918f4bca75f92 From 238a5511b753e6633cb3f94ac6e4c315497c5d2b Mon Sep 17 00:00:00 2001 From: Brando Date: Fri, 24 Jan 2025 09:52:45 -0800 Subject: [PATCH 29/29] update todo --- todo.md | 1 + 1 file changed, 1 insertion(+) diff --git a/todo.md b/todo.md index 2a05f23..0d720c5 100644 --- a/todo.md +++ b/todo.md @@ -14,6 +14,7 @@ x.x - [x] make operand constants - [x] drafting messages crashes - [x] add text at the bottom that says "press '?' or type ":help" to show help" +- [ ] improve help - [ ] chat configuration implemented in ncurses - [ ] user typing - [x] update build and test process