diff options
author | Max Kellermann <max@duempel.org> | 2008-10-06 14:56:15 +0200 |
---|---|---|
committer | Max Kellermann <max@duempel.org> | 2008-10-06 14:56:15 +0200 |
commit | 14a15db8fa40bf40047229be92d99c0f5a6d8309 (patch) | |
tree | 8ad8c917c432cc96661e7f220f01b65134fcd141 | |
parent | 32ac49ed95f5959d2206bf4e710350d435a04d05 (diff) | |
download | mpd-14a15db8fa40bf40047229be92d99c0f5a6d8309.tar.gz mpd-14a15db8fa40bf40047229be92d99c0f5a6d8309.tar.xz mpd-14a15db8fa40bf40047229be92d99c0f5a6d8309.zip |
wreadln: moved code to wreadln_delete()
Remove some more clutter from wreadln() by merging the duplicate
character deletion code to wreadln_delete_char().
Diffstat (limited to '')
-rw-r--r-- | src/wreadln.c | 23 |
1 files changed, 16 insertions, 7 deletions
diff --git a/src/wreadln.c b/src/wreadln.c index 59026ed08..608141f64 100644 --- a/src/wreadln.c +++ b/src/wreadln.c @@ -21,6 +21,7 @@ #include "screen_utils.h" #include "config.h" +#include <assert.h> #include <stdlib.h> #include <string.h> #include <glib.h> @@ -132,6 +133,17 @@ wreadln_insert_byte(struct wreadln *wr, gint key) cursor_move_right(wr); } +static void +wreadln_delete_char(struct wreadln *wr, size_t x) +{ + size_t i; + + assert(x < strlen(wr->line)); + + for (i = x; wr->line[i] != 0; i++) + wr->line[i] = wr->line[i + 1]; +} + /* libcurses version */ static gchar * @@ -274,18 +286,15 @@ _wreadln(WINDOW *w, case 127: case KEY_BCKSPC: /* handle backspace: copy all */ case KEY_BACKSPACE: /* chars starting from curpos */ - if (wr.cursor > 0) {/* - 1 from buf[n+1] to buf */ - for (i = wr.cursor - 1; wr.line[i] != 0; i++) - wr.line[i] = wr.line[i + 1]; + if (wr.cursor > 0) { /* - 1 from buf[n+1] to buf */ cursor_move_left(&wr); + wreadln_delete_char(&wr, wr.cursor); } break; case KEY_DC: /* handle delete key. As above */ case KEY_CTRL_D: - if (wr.cursor <= utf8_width(wr.line) - 1) { - for (i = wr.cursor; wr.line[i] != 0; i++) - wr.line[i] = wr.line[i + 1]; - } + if (wr.line[wr.cursor] != 0) + wreadln_delete_char(&wr, wr.cursor); break; case KEY_UP: case KEY_CTRL_P: |