Add /move command

weechat-hashes
Curtis McEnroe 2019-02-27 00:17:59 -05:00
parent adc6d3bdd2
commit d8cffb8ae7
No known key found for this signature in database
GPG Key ID: CEA2F97ADCFCD77C
4 changed files with 52 additions and 8 deletions

View File

@ -162,6 +162,16 @@ Close the current window.
.It Ic /help , /man .It Ic /help , /man
View this manual. View this manual.
. .
.It Ic /move Ar num
Move window to number.
If
.Ar num
starts with
.Cm +
or
.Cm - ,
the number is relative to the current window.
.
.It Ic /open Op Ar range .It Ic /open Op Ar range
Open a Open a
.Ar range .Ar range

1
chat.h
View File

@ -126,6 +126,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, bool relative); void uiShowNum(int num, bool relative);
void uiMoveTag(struct Tag tag, int num, bool relative);
void uiCloseTag(struct Tag tag); void uiCloseTag(struct Tag tag);
enum UIHeat { enum UIHeat {

10
input.c
View File

@ -117,6 +117,15 @@ static void inputMan(struct Tag tag, char *params) {
eventWait((const char *[]) { "man", "1", "catgirl", NULL }); eventWait((const char *[]) { "man", "1", "catgirl", NULL });
} }
static void inputMove(struct Tag tag, char *params) {
char *num = strsep(&params, " ");
if (num) {
uiMoveTag(tag, strtol(num, NULL, 0), num[0] == '+' || num[0] == '-');
} else {
uiLog(tag, UIHot, L"/move requires a number");
}
}
static void inputOpen(struct Tag tag, char *params) { static void inputOpen(struct Tag tag, char *params) {
if (params && !isdigit(params[0])) { if (params && !isdigit(params[0])) {
urlOpenMatch(tag, params); urlOpenMatch(tag, params);
@ -174,6 +183,7 @@ static const struct {
{ "/join", inputJoin }, { "/join", inputJoin },
{ "/man", inputMan }, { "/man", inputMan },
{ "/me", inputMe }, { "/me", inputMe },
{ "/move", inputMove },
{ "/names", inputWho }, { "/names", inputWho },
{ "/nick", inputNick }, { "/nick", inputNick },
{ "/open", inputOpen }, { "/open", inputOpen },

39
ui.c
View File

@ -76,6 +76,15 @@ static void windowAppend(struct Window *win) {
windows.tag[win->tag.id] = win; windows.tag[win->tag.id] = win;
} }
static void windowInsert(struct Window *win, struct Window *next) {
win->prev = next->prev;
win->next = next;
if (win->prev) win->prev->next = win;
win->next->prev = win;
if (!win->prev) windows.head = win;
windows.tag[win->tag.id] = win;
}
static void windowRemove(struct Window *win) { static void windowRemove(struct Window *win) {
windows.tag[win->tag.id] = NULL; windows.tag[win->tag.id] = NULL;
if (win->prev) win->prev->next = win->next; if (win->prev) win->prev->next = win->next;
@ -365,6 +374,17 @@ void uiShowTag(struct Tag tag) {
uiShowWindow(windowFor(tag)); uiShowWindow(windowFor(tag));
} }
static void uiShowAuto(void) {
struct Window *unread = NULL;
struct Window *hot;
for (hot = windows.head; hot; hot = hot->next) {
if (hot->hot) break;
if (!unread && hot->unread) unread = hot;
}
if (!hot && !unread) return;
uiShowWindow(hot ? hot : unread);
}
void uiShowNum(int num, bool relative) { void uiShowNum(int num, bool relative) {
struct Window *win = (relative ? windows.active : windows.head); struct Window *win = (relative ? windows.active : windows.head);
if (num < 0) { if (num < 0) {
@ -375,15 +395,18 @@ void uiShowNum(int num, bool relative) {
if (win) uiShowWindow(win); if (win) uiShowWindow(win);
} }
static void uiShowAuto(void) { void uiMoveTag(struct Tag tag, int num, bool relative) {
struct Window *unread = NULL; struct Window *win = windowFor(tag);
struct Window *hot; windowRemove(win);
for (hot = windows.head; hot; hot = hot->next) { struct Window *ins = (relative ? win : windows.head);
if (hot->hot) break; if (num < 0) {
if (!unread && hot->unread) unread = hot; for (; ins; ins = ins->prev) if (!num++) break;
} else {
if (relative) ins = ins->next;
for (; ins; ins = ins->next) if (!num--) break;
} }
if (!hot && !unread) return; ins ? windowInsert(win, ins) : windowAppend(win);
uiShowWindow(hot ? hot : unread); uiStatus();
} }
void uiCloseTag(struct Tag tag) { void uiCloseTag(struct Tag tag) {