summary refs log tree commit diff
diff options
context:
space:
mode:
authorJune McEnroe <june@causal.agency>2020-02-05 19:00:54 -0500
committerJune McEnroe <june@causal.agency>2020-02-05 19:00:54 -0500
commitb2d35edcb22a9a41235229b41b180a50b51b5908 (patch)
tree4cfc6ca3682aff0fa7fd65348c35210df832460f
parentScroll the input window (diff)
downloadcatgirl-b2d35edcb22a9a41235229b41b180a50b51b5908.tar.gz
catgirl-b2d35edcb22a9a41235229b41b180a50b51b5908.zip
Change prompt depending on command
Diffstat (limited to '')
-rw-r--r--chat.h3
-rw-r--r--command.c21
-rw-r--r--ui.c23
3 files changed, 42 insertions, 5 deletions
diff --git a/chat.h b/chat.h
index 90c7da8..b73cf40 100644
--- a/chat.h
+++ b/chat.h
@@ -112,6 +112,9 @@ void ircFormat(const char *format, ...)
 
 void handle(struct Message msg);
 void command(size_t id, char *input);
+const char *commandIsPrivmsg(size_t id, const char *input);
+const char *commandIsNotice(size_t id, const char *input);
+const char *commandIsAction(size_t id, const char *input);
 
 enum Heat { Cold, Warm, Hot };
 void uiInit(void);
diff --git a/command.c b/command.c
index ef27888..928f470 100644
--- a/command.c
+++ b/command.c
@@ -19,6 +19,27 @@
 
 #include "chat.h"
 
+const char *commandIsPrivmsg(size_t id, const char *input) {
+	if (id == Network || id == Debug) return NULL;
+	if (input[0] != '/') return input;
+	const char *space = strchr(&input[1], ' ');
+	const char *slash = strchr(&input[1], '/');
+	if (slash && (!space || slash < space)) return input;
+	return NULL;
+}
+
+const char *commandIsNotice(size_t id, const char *input) {
+	if (id == Network || id == Debug) return NULL;
+	if (strncmp(input, "/notice ", 8)) return NULL;
+	return &input[8];
+}
+
+const char *commandIsAction(size_t id, const char *input) {
+	if (id == Network || id == Debug) return NULL;
+	if (strncmp(input, "/me ", 4)) return NULL;
+	return &input[4];
+}
+
 void command(size_t id, char *input) {
 	if (id == Debug) {
 		ircFormat("%s\r\n", input);
diff --git a/ui.c b/ui.c
index 12c8541..daa6dec 100644
--- a/ui.c
+++ b/ui.c
@@ -479,16 +479,29 @@ static void inputUpdate(void) {
 		colorPair(mapColor(self.color), -1),
 		NULL
 	);
+	const char *head = editHead();
+	const char *skip = NULL;
 	if (self.nick) {
-		// TODO: Check if input is command or action.
-		waddch(input, '<');
-		waddstr(input, self.nick);
-		waddstr(input, "> ");
+		size_t id = windows.active->id;
+		if (NULL != (skip = commandIsPrivmsg(id, head))) {
+			waddch(input, '<');
+			waddstr(input, self.nick);
+			waddstr(input, "> ");
+		} else if (NULL != (skip = commandIsNotice(id, head))) {
+			waddch(input, '-');
+			waddstr(input, self.nick);
+			waddstr(input, "- ");
+		} else if (NULL != (skip = commandIsAction(id, head))) {
+			waddstr(input, "* ");
+			waddstr(input, self.nick);
+			waddch(input, ' ');
+		}
 	}
+	if (skip) head = skip;
 
 	int y, x;
 	struct Style style = Reset;
-	inputAdd(&style, editHead());
+	inputAdd(&style, head);
 	getyx(input, y, x);
 	inputAdd(&style, editTail());
 	wclrtoeol(input);