Added gnu readline

This commit is contained in:
James Booth
2015-01-27 22:13:09 +00:00
parent 25d31101bf
commit 2cdbfc7eb7
14 changed files with 428 additions and 243 deletions

View File

@@ -43,6 +43,8 @@
#include <string.h>
#include <glib.h>
#include <readline/readline.h>
#include <readline/history.h>
#include "profanity.h"
#include "chat_session.h"
@@ -71,6 +73,20 @@ static void _create_directories(void);
static void _connect_default(const char * const account);
static gboolean idle = FALSE;
static void cb_linehandler(char *);
static gboolean cmd_result = TRUE;
static void
cb_linehandler(char *line)
{
/* Can use ^D (stty eof) or `exit' to exit. */
if (*line) {
add_history(line);
}
rl_redisplay();
cmd_result = cmd_process_input(line);
free(line);
}
void
prof_run(const int disable_tls, char *log_level, char *account_name)
@@ -79,26 +95,44 @@ prof_run(const int disable_tls, char *log_level, char *account_name)
_connect_default(account_name);
ui_update();
char *line = NULL;
gboolean cmd_result = TRUE;
fd_set fds;
int r;
rl_callback_handler_install(NULL, cb_linehandler);
log_info("Starting main event loop");
struct timeval t;
t.tv_sec = 0;
t.tv_usec = 10000;
while(cmd_result) {
while(!line) {
_check_autoaway();
line = ui_readline();
#ifdef HAVE_LIBOTR
otr_poll();
#endif
notify_remind();
jabber_process_events();
ui_update();
_check_autoaway();
FD_ZERO(&fds);
FD_SET(fileno (rl_instream), &fds);
r = select(FD_SETSIZE, &fds, NULL, NULL, &t);
if (r < 0) {
perror ("rltest: select");
rl_callback_handler_remove();
break;
}
cmd_result = cmd_process_input(line);
ui_input_clear();
FREE_SET_NULL(line);
if (FD_ISSET (fileno (rl_instream), &fds)) {
rl_callback_read_char();
ui_write(rl_line_buffer, rl_point);
}
// line = ui_readline();
#ifdef HAVE_LIBOTR
otr_poll();
#endif
notify_remind();
jabber_process_events();
ui_update();
}
rl_callback_handler_remove();
}
void