about summary refs log tree commit diff
diff options
context:
space:
mode:
-rw-r--r--chat.h1
-rw-r--r--command.c34
2 files changed, 22 insertions, 13 deletions
diff --git a/chat.h b/chat.h
index 5b3c01c..9317843 100644
--- a/chat.h
+++ b/chat.h
@@ -123,6 +123,7 @@ void uiShow(void);
 void uiHide(void);
 void uiDraw(void);
 void uiShowID(size_t id);
+void uiShowNum(size_t num);
 void uiRead(void);
 void uiWrite(size_t id, enum Heat heat, const time_t *time, const char *str);
 void uiFormat(
diff --git a/command.c b/command.c
index 7fb98af..8471214 100644
--- a/command.c
+++ b/command.c
@@ -57,9 +57,16 @@ static void commandMe(size_t id, char *params) {
 }
 
 static void commandQuit(size_t id, char *params) {
+	(void)id;
 	set(&self.quit, (params ? params : "Goodbye"));
 }
 
+static void commandWindow(size_t id, char *params) {
+	(void)id;
+	if (!params) return;
+	uiShowNum(strtoul(params, NULL, 10));
+}
+
 static const struct Handler {
 	const char *cmd;
 	Command *fn;
@@ -68,6 +75,7 @@ static const struct Handler {
 	{ "/notice", commandNotice },
 	{ "/quit", commandQuit },
 	{ "/quote", commandQuote },
+	{ "/window", commandWindow },
 };
 
 static int compar(const void *cmd, const void *_handler) {
@@ -97,21 +105,21 @@ const char *commandIsAction(size_t id, const char *input) {
 }
 
 void command(size_t id, char *input) {
-	if (id == Debug) {
+	if (id == Debug && input[0] != '/') {
 		commandQuote(id, input);
-		return;
-	}
-	if (commandIsPrivmsg(id, input)) {
+	} else if (commandIsPrivmsg(id, input)) {
 		commandPrivmsg(id, input);
-		return;
-	}
-	char *cmd = strsep(&input, " ");
-	const struct Handler *handler = bsearch(
-		cmd, Commands, ARRAY_LEN(Commands), sizeof(*handler), compar
-	);
-	if (handler) {
-		handler->fn(id, input);
+	} else if (input[0] == '/' && isdigit(input[1])) {
+		commandWindow(id, &input[1]);
 	} else {
-		uiFormat(id, Hot, NULL, "No such command %s", cmd);
+		char *cmd = strsep(&input, " ");
+		const struct Handler *handler = bsearch(
+			cmd, Commands, ARRAY_LEN(Commands), sizeof(*handler), compar
+		);
+		if (handler) {
+			handler->fn(id, input);
+		} else {
+			uiFormat(id, Hot, NULL, "No such command %s", cmd);
+		}
 	}
 }
2019-02-22Reorganize input.cJune McEnroe 2019-02-22Fix name of <raw> window in man pageJune McEnroe 2019-02-22Rename global tags with angle bracketsJune McEnroe 2019-02-22Show status window while connectingJune McEnroe 2019-02-22Reorganize UI code for the umpteenth timeJune McEnroe It's actually in a good state now, I think. 2019-02-21Replace "view" with "window"June McEnroe I think originally I didn't want to use the same word as curses WINDOW but it's really much clearer for the user if they're just called windows. UI code probably needs yet another rewrite though. Still feels messy. 2019-02-21Remove ROT13June McEnroe It's just not convenient when it can only do the whole line... 2019-02-21Clean up man pageJune McEnroe 2019-01-26Draw UI before connectingJune McEnroe Otherwise the "Traveling" message isn't visible while connecting. 2019-01-25Avoid unused variable warnings with getyxJune McEnroe 2019-01-25Add GNU/Linux build instructionsJune McEnroe