summary refs log tree commit diff
path: root/ui.c
diff options
context:
space:
mode:
authorJune McEnroe <june@causal.agency>2019-02-23 12:24:39 -0500
committerJune McEnroe <june@causal.agency>2019-02-23 12:24:39 -0500
commitc06a45746117786f687ded1c62047e9194107e96 (patch)
treec0ec8f298830dd055615591dfc347b9eb067c541 /ui.c
parentChange example command to join #ascii.town on freenode (diff)
downloadcatgirl-c06a45746117786f687ded1c62047e9194107e96.tar.gz
catgirl-c06a45746117786f687ded1c62047e9194107e96.zip
Add C-n and C-p key bindings to switch windows
Diffstat (limited to 'ui.c')
-rw-r--r--ui.c20
1 files changed, 10 insertions, 10 deletions
diff --git a/ui.c b/ui.c
index 26598cb..2f58fd4 100644
--- a/ui.c
+++ b/ui.c
@@ -354,18 +354,15 @@ void uiShowTag(struct Tag tag) {
 	uiPrompt(false);
 }
 
-void uiShowNum(int num) {
-	struct Window *win = NULL;
+void uiShowNum(int num, bool relative) {
+	struct Window *win = (relative ? windows.active : windows.head);
 	if (num < 0) {
-		for (win = windows.tail; win; win = win->prev) {
-			if (!++num) break;
-		}
+		for (; win; win = win->prev) if (!num++) break;
 	} else {
-		for (win = windows.head; win; win = win->next) {
-			if (!num--) break;
-		}
+		for (; win; win = win->next) if (!num--) break;
 	}
-	if (win) windowShow(win);
+	if (!win) return;
+	windowShow(win);
 	uiStatus();
 	uiPrompt(false);
 }
@@ -470,7 +467,7 @@ static void keyChar(wchar_t ch) {
 	}
 	if (meta) {
 		meta = false;
-		if (ch >= L'0' && ch <= L'9') uiShowNum(ch - L'0');
+		if (ch >= L'0' && ch <= L'9') uiShowNum(ch - L'0', false);
 		if (!win) return;
 		switch (ch) {
 			break; case L'b':  edit(win->tag, EditBackWord, 0);
@@ -485,6 +482,9 @@ static void keyChar(wchar_t ch) {
 	if (ch == CTRL(L'L')) clearok(curscr, true);
 	if (!win) return;
 	switch (ch) {
+		break; case CTRL(L'N'): uiShowNum(+1, true);
+		break; case CTRL(L'P'): uiShowNum(-1, true);
+
 		break; case CTRL(L'A'): edit(win->tag, EditHome, 0);
 		break; case CTRL(L'B'): edit(win->tag, EditLeft, 0);
 		break; case CTRL(L'D'): edit(win->tag, EditDelete, 0);