Add C-n and C-p key bindings to switch windows

master
Curtis McEnroe 2019-02-23 12:24:39 -05:00
parent 740cb9f687
commit c06a457461
No known key found for this signature in database
GPG Key ID: CEA2F97ADCFCD77C
4 changed files with 18 additions and 13 deletions

View File

@ -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

2
chat.h
View File

@ -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 {

View File

@ -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, &params, 0);
if (!params[0]) {
uiShowNum(num);
uiShowNum(num, relative);
} else {
struct Tag name = tagFind(params);
if (name.id != TagNone.id) {

20
ui.c
View File

@ -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);