Colorize nicks and channels
parent
9e0bcb3805
commit
3b490562d4
56
chat.c
56
chat.c
|
@ -177,6 +177,16 @@ static void uiFmt(const char *format, ...) {
|
||||||
free(buf);
|
free(buf);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static int color(const char *s) {
|
||||||
|
if (!s) return 0;
|
||||||
|
int x = 0;
|
||||||
|
for (; s[0]; ++s) {
|
||||||
|
x ^= s[0];
|
||||||
|
}
|
||||||
|
x &= 15;
|
||||||
|
return (x == 1) ? 0 : x;
|
||||||
|
}
|
||||||
|
|
||||||
static struct {
|
static struct {
|
||||||
int sock;
|
int sock;
|
||||||
struct tls *tls;
|
struct tls *tls;
|
||||||
|
@ -233,19 +243,32 @@ static void handlePing(char *prefix, char *params) {
|
||||||
|
|
||||||
static void handleJoin(char *prefix, char *params) {
|
static void handleJoin(char *prefix, char *params) {
|
||||||
char *nick = prift(&prefix);
|
char *nick = prift(&prefix);
|
||||||
|
char *user = prift(&prefix);
|
||||||
char *chan = shift(¶ms);
|
char *chan = shift(¶ms);
|
||||||
uiFmt("--> %s arrived in %s", nick, chan);
|
uiFmt(
|
||||||
|
"\3%d%s\3 arrived in \3%d%s\3",
|
||||||
|
color(user), nick, color(chan), chan
|
||||||
|
);
|
||||||
}
|
}
|
||||||
static void handlePart(char *prefix, char *params) {
|
static void handlePart(char *prefix, char *params) {
|
||||||
char *nick = prift(&prefix);
|
char *nick = prift(&prefix);
|
||||||
|
char *user = prift(&prefix);
|
||||||
char *chan = shift(¶ms);
|
char *chan = shift(¶ms);
|
||||||
char *mesg = shift(¶ms);
|
char *mesg = shift(¶ms);
|
||||||
uiFmt("<-- %s left %s, \"%s\"", nick, chan, mesg);
|
uiFmt(
|
||||||
|
"\3%d%s\3 left \3%d%s\3, \"%s\"",
|
||||||
|
color(user), nick, color(chan), chan, mesg
|
||||||
|
);
|
||||||
}
|
}
|
||||||
static void handleQuit(char *prefix, char *params) {
|
static void handleQuit(char *prefix, char *params) {
|
||||||
char *nick = prift(&prefix);
|
char *nick = prift(&prefix);
|
||||||
|
char *user = prift(&prefix);
|
||||||
char *mesg = shift(¶ms);
|
char *mesg = shift(¶ms);
|
||||||
uiFmt("<-- %s left, \"%s\"", nick, mesg);
|
char *quot = (mesg[0] == '"') ? "" : "\"";
|
||||||
|
uiFmt(
|
||||||
|
"\3%d%s\3 left, %s%s%s",
|
||||||
|
color(user), nick, quot, mesg, quot
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void handle332(char *prefix, char *params) {
|
static void handle332(char *prefix, char *params) {
|
||||||
|
@ -253,14 +276,21 @@ static void handle332(char *prefix, char *params) {
|
||||||
shift(¶ms);
|
shift(¶ms);
|
||||||
char *chan = shift(¶ms);
|
char *chan = shift(¶ms);
|
||||||
char *topic = shift(¶ms);
|
char *topic = shift(¶ms);
|
||||||
uiFmt("--- The sign in %s reads, \"%s\"", chan, topic);
|
uiFmt(
|
||||||
|
"The sign in \3%d%s\3 reads, \"%s\"",
|
||||||
|
color(chan), chan, topic
|
||||||
|
);
|
||||||
uiTopic(topic);
|
uiTopic(topic);
|
||||||
}
|
}
|
||||||
static void handleTopic(char *prefix, char *params) {
|
static void handleTopic(char *prefix, char *params) {
|
||||||
char *nick = prift(&prefix);
|
char *nick = prift(&prefix);
|
||||||
|
char *user = prift(&prefix);
|
||||||
char *chan = shift(¶ms);
|
char *chan = shift(¶ms);
|
||||||
char *topic = shift(¶ms);
|
char *topic = shift(¶ms);
|
||||||
uiFmt("--- %s placed a new sign in %s, \"%s\"", nick, chan, topic);
|
uiFmt(
|
||||||
|
"\3%d%s\3 placed a new sign in \3%d%s\3, \"%s\"",
|
||||||
|
color(user), nick, color(chan), chan, topic
|
||||||
|
);
|
||||||
uiTopic(topic);
|
uiTopic(topic);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -270,21 +300,23 @@ static void handle353(char *prefix, char *params) {
|
||||||
shift(¶ms);
|
shift(¶ms);
|
||||||
char *chan = shift(¶ms);
|
char *chan = shift(¶ms);
|
||||||
char *names = shift(¶ms);
|
char *names = shift(¶ms);
|
||||||
// TODO: Clean up names (add commas, remove sigils)
|
// TODO: Do a WHO instead to get usernames
|
||||||
uiFmt("--- In %s are %s", chan, names);
|
uiFmt("In %s are %s", chan, names);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void handlePrivmsg(char *prefix, char *params) {
|
static void handlePrivmsg(char *prefix, char *params) {
|
||||||
char *nick = prift(&prefix);
|
char *nick = prift(&prefix);
|
||||||
|
char *user = prift(&prefix);
|
||||||
shift(¶ms);
|
shift(¶ms);
|
||||||
char *message = shift(¶ms);
|
char *mesg = shift(¶ms);
|
||||||
uiFmt("<%s> %s", nick, message);
|
uiFmt("<\3%d%s\3> %s", color(user), nick, mesg);
|
||||||
}
|
}
|
||||||
static void handleNotice(char *prefix, char *params) {
|
static void handleNotice(char *prefix, char *params) {
|
||||||
char *nick = prift(&prefix);
|
char *nick = prift(&prefix);
|
||||||
|
char *user = prift(&prefix);
|
||||||
shift(¶ms);
|
shift(¶ms);
|
||||||
char *message = shift(¶ms);
|
char *message = shift(¶ms);
|
||||||
uiFmt("-%s- %s", nick, message);
|
uiFmt("-\3%d%s\3- %s", color(user), nick, message);
|
||||||
}
|
}
|
||||||
|
|
||||||
static const struct {
|
static const struct {
|
||||||
|
@ -350,7 +382,7 @@ static void uiRead(void) {
|
||||||
asprintf(¶ms, "%s :%s", client.chan, buf);
|
asprintf(¶ms, "%s :%s", client.chan, buf);
|
||||||
if (!params) err(EX_OSERR, "asprintf");
|
if (!params) err(EX_OSERR, "asprintf");
|
||||||
clientFmt("PRIVMSG %s\r\n", params);
|
clientFmt("PRIVMSG %s\r\n", params);
|
||||||
handlePrivmsg(client.nick, params);
|
handlePrivmsg(client.nick, params); // FIXME: username
|
||||||
free(params);
|
free(params);
|
||||||
fill = 0;
|
fill = 0;
|
||||||
wmove(ui.input, 1, 0);
|
wmove(ui.input, 1, 0);
|
||||||
|
@ -411,7 +443,7 @@ int main(int argc, char *argv[]) {
|
||||||
erase();
|
erase();
|
||||||
|
|
||||||
uiInit();
|
uiInit();
|
||||||
uiChat("=== Traveling...");
|
uiChat("Traveling...");
|
||||||
uiDraw();
|
uiDraw();
|
||||||
|
|
||||||
struct tls_config *config = tls_config_new();
|
struct tls_config *config = tls_config_new();
|
||||||
|
|
Loading…
Reference in New Issue