about summary refs log tree commit diff stats
path: root/src
diff options
context:
space:
mode:
authorJames Booth <boothj5@gmail.com>2015-02-05 00:58:23 +0000
committerJames Booth <boothj5@gmail.com>2015-02-05 00:58:23 +0000
commita70aa0255fc438894e563f80dfb4ab88278a1118 (patch)
treea0ecd10ec5fe50aff2149cfde1fd6fd5bad2c2f2 /src
parent30180ac8bb125e4cae03c415201f796863d4c80b (diff)
downloadprofani-tty-a70aa0255fc438894e563f80dfb4ab88278a1118.tar.gz
Moved command processing to main loop, allow resize during password prompt
Diffstat (limited to 'src')
-rw-r--r--src/profanity.c10
-rw-r--r--src/ui/core.c10
-rw-r--r--src/ui/inputwin.c51
-rw-r--r--src/ui/inputwin.h4
-rw-r--r--src/ui/ui.h2
5 files changed, 51 insertions, 26 deletions
diff --git a/src/profanity.c b/src/profanity.c
index f863a323..86730649 100644
--- a/src/profanity.c
+++ b/src/profanity.c
@@ -82,10 +82,18 @@ prof_run(const int disable_tls, char *log_level, char *account_name)
 
     log_info("Starting main event loop");
 
+    char *line = NULL;
     while(cont) {
         _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
         otr_poll();
diff --git a/src/ui/core.c b/src/ui/core.c
index add80dff..0fde3387 100644
--- a/src/ui/core.c
+++ b/src/ui/core.c
@@ -198,7 +198,7 @@ ui_close(void)
     endwin();
 }
 
-gboolean
+char *
 ui_readline(void)
 {
     return inp_readline();
@@ -2249,15 +2249,9 @@ ui_win_unread(int index)
 char *
 ui_ask_password(void)
 {
-  char *passwd = malloc(sizeof(char) * (MAX_PASSWORD_SIZE + 1));
   status_bar_get_password();
   status_bar_update_virtual();
-  inp_block();
-  inp_get_password(passwd);
-//  inp_non_block(prefs_get_inpblock());
-  inp_nonblocking(TRUE);
-
-  return passwd;
+  return inp_get_password();
 }
 
 void
diff --git a/src/ui/inputwin.c b/src/ui/inputwin.c
index 1e78bbcc..5f13377a 100644
--- a/src/ui/inputwin.c
+++ b/src/ui/inputwin.c
@@ -74,7 +74,8 @@ static gint no_input_count = 0;
 
 static fd_set fds;
 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 int _inp_printable(const wint_t ch);
@@ -132,9 +133,11 @@ create_input_window(void)
     _inp_win_update_virtual();
 }
 
-gboolean
+char *
 inp_readline(void)
 {
+    free(inp_line);
+    inp_line = NULL;
     FD_ZERO(&fds);
     FD_SET(fileno(rl_instream), &fds);
     errno = 0;
@@ -142,13 +145,16 @@ inp_readline(void)
     if (r < 0) {
         char *err_msg = strerror(errno);
         log_error("Readline failed: %s", err_msg);
-        return TRUE;
+        return NULL;
     }
 
     if (FD_ISSET(fileno(rl_instream), &fds)) {
         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();
         }
 
@@ -168,7 +174,11 @@ inp_readline(void)
         p_rl_timeout.tv_usec = inp_timeout * 1000;
     }
 
-    return cmd_result;
+    if (inp_line) {
+        return strdup(inp_line);
+    } else {
+        return NULL;
+    }
 }
 
 void
@@ -213,6 +223,8 @@ inp_nonblocking(gboolean reset)
             }
         }
     }
+
+    log_info("Timeout: %d", inp_timeout);
 }
 
 void
@@ -228,19 +240,29 @@ inp_close(void)
     rl_callback_handler_remove();
 }
 
-void
-inp_get_password(char *passwd)
+char*
+inp_get_password(void)
 {
     werase(inp_win);
     wmove(inp_win, 0, 0);
     pad_start = 0;
     _inp_win_update_virtual();
     doupdate();
-    noecho();
-    mvwgetnstr(inp_win, 0, 1, passwd, MAX_PASSWORD_SIZE);
-    wmove(inp_win, 0, 0);
-    echo();
+    char *password = NULL;
+    get_password = TRUE;
+    while (!password) {
+        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();
+    return password;
 }
 
 void
@@ -378,10 +400,11 @@ static void
 _inp_rl_linehandler(char *line)
 {
     if (line && *line) {
-        add_history(line);
+        if (!get_password) {
+            add_history(line);
+        }
     }
-    cmd_result = cmd_process_input(line);
-    free(line);
+    inp_line = line;
 }
 
 static int
diff --git a/src/ui/inputwin.h b/src/ui/inputwin.h
index a88211c4..b9026863 100644
--- a/src/ui/inputwin.h
+++ b/src/ui/inputwin.h
@@ -40,13 +40,13 @@
 #define INP_WIN_MAX 1000
 
 void create_input_window(void);
-gboolean inp_readline(void);
+char* inp_readline(void);
 void inp_nonblocking(gboolean reset);
 void inp_close(void);
 void inp_win_clear(void);
 void inp_win_resize(void);
 void inp_put_back(void);
 void inp_block(void);
-void inp_get_password(char *passwd);
+char* inp_get_password(void);
 
 #endif
diff --git a/src/ui/ui.h b/src/ui/ui.h
index 92f570d5..1062eac1 100644
--- a/src/ui/ui.h
+++ b/src/ui/ui.h
@@ -233,7 +233,7 @@ void ui_update_presence(const resource_presence_t resource_presence,
 void ui_about(void);
 void ui_statusbar_new(const int win);
 
-gboolean ui_readline(void);
+char* ui_readline(void);
 void ui_input_clear(void);
 void ui_input_nonblocking(gboolean);
 void ui_write(char *line, int offset);