about summary refs log tree commit diff stats
path: root/src/ui
diff options
context:
space:
mode:
Diffstat (limited to 'src/ui')
-rw-r--r--src/ui/core.c9
-rw-r--r--src/ui/inputwin.c30
-rw-r--r--src/ui/inputwin.h2
-rw-r--r--src/ui/ui.h2
4 files changed, 21 insertions, 22 deletions
diff --git a/src/ui/core.c b/src/ui/core.c
index 9ded610b..69701616 100644
--- a/src/ui/core.c
+++ b/src/ui/core.c
@@ -74,7 +74,6 @@
 
 static char *win_title;
 
-static char line[INP_WIN_MAX];
 static int inp_size;
 
 #ifdef HAVE_LIBXSS
@@ -183,8 +182,8 @@ ui_readline(void)
 {
     int key_type;
     wint_t ch;
-    inp_get_char(line, &key_type, &ch);
 
+    char *line = inp_get_char(&key_type, &ch);
     _win_handle_switch(ch);
 
     ProfWin *current = wins_get_current();
@@ -201,11 +200,7 @@ ui_readline(void)
         ui_input_nonblocking(FALSE);
     }
 
-    if (ch == '\n') {
-        return line;
-    } else {
-        return NULL;
-    }
+    return line;
 }
 
 void
diff --git a/src/ui/inputwin.c b/src/ui/inputwin.c
index c4c90986..43eaeba8 100644
--- a/src/ui/inputwin.c
+++ b/src/ui/inputwin.c
@@ -72,9 +72,12 @@
 #define KEY_CTRL_U 0025
 #define KEY_CTRL_W 0027
 
+#define INP_WIN_MAX 1000
+
 static WINDOW *inp_win;
 static int pad_start = 0;
 static int rows, cols;
+static char line[INP_WIN_MAX];
 static int inp_size;
 
 static int _handle_edit(int result, const wint_t ch, char *input);
@@ -132,13 +135,13 @@ inp_block(void)
     wtimeout(inp_win, -1);
 }
 
-void
-inp_get_char(char *result, int *key_type, wint_t *ch)
+char *
+inp_get_char(int *key_type, wint_t *ch)
 {
     int display_size = 0;
 
     if (inp_size != 0) {
-        display_size = g_utf8_strlen(result, inp_size);
+        display_size = g_utf8_strlen(line, inp_size);
     }
 
     // echo off, and get some more input
@@ -146,7 +149,7 @@ inp_get_char(char *result, int *key_type, wint_t *ch)
     *key_type = wget_wch(inp_win, ch);
 
     gboolean in_command = FALSE;
-    if ((display_size > 0 && result[0] == '/') ||
+    if ((display_size > 0 && line[0] == '/') ||
             (display_size == 0 && *ch == '/')) {
         in_command = TRUE;
     }
@@ -159,11 +162,11 @@ inp_get_char(char *result, int *key_type, wint_t *ch)
     }
 
     // if it wasn't an arrow key etc
-    if (!_handle_edit(*key_type, *ch, result)) {
+    if (!_handle_edit(*key_type, *ch, line)) {
         if (_printable(*ch) && *key_type != KEY_CODE_YES) {
             if (inp_size >= INP_WIN_MAX) {
                 *ch = ERR;
-                return;
+                return NULL;
             }
 
             int inp_x = getcurx(inp_win);
@@ -173,9 +176,9 @@ inp_get_char(char *result, int *key_type, wint_t *ch)
                 char bytes[MB_CUR_MAX];
                 size_t utf_len = wcrtomb(bytes, *ch, NULL);
 
-                char *next_ch = g_utf8_offset_to_pointer(result, inp_x);
+                char *next_ch = g_utf8_offset_to_pointer(line, inp_x);
                 char *offset;
-                for (offset = &result[inp_size - 1]; offset >= next_ch; offset--) {
+                for (offset = &line[inp_size - 1]; offset >= next_ch; offset--) {
                     *(offset + utf_len) = *offset;
                 }
                 int i;
@@ -184,7 +187,7 @@ inp_get_char(char *result, int *key_type, wint_t *ch)
                 }
 
                 inp_size += utf_len;
-                result[inp_size] = '\0';
+                line[inp_size] = '\0';
                 waddstr(inp_win, next_ch);
                 wmove(inp_win, 0, inp_x + 1);
 
@@ -202,9 +205,9 @@ inp_get_char(char *result, int *key_type, wint_t *ch)
                 if (utf_len < MB_CUR_MAX) {
                     int i;
                     for (i = 0 ; i < utf_len; i++) {
-                        result[inp_size++] = bytes[i];
+                        line[inp_size++] = bytes[i];
                     }
-                    result[inp_size] = '\0';
+                    line[inp_size] = '\0';
 
                     bytes[utf_len] = '\0';
                     waddstr(inp_win, bytes);
@@ -227,8 +230,11 @@ inp_get_char(char *result, int *key_type, wint_t *ch)
     echo();
 
     if (*ch == '\n') {
-        result[inp_size++] = '\0';
+        line[inp_size++] = '\0';
         inp_size = 0;
+        return strdup(line);
+    } else {
+        return NULL;
     }
 }
 
diff --git a/src/ui/inputwin.h b/src/ui/inputwin.h
index eb6c2127..5d104cdb 100644
--- a/src/ui/inputwin.h
+++ b/src/ui/inputwin.h
@@ -36,7 +36,7 @@
 #define UI_INPUTWIN_H
 
 void create_input_window(void);
-void inp_get_char(char *result, int *key_type, wint_t *ch);
+char* inp_get_char(int *key_type, wint_t *ch);
 void inp_win_reset(void);
 void inp_win_resize(void);
 void inp_put_back(void);
diff --git a/src/ui/ui.h b/src/ui/ui.h
index be6d2fd0..90dd4d28 100644
--- a/src/ui/ui.h
+++ b/src/ui/ui.h
@@ -51,8 +51,6 @@
 #include "ui/window.h"
 #include "xmpp/xmpp.h"
 
-#define INP_WIN_MAX 1000
-
 // ui startup and control
 void ui_init(void);
 void ui_load_colours(void);