mirror of
https://github.com/Tha14/toxic.git
synced 2024-11-13 02:43:02 +01:00
put repeated code for printing time into a function
This commit is contained in:
parent
42d4c92971
commit
17aead45ed
24
src/chat.c
24
src/chat.c
@ -24,14 +24,11 @@ static void chat_onMessage(ToxWindow *self, Tox *m, int num, uint8_t *msg, uint1
|
||||
return;
|
||||
|
||||
ChatContext *ctx = (ChatContext *) self->chatwin;
|
||||
struct tm *timeinfo = get_time();
|
||||
|
||||
uint8_t nick[TOX_MAX_NAME_LENGTH] = {'\0'};
|
||||
tox_getname(m, num, nick);
|
||||
|
||||
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(CYAN));
|
||||
print_time(ctx->history);
|
||||
wattron(ctx->history, COLOR_PAIR(4));
|
||||
wprintw(ctx->history, "%s: ", nick);
|
||||
wattroff(ctx->history, COLOR_PAIR(4));
|
||||
@ -62,15 +59,11 @@ static void chat_onAction(ToxWindow *self, Tox *m, int num, uint8_t *action, uin
|
||||
return;
|
||||
|
||||
ChatContext *ctx = (ChatContext *) self->chatwin;
|
||||
struct tm *timeinfo = get_time();
|
||||
|
||||
uint8_t nick[TOX_MAX_NAME_LENGTH] = {'\0'};
|
||||
tox_getname(m, num, nick);
|
||||
|
||||
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(CYAN));
|
||||
|
||||
print_time(ctx->history);
|
||||
wattron(ctx->history, COLOR_PAIR(YELLOW));
|
||||
wprintw(ctx->history, "* %s %s\n", nick, action);
|
||||
wattroff(ctx->history, COLOR_PAIR(YELLOW));
|
||||
@ -202,20 +195,15 @@ static void print_chat_help(ChatContext *ctx)
|
||||
}
|
||||
|
||||
static void send_action(ToxWindow *self, ChatContext *ctx, Tox *m, uint8_t *action) {
|
||||
struct tm *timeinfo = get_time();
|
||||
|
||||
if (action == NULL) {
|
||||
wprintw(ctx->history, "Invalid syntax.\n");
|
||||
return;
|
||||
}
|
||||
|
||||
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(CYAN));
|
||||
|
||||
uint8_t selfname[TOX_MAX_NAME_LENGTH];
|
||||
tox_getselfname(m, selfname, TOX_MAX_NAME_LENGTH);
|
||||
|
||||
print_time(ctx->history);
|
||||
wattron(ctx->history, COLOR_PAIR(YELLOW));
|
||||
wprintw(ctx->history, "* %s %s\n", selfname, action);
|
||||
wattroff(ctx->history, COLOR_PAIR(YELLOW));
|
||||
@ -232,8 +220,6 @@ static void chat_onKey(ToxWindow *self, Tox *m, wint_t key)
|
||||
ChatContext *ctx = (ChatContext *) self->chatwin;
|
||||
StatusBar *statusbar = (StatusBar *) self->stb;
|
||||
|
||||
struct tm *timeinfo = get_time();
|
||||
|
||||
int x, y, y2, x2;
|
||||
getyx(self->window, y, x);
|
||||
getmaxyx(self->window, y2, x2);
|
||||
@ -287,9 +273,7 @@ static void chat_onKey(ToxWindow *self, Tox *m, wint_t key)
|
||||
uint8_t selfname[TOX_MAX_NAME_LENGTH];
|
||||
tox_getselfname(m, selfname, TOX_MAX_NAME_LENGTH);
|
||||
|
||||
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(CYAN));
|
||||
print_time(ctx->history);
|
||||
wattron(ctx->history, COLOR_PAIR(GREEN));
|
||||
wprintw(ctx->history, "%s: ", selfname);
|
||||
wattroff(ctx->history, COLOR_PAIR(GREEN));
|
||||
|
@ -100,15 +100,12 @@ static void groupchat_onGroupMessage(ToxWindow *self, Tox *m, int groupnum, int
|
||||
return;
|
||||
|
||||
ChatContext *ctx = (ChatContext *) self->chatwin;
|
||||
struct tm *timeinfo = get_time();
|
||||
|
||||
uint8_t nick[TOX_MAX_NAME_LENGTH] = {'\0'};
|
||||
tox_group_peername(m, groupnum, peernum, nick);
|
||||
nick[TOXIC_MAX_NAME_LENGTH] = '\0'; /* enforce client max name length */
|
||||
|
||||
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(CYAN));
|
||||
print_time(ctx->history);
|
||||
wattron(ctx->history, COLOR_PAIR(4));
|
||||
wprintw(ctx->history, "%s: ", nick);
|
||||
wattroff(ctx->history, COLOR_PAIR(4));
|
||||
@ -126,7 +123,6 @@ static void groupchat_onGroupMessage(ToxWindow *self, Tox *m, int groupnum, int
|
||||
static void groupchat_onKey(ToxWindow *self, Tox *m, wint_t key)
|
||||
{
|
||||
ChatContext *ctx = (ChatContext *) self->chatwin;
|
||||
struct tm *timeinfo = get_time();
|
||||
|
||||
int x, y, y2, x2;
|
||||
getyx(self->window, y, x);
|
||||
@ -181,9 +177,7 @@ static void groupchat_onKey(ToxWindow *self, Tox *m, wint_t key)
|
||||
// uint8_t selfname[TOX_MAX_NAME_LENGTH];
|
||||
// tox_getselfname(m, selfname, TOX_MAX_NAME_LENGTH);
|
||||
|
||||
// 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(CYAN));
|
||||
// print_time(ctx->history);
|
||||
// wattron(ctx->history, COLOR_PAIR(GREEN));
|
||||
// wprintw(ctx->history, "%s: ", selfname);
|
||||
// wattroff(ctx->history, COLOR_PAIR(GREEN));
|
||||
|
@ -95,3 +95,13 @@ char *wc_to_char(wchar_t ch)
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
/* Prints the time to given window */
|
||||
void print_time(WINDOW *window)
|
||||
{
|
||||
struct tm *timeinfo = get_time();
|
||||
|
||||
wattron(window, COLOR_PAIR(CYAN));
|
||||
wprintw(window, "[%02d:%02d:%02d] ", timeinfo->tm_hour, timeinfo->tm_min, timeinfo->tm_sec);
|
||||
wattroff(window, COLOR_PAIR(CYAN));
|
||||
}
|
@ -16,3 +16,6 @@ uint8_t *wcs_to_char(wchar_t *string);
|
||||
|
||||
/* convert a wide char to null terminated string */
|
||||
char *wc_to_char(wchar_t ch);
|
||||
|
||||
/* Prints the time to window w */
|
||||
void print_time(WINDOW *window);
|
||||
|
Loading…
Reference in New Issue
Block a user