Code

use g_ascii_isspace() instead of IS_WHITESPACE()
[ncmpc.git] / src / wreadln.c
index f6b848cdd86788df9ade64319e474e8c8f052fad..d01cfcb87c8517544c930cc5a86b9b8ba1440af2 100644 (file)
@@ -18,6 +18,8 @@
  *
  */
 
+#include "wreadln.h"
+#include "charset.h"
 #include "config.h"
 
 #include <stdlib.h>
 #include <ncurses.h>
 #endif
 
-#include "wreadln.h"
-
 #define KEY_CTRL_A   1
+#define KEY_CTRL_B   2
 #define KEY_CTRL_C   3
-#define KEY_CTRL_D   4 
+#define KEY_CTRL_D   4
 #define KEY_CTRL_E   5
+#define KEY_CTRL_F   6
 #define KEY_CTRL_G   7
 #define KEY_CTRL_K   11
+#define KEY_CTRL_N   14
+#define KEY_CTRL_P   16
 #define KEY_CTRL_U   21
 #define KEY_CTRL_Z   26
 #define KEY_BCKSPC   8
@@ -55,7 +59,6 @@ wrln_gcmp_post_cb_t wrln_post_completion_callback = NULL;
 
 extern void sigstop(void);
 extern void screen_bell(void);
-extern size_t my_strlen(char *str);
 
 #ifndef USE_NCURSESW
 /* move the cursor one step to the right */
@@ -66,7 +69,8 @@ static inline void cursor_move_right(gint *cursor,
                                     gint x1,
                                     gchar *line)
 {
-       if (*cursor < strlen(line) && *cursor < wrln_max_line_size - 1) {
+       if (*cursor < (int)strlen(line) &&
+           *cursor < (int)wrln_max_line_size - 1) {
                (*cursor)++;
                if (*cursor + x0 >= x1 && *start < *cursor - width + 1)
                        (*start)++;
@@ -112,7 +116,7 @@ static inline void drawline(gint cursor,
   /* clear input area */
   whline(w, ' ', width);
   /* print visible part of the line buffer */
-  if(masked == TRUE) whline(w, '*', my_strlen(line)-start);
+  if(masked == TRUE) whline(w, '*', utf8_width(line) - start);
   else waddnstr(w, line+start, width);
   /* move the cursor to the correct position */
   wmove(w, y, x0 + cursor-start);
@@ -250,9 +254,11 @@ _wreadln(WINDOW *w,
                        return NULL;
 
                case KEY_LEFT:
+               case KEY_CTRL_B:
                        cursor_move_left(&cursor, &start);
                        break;
                case KEY_RIGHT:
+               case KEY_CTRL_F:
                        cursor_move_right(&cursor, &start, width, x0, x1, line);
                        break;
                case KEY_HOME:
@@ -268,7 +274,7 @@ _wreadln(WINDOW *w,
                        line[cursor] = 0;
                        break;
                case KEY_CTRL_U:
-                       cursor = my_strlen(line);
+                       cursor = utf8_width(line);
                        for (i = 0;i < cursor; i++)
                                line[i] = '\0';
                        cursor = 0;
@@ -284,12 +290,13 @@ _wreadln(WINDOW *w,
                        break;
                case KEY_DC:            /* handle delete key. As above */
                case KEY_CTRL_D:
-                       if (cursor <= my_strlen(line) - 1) {
+                       if (cursor <= (gint)utf8_width(line) - 1) {
                                for (i = cursor; line[i] != 0; i++)
                                        line[i] = line[i + 1];
                        }
                        break;
                case KEY_UP:
+               case KEY_CTRL_P:
                        /* get previous history entry */
                        if( history && hlist->prev ) {
                                if( hlist==hcurrent )
@@ -304,6 +311,7 @@ _wreadln(WINDOW *w,
                        cursor_move_to_eol(&cursor, &start, width, x0, x1, line);
                        break;
                case KEY_DOWN:
+               case KEY_CTRL_N:
                        /* get next history entry */
                        if( history && hlist->next ) {
                                /* get next line */
@@ -325,7 +333,7 @@ _wreadln(WINDOW *w,
                        if (key >= 32) {
                                if (strlen (line + cursor)) { /* if the cursor is */
                                        /* not at the last pos */
-                                       gchar *tmp = 0;
+                                       gchar *tmp = NULL;
                                        gsize size = strlen(line + cursor) + 1;
 
                                        tmp = g_malloc0(size);