From c06a45746117786f687ded1c62047e9194107e96 Mon Sep 17 00:00:00 2001 From: Curtis McEnroe Date: Sat, 23 Feb 2019 12:24:39 -0500 Subject: [PATCH] Add C-n and C-p key bindings to switch windows --- catgirl.1 | 6 +++++- chat.h | 2 +- input.c | 3 ++- ui.c | 20 ++++++++++---------- 4 files changed, 18 insertions(+), 13 deletions(-) diff --git a/catgirl.1 b/catgirl.1 index 8927480..2f2bcbb 100644 --- a/catgirl.1 +++ b/catgirl.1 @@ -1,4 +1,4 @@ -.Dd February 22, 2019 +.Dd February 23, 2019 .Dt CATGIRL 1 .Os . @@ -292,6 +292,10 @@ The color numbers are as follows: .Bl -tag -width "PageDown" -compact .It Ic C-l Redraw the UI. +.It Ic C-n +Switch to the next window. +.It Ic C-p +Swittch to the previous window. .It Ic M-m Insert a blank line in the window. .It Ic M- Ns Ar n diff --git a/chat.h b/chat.h index afb32ef..452470d 100644 --- a/chat.h +++ b/chat.h @@ -122,7 +122,7 @@ void uiExit(int status); void uiPrompt(bool nickChanged); void uiShowTag(struct Tag tag); -void uiShowNum(int num); +void uiShowNum(int num, bool relative); void uiCloseTag(struct Tag tag); enum UIHeat { diff --git a/input.c b/input.c index 7c2ffef..dee50f2 100644 --- a/input.c +++ b/input.c @@ -146,9 +146,10 @@ static void inputWindow(struct Tag tag, char *params) { uiLog(tag, UIHot, L"/window requires a name or number"); return; } + bool relative = (params[0] == '+' || params[0] == '-'); int num = strtol(params, ¶ms, 0); if (!params[0]) { - uiShowNum(num); + uiShowNum(num, relative); } else { struct Tag name = tagFind(params); if (name.id != TagNone.id) { 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);