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

13
chat.c
View File

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

1
chat.h
View File

@ -75,6 +75,7 @@ extern struct Self {
char *nick; char *nick;
char *user; char *user;
enum Color color; enum Color color;
char *quit;
} self; } self;
static inline void set(char **field, const char *value) { 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); commandPrivmsg(id, buf);
} }
static void commandQuit(size_t id, char *params) {
set(&self.quit, (params ? params : "Goodbye"));
}
static const struct Handler { static const struct Handler {
const char *cmd; const char *cmd;
Command *fn; Command *fn;
} Commands[] = { } Commands[] = {
{ "/me", commandMe }, { "/me", commandMe },
{ "/notice", commandNotice }, { "/notice", commandNotice },
{ "/quit", commandQuit },
{ "/quote", commandQuote }, { "/quote", commandQuote },
}; };