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

weechat-hashes
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 .Dt CATGIRL 1
.Os .Os
. .
@ -292,6 +292,10 @@ The color numbers are as follows:
.Bl -tag -width "PageDown" -compact .Bl -tag -width "PageDown" -compact
.It Ic C-l .It Ic C-l
Redraw the UI. 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 .It Ic M-m
Insert a blank line in the window. Insert a blank line in the window.
.It Ic M- Ns Ar n .It Ic M- Ns Ar n

2
chat.h
View File

@ -122,7 +122,7 @@ void uiExit(int status);
void uiPrompt(bool nickChanged); void uiPrompt(bool nickChanged);
void uiShowTag(struct Tag tag); void uiShowTag(struct Tag tag);
void uiShowNum(int num); void uiShowNum(int num, bool relative);
void uiCloseTag(struct Tag tag); void uiCloseTag(struct Tag tag);
enum UIHeat { 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"); uiLog(tag, UIHot, L"/window requires a name or number");
return; return;
} }
bool relative = (params[0] == '+' || params[0] == '-');
int num = strtol(params, &params, 0); int num = strtol(params, &params, 0);
if (!params[0]) { if (!params[0]) {
uiShowNum(num); uiShowNum(num, relative);
} else { } else {
struct Tag name = tagFind(params); struct Tag name = tagFind(params);
if (name.id != TagNone.id) { if (name.id != TagNone.id) {

20
ui.c
View File

@ -354,18 +354,15 @@ void uiShowTag(struct Tag tag) {
uiPrompt(false); uiPrompt(false);
} }
void uiShowNum(int num) { void uiShowNum(int num, bool relative) {
struct Window *win = NULL; struct Window *win = (relative ? windows.active : windows.head);
if (num < 0) { if (num < 0) {
for (win = windows.tail; win; win = win->prev) { for (; win; win = win->prev) if (!num++) break;
if (!++num) break;
}
} else { } else {
for (win = windows.head; win; win = win->next) { for (; win; win = win->next) if (!num--) break;
if (!num--) break;
} }
} if (!win) return;
if (win) windowShow(win); windowShow(win);
uiStatus(); uiStatus();
uiPrompt(false); uiPrompt(false);
} }
@ -470,7 +467,7 @@ static void keyChar(wchar_t ch) {
} }
if (meta) { if (meta) {
meta = false; 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; if (!win) return;
switch (ch) { switch (ch) {
break; case L'b': edit(win->tag, EditBackWord, 0); 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 (ch == CTRL(L'L')) clearok(curscr, true);
if (!win) return; if (!win) return;
switch (ch) { 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'A'): edit(win->tag, EditHome, 0);
break; case CTRL(L'B'): edit(win->tag, EditLeft, 0); break; case CTRL(L'B'): edit(win->tag, EditLeft, 0);
break; case CTRL(L'D'): edit(win->tag, EditDelete, 0); break; case CTRL(L'D'): edit(win->tag, EditDelete, 0);