mirror of
https://github.com/profanity-im/profanity.git
synced 2025-02-02 15:08:15 -05:00
Moved command processing to main loop, allow resize during password prompt
This commit is contained in:
parent
30180ac8bb
commit
a70aa0255f
@ -82,10 +82,18 @@ prof_run(const int disable_tls, char *log_level, char *account_name)
|
|||||||
|
|
||||||
log_info("Starting main event loop");
|
log_info("Starting main event loop");
|
||||||
|
|
||||||
|
char *line = NULL;
|
||||||
while(cont) {
|
while(cont) {
|
||||||
_check_autoaway();
|
_check_autoaway();
|
||||||
|
|
||||||
cont = ui_readline();
|
line = ui_readline();
|
||||||
|
if (line) {
|
||||||
|
cont = cmd_process_input(line);
|
||||||
|
free(line);
|
||||||
|
line = NULL;
|
||||||
|
} else {
|
||||||
|
cont = TRUE;
|
||||||
|
}
|
||||||
|
|
||||||
#ifdef HAVE_LIBOTR
|
#ifdef HAVE_LIBOTR
|
||||||
otr_poll();
|
otr_poll();
|
||||||
|
@ -198,7 +198,7 @@ ui_close(void)
|
|||||||
endwin();
|
endwin();
|
||||||
}
|
}
|
||||||
|
|
||||||
gboolean
|
char *
|
||||||
ui_readline(void)
|
ui_readline(void)
|
||||||
{
|
{
|
||||||
return inp_readline();
|
return inp_readline();
|
||||||
@ -2249,15 +2249,9 @@ ui_win_unread(int index)
|
|||||||
char *
|
char *
|
||||||
ui_ask_password(void)
|
ui_ask_password(void)
|
||||||
{
|
{
|
||||||
char *passwd = malloc(sizeof(char) * (MAX_PASSWORD_SIZE + 1));
|
|
||||||
status_bar_get_password();
|
status_bar_get_password();
|
||||||
status_bar_update_virtual();
|
status_bar_update_virtual();
|
||||||
inp_block();
|
return inp_get_password();
|
||||||
inp_get_password(passwd);
|
|
||||||
// inp_non_block(prefs_get_inpblock());
|
|
||||||
inp_nonblocking(TRUE);
|
|
||||||
|
|
||||||
return passwd;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
|
@ -74,7 +74,8 @@ static gint no_input_count = 0;
|
|||||||
|
|
||||||
static fd_set fds;
|
static fd_set fds;
|
||||||
static int r;
|
static int r;
|
||||||
static gboolean cmd_result = TRUE;
|
static char *inp_line = NULL;
|
||||||
|
static gboolean get_password = FALSE;
|
||||||
|
|
||||||
static void _inp_win_update_virtual(void);
|
static void _inp_win_update_virtual(void);
|
||||||
static int _inp_printable(const wint_t ch);
|
static int _inp_printable(const wint_t ch);
|
||||||
@ -132,9 +133,11 @@ create_input_window(void)
|
|||||||
_inp_win_update_virtual();
|
_inp_win_update_virtual();
|
||||||
}
|
}
|
||||||
|
|
||||||
gboolean
|
char *
|
||||||
inp_readline(void)
|
inp_readline(void)
|
||||||
{
|
{
|
||||||
|
free(inp_line);
|
||||||
|
inp_line = NULL;
|
||||||
FD_ZERO(&fds);
|
FD_ZERO(&fds);
|
||||||
FD_SET(fileno(rl_instream), &fds);
|
FD_SET(fileno(rl_instream), &fds);
|
||||||
errno = 0;
|
errno = 0;
|
||||||
@ -142,13 +145,16 @@ inp_readline(void)
|
|||||||
if (r < 0) {
|
if (r < 0) {
|
||||||
char *err_msg = strerror(errno);
|
char *err_msg = strerror(errno);
|
||||||
log_error("Readline failed: %s", err_msg);
|
log_error("Readline failed: %s", err_msg);
|
||||||
return TRUE;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (FD_ISSET(fileno(rl_instream), &fds)) {
|
if (FD_ISSET(fileno(rl_instream), &fds)) {
|
||||||
rl_callback_read_char();
|
rl_callback_read_char();
|
||||||
|
|
||||||
if (rl_line_buffer && rl_line_buffer[0] != '/' && rl_line_buffer[0] != '\0' && rl_line_buffer[0] != '\n') {
|
if (rl_line_buffer &&
|
||||||
|
rl_line_buffer[0] != '/' &&
|
||||||
|
rl_line_buffer[0] != '\0' &&
|
||||||
|
rl_line_buffer[0] != '\n') {
|
||||||
prof_handle_activity();
|
prof_handle_activity();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -168,7 +174,11 @@ inp_readline(void)
|
|||||||
p_rl_timeout.tv_usec = inp_timeout * 1000;
|
p_rl_timeout.tv_usec = inp_timeout * 1000;
|
||||||
}
|
}
|
||||||
|
|
||||||
return cmd_result;
|
if (inp_line) {
|
||||||
|
return strdup(inp_line);
|
||||||
|
} else {
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
@ -213,6 +223,8 @@ inp_nonblocking(gboolean reset)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
log_info("Timeout: %d", inp_timeout);
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
@ -228,19 +240,29 @@ inp_close(void)
|
|||||||
rl_callback_handler_remove();
|
rl_callback_handler_remove();
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
char*
|
||||||
inp_get_password(char *passwd)
|
inp_get_password(void)
|
||||||
{
|
{
|
||||||
werase(inp_win);
|
werase(inp_win);
|
||||||
wmove(inp_win, 0, 0);
|
wmove(inp_win, 0, 0);
|
||||||
pad_start = 0;
|
pad_start = 0;
|
||||||
_inp_win_update_virtual();
|
_inp_win_update_virtual();
|
||||||
doupdate();
|
doupdate();
|
||||||
noecho();
|
char *password = NULL;
|
||||||
mvwgetnstr(inp_win, 0, 1, passwd, MAX_PASSWORD_SIZE);
|
get_password = TRUE;
|
||||||
wmove(inp_win, 0, 0);
|
while (!password) {
|
||||||
echo();
|
password = inp_readline();
|
||||||
|
ui_update();
|
||||||
|
werase(inp_win);
|
||||||
|
wmove(inp_win, 0, 0);
|
||||||
|
pad_start = 0;
|
||||||
|
_inp_win_update_virtual();
|
||||||
|
doupdate();
|
||||||
|
}
|
||||||
|
get_password = FALSE;
|
||||||
|
|
||||||
status_bar_clear();
|
status_bar_clear();
|
||||||
|
return password;
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
@ -378,10 +400,11 @@ static void
|
|||||||
_inp_rl_linehandler(char *line)
|
_inp_rl_linehandler(char *line)
|
||||||
{
|
{
|
||||||
if (line && *line) {
|
if (line && *line) {
|
||||||
add_history(line);
|
if (!get_password) {
|
||||||
|
add_history(line);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
cmd_result = cmd_process_input(line);
|
inp_line = line;
|
||||||
free(line);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static int
|
static int
|
||||||
|
@ -40,13 +40,13 @@
|
|||||||
#define INP_WIN_MAX 1000
|
#define INP_WIN_MAX 1000
|
||||||
|
|
||||||
void create_input_window(void);
|
void create_input_window(void);
|
||||||
gboolean inp_readline(void);
|
char* inp_readline(void);
|
||||||
void inp_nonblocking(gboolean reset);
|
void inp_nonblocking(gboolean reset);
|
||||||
void inp_close(void);
|
void inp_close(void);
|
||||||
void inp_win_clear(void);
|
void inp_win_clear(void);
|
||||||
void inp_win_resize(void);
|
void inp_win_resize(void);
|
||||||
void inp_put_back(void);
|
void inp_put_back(void);
|
||||||
void inp_block(void);
|
void inp_block(void);
|
||||||
void inp_get_password(char *passwd);
|
char* inp_get_password(void);
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
@ -233,7 +233,7 @@ void ui_update_presence(const resource_presence_t resource_presence,
|
|||||||
void ui_about(void);
|
void ui_about(void);
|
||||||
void ui_statusbar_new(const int win);
|
void ui_statusbar_new(const int win);
|
||||||
|
|
||||||
gboolean ui_readline(void);
|
char* ui_readline(void);
|
||||||
void ui_input_clear(void);
|
void ui_input_clear(void);
|
||||||
void ui_input_nonblocking(gboolean);
|
void ui_input_nonblocking(gboolean);
|
||||||
void ui_write(char *line, int offset);
|
void ui_write(char *line, int offset);
|
||||||
|
@ -329,9 +329,9 @@ void ui_update_presence(const resource_presence_t resource_presence,
|
|||||||
void ui_about(void) {}
|
void ui_about(void) {}
|
||||||
void ui_statusbar_new(const int win) {}
|
void ui_statusbar_new(const int win) {}
|
||||||
|
|
||||||
gboolean ui_readline(void)
|
char* ui_readline(void)
|
||||||
{
|
{
|
||||||
return TRUE;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
void ui_inp_history_append(char *inp) {}
|
void ui_inp_history_append(char *inp) {}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user