1
0
mirror of https://github.com/Tha14/toxic.git synced 2024-11-23 00:53:03 +01:00

define curses colours and replace magic numbers

This commit is contained in:
Jfreegman 2013-09-05 00:47:33 -04:00
parent f5695a4b3e
commit f7d96b0779
6 changed files with 79 additions and 69 deletions

View File

@ -55,9 +55,9 @@ static void chat_onMessage(ToxWindow *self, Tox *m, int num, uint8_t *msg, uint1
msg[len-1] = '\0';
nick[TOX_MAX_NAME_LENGTH-1] = '\0';
wattron(ctx->history, COLOR_PAIR(2));
wattron(ctx->history, COLOR_PAIR(CYAN));
wprintw(ctx->history, "[%02d:%02d:%02d] ", timeinfo->tm_hour, timeinfo->tm_min, timeinfo->tm_sec);
wattroff(ctx->history, COLOR_PAIR(2));
wattroff(ctx->history, COLOR_PAIR(CYAN));
wattron(ctx->history, COLOR_PAIR(4));
wprintw(ctx->history, "%s: ", nick);
wattroff(ctx->history, COLOR_PAIR(4));
@ -75,9 +75,9 @@ void chat_onConnectionChange(ToxWindow *self, Tox *m, int num, uint8_t status)
if (ctx->friendnum != num)
return;
wattron(ctx->history, COLOR_PAIR(2));
wattron(ctx->history, COLOR_PAIR(CYAN));
wprintw(ctx->history, "[%02d:%02d:%02d] ", timeinfo->tm_hour, timeinfo->tm_min, timeinfo->tm_sec);
wattroff(ctx->history, COLOR_PAIR(2));
wattroff(ctx->history, COLOR_PAIR(CYAN));
if (status == 1)
wprintw(ctx->history, "* Chat partner has come online\n");
@ -98,13 +98,13 @@ static void chat_onAction(ToxWindow *self, Tox *m, int num, uint8_t *action, uin
action[len - 1] = '\0';
wattron(ctx->history, COLOR_PAIR(2));
wattron(ctx->history, COLOR_PAIR(CYAN));
wprintw(ctx->history, "[%02d:%02d:%02d] ", timeinfo->tm_hour, timeinfo->tm_min, timeinfo->tm_sec);
wattroff(ctx->history, COLOR_PAIR(2));
wattroff(ctx->history, COLOR_PAIR(CYAN));
wattron(ctx->history, COLOR_PAIR(5));
wattron(ctx->history, COLOR_PAIR(YELLOW));
wprintw(ctx->history, "* %s %s\n", nick, action);
wattroff(ctx->history, COLOR_PAIR(5));
wattroff(ctx->history, COLOR_PAIR(YELLOW));
self->blink = true;
beep();
@ -118,9 +118,9 @@ static void chat_onNickChange(ToxWindow *self, int num, uint8_t *nick, uint16_t
if (ctx->friendnum != num)
return;
wattron(ctx->history, COLOR_PAIR(2));
wattron(ctx->history, COLOR_PAIR(CYAN));
wprintw(ctx->history, "[%02d:%02d:%02d] ", timeinfo->tm_hour, timeinfo->tm_min, timeinfo->tm_sec);
wattroff(ctx->history, COLOR_PAIR(2));
wattroff(ctx->history, COLOR_PAIR(CYAN));
nick[len - 1] = '\0';
snprintf(self->title, sizeof(self->title), "[%s]", nick);
@ -136,31 +136,31 @@ static void chat_onStatusChange(ToxWindow *self, Tox *m, int num, TOX_USERSTATUS
if (ctx->friendnum != num)
return;
wattron(ctx->history, COLOR_PAIR(2));
wattron(ctx->history, COLOR_PAIR(CYAN));
wprintw(ctx->history, "[%02d:%02d:%02d] ", timeinfo->tm_hour, timeinfo->tm_min, timeinfo->tm_sec);
wattroff(ctx->history, COLOR_PAIR(2));
wattroff(ctx->history, COLOR_PAIR(CYAN));
switch(status) {
case TOX_USERSTATUS_NONE:
wprintw(ctx->history, "* Chat partner set status to ");
wattron(ctx->history, COLOR_PAIR(1));
wattron(ctx->history, COLOR_PAIR(GREEN));
wprintw(ctx->history, "[Online]\n");
wattroff(ctx->history, COLOR_PAIR(1));
wattroff(ctx->history, COLOR_PAIR(GREEN));
break;
case TOX_USERSTATUS_BUSY:
wprintw(ctx->history, "* Chat partner set status to ");
wattron(ctx->history, COLOR_PAIR(3));
wattron(ctx->history, COLOR_PAIR(RED));
wprintw(ctx->history, "[Busy]\n");
wattroff(ctx->history, COLOR_PAIR(3));
wattroff(ctx->history, COLOR_PAIR(RED));
break;
case TOX_USERSTATUS_AWAY:
wprintw(ctx->history, "* Chat partner set status to ");
wattron(ctx->history, COLOR_PAIR(5));
wattron(ctx->history, COLOR_PAIR(YELLOW));
wprintw(ctx->history, "[Away]\n");
wattroff(ctx->history, COLOR_PAIR(5));
wattroff(ctx->history, COLOR_PAIR(YELLOW));
break;
}
}
@ -176,9 +176,9 @@ static void chat_onStatusMessageChange(ToxWindow *self, int num, uint8_t *status
status[len - 1] = '\0';
if (strncmp(status, "Online", strlen("status"))) { /* Ignore default "Online" message */
wattron(ctx->history, COLOR_PAIR(2));
wattron(ctx->history, COLOR_PAIR(CYAN));
wprintw(ctx->history, "[%02d:%02d:%02d] ", timeinfo->tm_hour, timeinfo->tm_min, timeinfo->tm_sec);
wattroff(ctx->history, COLOR_PAIR(2));
wattroff(ctx->history, COLOR_PAIR(CYAN));
wprintw(ctx->history, "* Chat partner changed personal note to: %s\n", status);
}
}
@ -286,18 +286,18 @@ static void chat_onKey(ToxWindow *self, Tox *m, wint_t key)
uint8_t selfname[TOX_MAX_NAME_LENGTH];
tox_getselfname(m, selfname, sizeof(selfname));
wattron(ctx->history, COLOR_PAIR(2));
wattron(ctx->history, COLOR_PAIR(CYAN));
wprintw(ctx->history, "[%02d:%02d:%02d] ", timeinfo->tm_hour, timeinfo->tm_min, timeinfo->tm_sec);
wattroff(ctx->history, COLOR_PAIR(2));
wattron(ctx->history, COLOR_PAIR(1));
wattroff(ctx->history, COLOR_PAIR(CYAN));
wattron(ctx->history, COLOR_PAIR(GREEN));
wprintw(ctx->history, "%s: ", selfname);
wattroff(ctx->history, COLOR_PAIR(1));
wattroff(ctx->history, COLOR_PAIR(GREEN));
wprintw(ctx->history, "%s\n", line);
if (tox_sendmessage(m, ctx->friendnum, (uint8_t *) line, strlen(line) + 1) == 0) {
wattron(ctx->history, COLOR_PAIR(3));
wattron(ctx->history, COLOR_PAIR(RED));
wprintw(ctx->history, " * Failed to send message.\n");
wattroff(ctx->history, COLOR_PAIR(3));
wattroff(ctx->history, COLOR_PAIR(RED));
}
}
}
@ -345,21 +345,21 @@ void execute(ToxWindow *self, ChatContext *ctx, Tox *m, char *cmd)
action++;
wattron(ctx->history, COLOR_PAIR(2));
wattron(ctx->history, COLOR_PAIR(CYAN));
wprintw(ctx->history, "[%02d:%02d:%02d] ", timeinfo->tm_hour, timeinfo->tm_min, timeinfo->tm_sec);
wattroff(ctx->history, COLOR_PAIR(2));
wattroff(ctx->history, COLOR_PAIR(CYAN));
uint8_t selfname[TOX_MAX_NAME_LENGTH];
tox_getselfname(m, selfname, sizeof(selfname));
wattron(ctx->history, COLOR_PAIR(5));
wattron(ctx->history, COLOR_PAIR(YELLOW));
wprintw(ctx->history, "* %s %s\n", selfname, action);
wattroff(ctx->history, COLOR_PAIR(5));
wattroff(ctx->history, COLOR_PAIR(YELLOW));
if (tox_sendaction(m, ctx->friendnum, (uint8_t *) action, strlen(action) + 1) == 0) {
wattron(ctx->history, COLOR_PAIR(3));
wattron(ctx->history, COLOR_PAIR(RED));
wprintw(ctx->history, " * Failed to send action\n");
wattroff(ctx->history, COLOR_PAIR(3));
wattroff(ctx->history, COLOR_PAIR(RED));
}
}
@ -379,25 +379,25 @@ void execute(ToxWindow *self, ChatContext *ctx, Tox *m, char *cmd)
if (!strncmp(status, "online", strlen("online"))) {
status_kind = TOX_USERSTATUS_NONE;
wprintw(ctx->history, "Status set to ");
wattron(ctx->history, COLOR_PAIR(1));
wattron(ctx->history, COLOR_PAIR(GREEN));
wprintw(ctx->history, "[Online]\n");
wattroff(ctx->history, COLOR_PAIR(1));
wattroff(ctx->history, COLOR_PAIR(GREEN));
}
else if (!strncmp(status, "away", strlen("away"))) {
status_kind = TOX_USERSTATUS_AWAY;
wprintw(ctx->history, "Status set to ");
wattron(ctx->history, COLOR_PAIR(5));
wattron(ctx->history, COLOR_PAIR(YELLOW));
wprintw(ctx->history, "[Away]\n");
wattroff(ctx->history, COLOR_PAIR(5));
wattroff(ctx->history, COLOR_PAIR(YELLOW));
}
else if (!strncmp(status, "busy", strlen("busy"))) {
status_kind = TOX_USERSTATUS_BUSY;
wprintw(ctx->history, "Status set to ");
wattron(ctx->history, COLOR_PAIR(3));
wattron(ctx->history, COLOR_PAIR(RED));
wprintw(ctx->history, "[Busy]\n");
wattroff(ctx->history, COLOR_PAIR(3));
wattroff(ctx->history, COLOR_PAIR(RED));
}
else {
@ -480,7 +480,7 @@ static void chat_onInit(ToxWindow *self, Tox *m)
void print_help(ChatContext *self)
{
wattron(self->history, COLOR_PAIR(2) | A_BOLD);
wattron(self->history, COLOR_PAIR(CYAN) | A_BOLD);
wprintw(self->history, "Commands:\n");
wattroff(self->history, A_BOLD);
@ -494,7 +494,7 @@ void print_help(ChatContext *self)
wprintw(self->history, " /quit or /exit : Exit Toxic\n");
wprintw(self->history, " /help : Print this message again\n\n");
wattroff(self->history, COLOR_PAIR(2));
wattroff(self->history, COLOR_PAIR(CYAN));
}
ToxWindow new_chat(Tox *m, int friendnum)

View File

@ -180,10 +180,10 @@ static void friendlist_onDraw(ToxWindow *self, Tox *m)
if (num_friends == 0) {
wprintw(self->window, "Empty. Add some friends! :-)\n");
} else {
wattron(self->window, COLOR_PAIR(2) | A_BOLD);
wattron(self->window, COLOR_PAIR(CYAN) | A_BOLD);
wprintw(self->window, " Open chat with up/down keys and enter.\n");
wprintw(self->window, " Delete friends with the backspace key.\n\n");
wattroff(self->window, COLOR_PAIR(2) | A_BOLD);
wattroff(self->window, COLOR_PAIR(CYAN) | A_BOLD);
}
int i;
@ -197,17 +197,17 @@ static void friendlist_onDraw(ToxWindow *self, Tox *m)
if (friends[i].online) {
TOX_USERSTATUS status = friends[i].status;
int colour = 7; /* Invalid or other errors default to black */
int colour = WHITE;
switch(status) {
case TOX_USERSTATUS_NONE:
colour = 1;
colour = GREEN;
break;
case TOX_USERSTATUS_AWAY:
colour = 5;
colour = YELLOW;
break;
case TOX_USERSTATUS_BUSY:
colour = 3;
colour = RED;
break;
}

View File

@ -71,6 +71,7 @@ static void init_term()
if (has_colors()) {
start_color();
init_pair(0, COLOR_WHITE, COLOR_BLACK);
init_pair(1, COLOR_GREEN, COLOR_BLACK);
init_pair(2, COLOR_CYAN, COLOR_BLACK);
init_pair(3, COLOR_RED, COLOR_BLACK);
@ -79,7 +80,6 @@ static void init_term()
init_pair(6, COLOR_MAGENTA, COLOR_BLACK);
init_pair(7, COLOR_BLACK, COLOR_BLACK);
init_pair(8, COLOR_BLACK, COLOR_WHITE);
}
refresh();
@ -398,17 +398,17 @@ int main(int argc, char *argv[])
load_data(m, DATA_FILE);
if (f_flag == -1) {
attron(COLOR_PAIR(3) | A_BOLD);
attron(COLOR_PAIR(RED) | A_BOLD);
wprintw(prompt->window, "You passed '-f' without giving an argument.\n"
"defaulting to 'data' for a keyfile...\n");
attroff(COLOR_PAIR(3) | A_BOLD);
attroff(COLOR_PAIR(RED) | A_BOLD);
}
if (config_err) {
attron(COLOR_PAIR(3) | A_BOLD);
attron(COLOR_PAIR(RED) | A_BOLD);
wprintw(prompt->window, "Unable to determine configuration directory.\n"
"defaulting to 'data' for a keyfile...\n");
attroff(COLOR_PAIR(3) | A_BOLD);
attroff(COLOR_PAIR(RED) | A_BOLD);
}
while (true) {

View File

@ -243,7 +243,7 @@ void cmd_quit(ToxWindow *self, Tox *m, int argc, char **argv)
void cmd_help(ToxWindow *self, Tox *m, int argc, char **argv)
{
wclear(self->window);
wattron(self->window, COLOR_PAIR(2) | A_BOLD);
wattron(self->window, COLOR_PAIR(CYAN) | A_BOLD);
wprintw(self->window, "Commands:\n");
wattroff(self->window, A_BOLD);
@ -264,7 +264,7 @@ void cmd_help(ToxWindow *self, Tox *m, int argc, char **argv)
wprintw(self->window, " * Use the TAB key to navigate through the tabs.\n\n");
wattroff(self->window, A_BOLD);
wattroff(self->window, COLOR_PAIR(2));
wattroff(self->window, COLOR_PAIR(CYAN));
}
void cmd_msg(ToxWindow *self, Tox *m, int argc, char **argv)
@ -530,9 +530,9 @@ static void prompt_onDraw(ToxWindow *self, Tox *m)
--y;
}
wattron(self->window, COLOR_PAIR(1));
wattron(self->window, COLOR_PAIR(GREEN));
mvwprintw(self->window, y, 0, "# ");
wattroff(self->window, COLOR_PAIR(1));
wattroff(self->window, COLOR_PAIR(GREEN));
mvwprintw(self->window, y, 2, "%s", prompt_buf);
wclrtoeol(self->window);
wrefresh(self->window);

View File

@ -24,6 +24,16 @@
#define TOXICVER "NOVER" //Use the -D flag to set this
#endif
/* Curses foreground colours (background is black) */
#define WHITE 0
#define GREEN 1
#define CYAN 2
#define RED 3
#define BLUE 4
#define YELLOW 5
#define MAGENTA 6
#define BLACK 7
typedef struct ToxWindow_ ToxWindow;
struct ToxWindow_ {

View File

@ -17,7 +17,7 @@ static ToxWindow *active_window;
static ToxWindow *prompt;
static Tox *m;
#define unknown_name "Unknown"
#define UNKNOWN_NAME "Unknown"
/* CALLBACKS START */
void on_request(uint8_t *public_key, uint8_t *data, uint16_t length, void *userdata)
@ -46,7 +46,7 @@ void on_connectionchange(Tox *m, int friendnumber, uint8_t status, void *userdat
tox_getname(m, friendnumber, (uint8_t *) &nick);
if (!nick[0])
snprintf(nick, sizeof(nick), "%s", unknown_name);
snprintf(nick, sizeof(nick), "%s", UNKNOWN_NAME);
if (status == 1)
wprintw(prompt->window, "\n%s has come online\n", nick, friendnumber);
@ -99,7 +99,7 @@ void on_statusmessagechange(Tox *m, int friendnumber, uint8_t *string, uint16_t
tox_getname(m, friendnumber, (uint8_t *) &nick);
if (!nick[0])
snprintf(nick, sizeof(nick), "%s", unknown_name);
snprintf(nick, sizeof(nick), "%s", UNKNOWN_NAME);
wprintw(prompt->window, "\n%s set note to: %s\n", nick, string);
}
@ -118,7 +118,7 @@ void on_statuschange(Tox *m, int friendnumber, TOX_USERSTATUS status, void *user
tox_getname(m, friendnumber, (uint8_t *) &nick);
if (!nick[0])
snprintf(nick, sizeof(nick), "%s", unknown_name);
snprintf(nick, sizeof(nick), "%s", UNKNOWN_NAME);
switch(status) {
case TOX_USERSTATUS_NONE:
@ -127,16 +127,16 @@ void on_statuschange(Tox *m, int friendnumber, TOX_USERSTATUS status, void *user
case TOX_USERSTATUS_BUSY:
wprintw(prompt->window, "\n%s set status to ", nick);
wattron(prompt->window, COLOR_PAIR(3));
wattron(prompt->window, COLOR_PAIR(RED));
wprintw(prompt->window, "[Busy]\n");
wattroff(prompt->window, COLOR_PAIR(3));
wattroff(prompt->window, COLOR_PAIR(RED));
break;
case TOX_USERSTATUS_AWAY:
wprintw(prompt->window, "\n%s set status to ", nick);
wattron(prompt->window, COLOR_PAIR(5));
wattron(prompt->window, COLOR_PAIR(YELLOW));
wprintw(prompt->window, "[Away]\n");
wattroff(prompt->window, COLOR_PAIR(5));
wattroff(prompt->window, COLOR_PAIR(YELLOW));
break;
}
@ -247,15 +247,15 @@ static void draw_bar()
static int odd = 0;
int blinkrate = 30;
attron(COLOR_PAIR(4));
attron(COLOR_PAIR(BLUE));
mvhline(LINES - 2, 0, '_', COLS);
attroff(COLOR_PAIR(4));
attroff(COLOR_PAIR(BLUE));
move(LINES - 1, 0);
attron(COLOR_PAIR(4) | A_BOLD);
attron(COLOR_PAIR(BLUE) | A_BOLD);
printw(" TOXIC " TOXICVER " |");
attroff(COLOR_PAIR(4) | A_BOLD);
attroff(COLOR_PAIR(BLUE) | A_BOLD);
int i;
@ -267,13 +267,13 @@ static void draw_bar()
odd = (odd + 1) % blinkrate;
if (windows[i].blink && (odd < (blinkrate / 2)))
attron(COLOR_PAIR(3));
attron(COLOR_PAIR(RED));
clrtoeol();
printw(" %s", windows[i].title);
if (windows[i].blink && (odd < (blinkrate / 2)))
attroff(COLOR_PAIR(3));
attroff(COLOR_PAIR(RED));
if (windows + i == active_window) {
attroff(A_BOLD);