Add /quit

weechat-hashes
C. McEnroe 2020-02-05 21:57:23 -05:00
parent 7c0b60221b
commit 7c0e9cf3d2
3 changed files with 14 additions and 5 deletions

11
chat.c
View File

@ -115,13 +115,12 @@ int main(int argc, char *argv[]) {
{ .events = POLLIN, .fd = STDIN_FILENO },
{ .events = POLLIN, .fd = irc },
};
for (;;) {
while (!self.quit) {
int nfds = poll(fds, 2, -1);
if (nfds < 0 && errno != EINTR) err(EX_IOERR, "poll");
if (signals[SIGHUP] || signals[SIGINT] || signals[SIGTERM]) {
break;
}
if (signals[SIGHUP]) self.quit = "zzz";
if (signals[SIGINT] || signals[SIGTERM]) break;
if (signals[SIGWINCH]) {
signals[SIGWINCH] = 0;
cursesWinch(SIGWINCH);
@ -136,6 +135,10 @@ int main(int argc, char *argv[]) {
uiDraw();
}
if (self.quit) {
ircFormat("QUIT :%s\r\n", self.quit);
} else {
ircFormat("QUIT\r\n");
}
uiHide();
}

1
chat.h
View File

@ -75,6 +75,7 @@ extern struct Self {
char *nick;
char *user;
enum Color color;
char *quit;
} self;
static inline void set(char **field, const char *value) {

View File

@ -56,12 +56,17 @@ static void commandMe(size_t id, char *params) {
commandPrivmsg(id, buf);
}
static void commandQuit(size_t id, char *params) {
set(&self.quit, (params ? params : "Goodbye"));
}
static const struct Handler {
const char *cmd;
Command *fn;
} Commands[] = {
{ "/me", commandMe },
{ "/notice", commandNotice },
{ "/quit", commandQuit },
{ "/quote", commandQuote },
};