Ejemplo n.º 1
0
void ui_read_line_n(char* buf, int n)
{
    int i;
    char current = NULL;
    char* tmp = malloc(2*sizeof(char));
    tmp[1]=NULL;
    for (i=0; i<n; i++) {
        current=ui_get_char();
        tmp[0]=current;
        ui_print(tmp);
        if(current=='\b' && i>0) {
            pthread_mutex_lock(&gUpdateMutex);
            i-=2;
            text_col-=2;
            text[text_row][text_col]='\0';
            update_screen_locked();
            pthread_mutex_unlock(&gUpdateMutex);
        }
        else if (current=='\n') {
            buf[i]=NULL;
            break;
        }
        else {
            buf[i]=current;
        }
    }
    buf[n]=NULL;
    return;
}
Ejemplo n.º 2
0
void
prof_run(const int disable_tls, char *log_level, char *account_name)
{
    _init(disable_tls, log_level);
    log_info("Starting main event loop");
    ui_input_nonblocking();
    GTimer *timer = g_timer_new();
    gboolean cmd_result = TRUE;
    jabber_conn_status_t conn_status = jabber_get_connection_status();

    char inp[INP_WIN_MAX];
    int size = 0;

    char *pref_connect_account = prefs_get_string(PREF_CONNECT_ACCOUNT);
    if (account_name != NULL) {
        char *cmd = "/connect";
        snprintf(inp, sizeof(inp), "%s %s", cmd, account_name);
        process_input(inp);
    } else if (pref_connect_account != NULL) {
        char *cmd = "/connect";
        snprintf(inp, sizeof(inp), "%s %s", cmd, pref_connect_account);
        process_input(inp);
    }
    prefs_free_string(pref_connect_account);
    ui_update();

    while(cmd_result == TRUE) {
        wint_t ch = ERR;
        int result;
        size = 0;

        while(ch != '\n') {
            conn_status = jabber_get_connection_status();
            if (conn_status == JABBER_CONNECTED) {
                _handle_idle_time();
            }

            gdouble elapsed = g_timer_elapsed(timer, NULL);

            gint remind_period = prefs_get_notify_remind();
            if (remind_period > 0 && elapsed >= remind_period) {
                notify_remind();
                g_timer_start(timer);
            }

            ui_handle_special_keys(&ch, result, inp, size);
#ifdef HAVE_LIBOTR
            otr_poll();
#endif
            jabber_process_events();
            ui_update();

            ch = ui_get_char(inp, &size, &result);
        }

        inp[size++] = '\0';
        cmd_result = process_input(inp);
    }

    g_timer_destroy(timer);
}