예제 #1
0
파일: prompt.c 프로젝트: h4ck3rm1k3/toxic
static void prompt_onInit(ToxWindow *self, Tox *m)
{
    curs_set(1);
    int y2, x2;
    getmaxyx(self->window, y2, x2);

    ChatContext *ctx = self->chatwin;
    ctx->history = subwin(self->window, y2 - CHATBOX_HEIGHT + 1, x2, 0, 0);
    ctx->linewin = subwin(self->window, CHATBOX_HEIGHT, x2, y2 - CHATBOX_HEIGHT, 0);

    ctx->log = calloc(1, sizeof(struct chatlog));
    ctx->hst = calloc(1, sizeof(struct history));

    if (ctx->log == NULL || ctx->hst == NULL)
        exit_toxic_err("failed in prompt_onInit", FATALERR_MEMORY);

    line_info_init(ctx->hst);

    if (user_settings->autolog == AUTOLOG_ON) {
        uint8_t myid[TOX_FRIEND_ADDRESS_SIZE];
        tox_get_address(m, myid);
        log_enable(self->name, myid, ctx->log);
    }

    scrollok(ctx->history, 0);
    wmove(self->window, y2 - CURS_Y_OFFSET, 0);

    print_welcome_msg(self);
}
예제 #2
0
파일: groupchat.c 프로젝트: subliun/toxic
static void groupchat_onInit(ToxWindow *self, Tox *m)
{
    int x2, y2;
    getmaxyx(self->window, y2, x2);

    if (x2 <= 0 || y2 <= 0)
        exit_toxic_err("failed in groupchat_onInit", FATALERR_CURSES);

    ChatContext *ctx = self->chatwin;

    ctx->history = subwin(self->window, y2 - CHATBOX_HEIGHT + 1, x2 - SIDEBAR_WIDTH - 1, 0, 0);
    ctx->linewin = subwin(self->window, CHATBOX_HEIGHT, x2, y2 - CHATBOX_HEIGHT, 0);
    ctx->sidebar = subwin(self->window, y2 - CHATBOX_HEIGHT + 1, SIDEBAR_WIDTH, 0, x2 - SIDEBAR_WIDTH);

    ctx->hst = calloc(1, sizeof(struct history));
    ctx->log = calloc(1, sizeof(struct chatlog));

    if (ctx->log == NULL || ctx->hst == NULL)
        exit_toxic_err("failed in groupchat_onInit", FATALERR_MEMORY);

    line_info_init(ctx->hst);

    if (user_settings->autolog == AUTOLOG_ON) {
        char myid[TOX_ADDRESS_SIZE];
        tox_self_get_address(m, (uint8_t *) myid);

        if (log_enable(self->name, myid, NULL, ctx->log, LOG_GROUP) == -1)
            line_info_add(self, NULL, NULL, NULL, SYS_MSG, 0, 0, "Warning: Log failed to initialize.");
    }

    execute(ctx->history, self, m, "/log", GLOBAL_COMMAND_MODE);

    scrollok(ctx->history, 0);
    wmove(self->window, y2 - CURS_Y_OFFSET, 0);
}
예제 #3
0
파일: prompt.c 프로젝트: Kuronogard/toxic
static void prompt_onInit(ToxWindow *self, Tox *m)
{
    ChatContext *ctx = self->chatwin;

    curs_set(1);
    int y2, x2;
    getmaxyx(self->window, y2, x2);

    ctx->history = subwin(self->window, y2, x2, 0, 0);
    scrollok(ctx->history, 1);

    ctx->log = malloc(sizeof(struct chatlog));
    ctx->hst = malloc(sizeof(struct history));

    if (ctx->log == NULL || ctx->hst == NULL) {
        endwin();
        fprintf(stderr, "malloc() failed. Aborting...\n");
        exit(EXIT_FAILURE);
    }

    memset(ctx->log, 0, sizeof(struct chatlog));
    memset(ctx->hst, 0, sizeof(struct history));

    line_info_init(ctx->hst);
    execute(ctx->history, self, m, "/help", GLOBAL_COMMAND_MODE);

    wmove(ctx->history, y2-1, 2);
}
예제 #4
0
파일: prompt.c 프로젝트: SmoothDude/toxic
static void prompt_onInit(ToxWindow *self, Tox *m)
{
    curs_set(1);
    int y2, x2;
    getmaxyx(self->window, y2, x2);

    ChatContext *ctx = self->chatwin;
    ctx->history = subwin(self->window, y2 - CHATBOX_HEIGHT + 1, x2, 0, 0);
    ctx->linewin = subwin(self->window, CHATBOX_HEIGHT, x2, y2 - CHATBOX_HEIGHT, 0);

    ctx->log = calloc(1, sizeof(struct chatlog));
    ctx->hst = calloc(1, sizeof(struct history));

    if (ctx->log == NULL || ctx->hst == NULL)
        exit_toxic_err("failed in prompt_onInit", FATALERR_MEMORY);

    line_info_init(ctx->hst);

    if (user_settings->autolog == AUTOLOG_ON) {
        char myid[TOX_ADDRESS_SIZE];
        tox_self_get_address(m, (uint8_t *) myid);

        if (log_enable(self->name, myid, NULL, ctx->log, LOG_PROMPT) == -1)
            line_info_add(self, NULL, NULL, NULL, SYS_MSG, 0, 0, "Warning: Log failed to initialize.");
    }

    scrollok(ctx->history, 0);
    wmove(self->window, y2 - CURS_Y_OFFSET, 0);

    if (user_settings->show_welcome_msg == SHOW_WELCOME_MSG_ON)
        print_welcome_msg(self);
}
예제 #5
0
파일: prompt.c 프로젝트: jin-eld/toxic
static void prompt_onInit(ToxWindow *self, Tox *m)
{
    ChatContext *ctx = self->chatwin;

    curs_set(1);
    int y2, x2;
    getmaxyx(self->window, y2, x2);

    ctx->history = subwin(self->window, y2, x2, 0, 0);
    scrollok(ctx->history, 1);

    ctx->log = malloc(sizeof(struct chatlog));
    ctx->hst = malloc(sizeof(struct history));

    if (ctx->log == NULL || ctx->hst == NULL) {
        endwin();
        fprintf(stderr, "malloc() failed. Aborting...\n");
        exit(EXIT_FAILURE);
    }

    memset(ctx->log, 0, sizeof(struct chatlog));
    memset(ctx->hst, 0, sizeof(struct history));

    line_info_init(ctx->hst);

    if (user_settings->autolog == AUTOLOG_ON) {
        uint8_t myid[TOX_FRIEND_ADDRESS_SIZE];
        tox_get_address(m, myid);
        log_enable(self->name, myid, ctx->log);
    }

    execute(ctx->history, self, m, "/help", GLOBAL_COMMAND_MODE);
    wmove(ctx->history, y2 - 1, 2);
}
예제 #6
0
파일: chat.c 프로젝트: prodigeni/toxic
static void chat_onInit(ToxWindow *self, Tox *m)
{
    curs_set(1);
    int x2, y2;
    getmaxyx(self->window, y2, x2);
    self->x = x2;

    /* Init statusbar info */
    StatusBar *statusbar = self->stb;

    statusbar->status = tox_get_user_status(m, self->num);
    statusbar->is_online = tox_get_friend_connection_status(m, self->num) == 1;

    char statusmsg[TOX_MAX_STATUSMESSAGE_LENGTH] = {'\0'};
    uint16_t s_len = tox_get_status_message(m, self->num, (uint8_t *) statusmsg, TOX_MAX_STATUSMESSAGE_LENGTH);
    statusmsg[s_len] = '\0';
    snprintf(statusbar->statusmsg, sizeof(statusbar->statusmsg), "%s", statusmsg);
    statusbar->statusmsg_len = s_len;

    char nick[TOX_MAX_NAME_LENGTH];
    int n_len = get_nick_truncate(m, nick, self->num);
    snprintf(statusbar->nick, sizeof(statusbar->nick), "%s", nick);
    statusbar->nick_len = n_len;

    /* Init subwindows */
    ChatContext *ctx = self->chatwin;

    statusbar->topline = subwin(self->window, 2, x2, 0, 0);
    ctx->history = subwin(self->window, y2 - CHATBOX_HEIGHT + 1, x2, 0, 0);
    ctx->linewin = subwin(self->window, CHATBOX_HEIGHT, x2, y2 - CHATBOX_HEIGHT, 0);

    ctx->hst = calloc(1, sizeof(struct history));
    ctx->log = calloc(1, sizeof(struct chatlog));

    if (ctx->log == NULL || ctx->hst == NULL)
        exit_toxic_err("failed in chat_onInit", FATALERR_MEMORY);

    line_info_init(ctx->hst);

    if (friends[self->num].logging_on)
        log_enable(nick, friends[self->num].pub_key, ctx->log);

    execute(ctx->history, self, m, "/log", GLOBAL_COMMAND_MODE);

    scrollok(ctx->history, 0);
    wmove(self->window, y2 - CURS_Y_OFFSET, 0);
}