Add /close

weechat-hashes
C. McEnroe 2020-02-08 02:26:00 -05:00
parent 55e721da42
commit 943502ea82
4 changed files with 44 additions and 0 deletions

View File

@ -146,6 +146,8 @@ Send a raw IRC command.
.
.Ss UI Commands
.Bl -tag -width Ds
.It Ic /close Op Ar name | num
Close the named, numbered or current window.
.It Ic /window Ar name
Switch to window by name.
.It Ic /window Ar num , Ic / Ns Ar num

2
chat.h
View File

@ -128,6 +128,8 @@ void uiHide(void);
void uiDraw(void);
void uiShowID(size_t id);
void uiShowNum(size_t num);
void uiCloseID(size_t id);
void uiCloseNum(size_t id);
void uiRead(void);
void uiWrite(size_t id, enum Heat heat, const time_t *time, const char *str);
void uiFormat(

View File

@ -100,10 +100,22 @@ static void commandWindow(size_t id, char *params) {
}
}
static void commandClose(size_t id, char *params) {
if (!params) {
uiCloseID(id);
} else if (isdigit(params[0])) {
uiCloseNum(strtoul(params, NULL, 10));
} else {
id = idFind(params);
if (id) uiCloseID(id);
}
}
static const struct Handler {
const char *cmd;
Command *fn;
} Commands[] = {
{ "/close", commandClose },
{ "/join", commandJoin },
{ "/me", commandMe },
{ "/nick", commandNick },

28
ui.c
View File

@ -573,6 +573,34 @@ void uiShowNum(size_t num) {
windowShow(window);
}
static void windowClose(struct Window *window) {
if (window->id == Network) return;
if (windows.active == window) {
windowShow(window->prev ? window->prev : window->next);
}
if (windows.other == window) windows.other = NULL;
windowRemove(window);
for (size_t i = 0; i < BufferCap; ++i) {
free(window->buffer.lines[i]);
}
delwin(window->pad);
free(window);
statusUpdate();
}
void uiCloseID(size_t id) {
windowClose(windowFor(id));
}
void uiCloseNum(size_t num) {
struct Window *window = windows.head;
for (size_t i = 0; i < num; ++i) {
window = window->next;
if (!window) return;
}
windowClose(window);
}
static void keyCode(int code) {
size_t id = windows.active->id;
switch (code) {