Add /quit
parent
7c0b60221b
commit
7c0e9cf3d2
11
chat.c
11
chat.c
|
@ -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
1
chat.h
|
@ -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) {
|
||||
|
|
|
@ -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 },
|
||||
};
|
||||
|
||||
|
|
Loading…
Reference in New Issue