Permalink
Browse files

Merge pull request #18 from gsserge/master

Yet Another Ctrl+W
  • Loading branch information...
2 parents 02d7935 + 98ca039 commit 8c9b481281ba401f6baf45bc9ca9fc940b59405f @antirez committed Oct 2, 2012
Showing with 14 additions and 0 deletions.
  1. +14 −0 linenoise.c
View
@@ -293,6 +293,8 @@ static int linenoisePrompt(int fd, char *buf, size_t buflen, const char *prompt)
size_t len = 0;
size_t cols = getColumns();
int history_index = 0;
+ size_t old_pos;
+ size_t diff;
buf[0] = '\0';
buflen--; /* Make sure there is always space for the nulterm */
@@ -468,6 +470,18 @@ static int linenoisePrompt(int fd, char *buf, size_t buflen, const char *prompt)
case 12: /* ctrl+l, clear screen */
linenoiseClearScreen();
refreshLine(fd,prompt,buf,len,pos,cols);
+ break;
+ case 23: /* ctrl+w, delete previous word */
+ old_pos = pos;
+ while (pos > 0 && buf[pos-1] == ' ')
+ pos--;
+ while (pos > 0 && buf[pos-1] != ' ')
+ pos--;
+ diff = old_pos - pos;
+ memmove(&buf[pos], &buf[old_pos], len-old_pos+1);
+ len -= diff;
+ refreshLine(fd,prompt,buf,len,pos,cols);
+ break;
}
}
return len;

0 comments on commit 8c9b481

Please sign in to comment.