commit 5597fee92d7afc91efc414aaa9c8dc0698100c61
parent 6ec80047624d575776df0fac03e18a9deb466bdd
Author: Claudio Alessi <smoppy@gmail.com>
Date: Fri, 14 Jul 2017 21:22:29 +0200
Now backspace works as expected.
Added the backspace support and bound it to the editor_chdel() function, which
delete the last character in the buffer.
Note: this has to be changed once in-buffer editing will be implemented.
This commit also align config.def.h which was still the old commands function names.
Diffstat:
2 files changed, 22 insertions(+), 12 deletions(-)
diff --git a/circo.c b/circo.c
@@ -39,7 +39,7 @@ char *argv0;
#define CTRL_ALT(k) ((k) + (129 - 'a'))
/* enums */
-enum { KeyUp = -50, KeyDown, KeyRight, KeyLeft, KeyHome, KeyEnd, KeyDel, KeyPgUp, KeyPgDw };
+enum { KeyUp = -50, KeyDown, KeyRight, KeyLeft, KeyHome, KeyEnd, KeyDel, KeyPgUp, KeyPgDw, KeyBackspace };
typedef union {
int i;
@@ -89,6 +89,7 @@ void drawbar(void);
void drawbuf(void);
void drawcmdln(void);
void *ecalloc(size_t nmemb, size_t size);
+void editor_chdel(const Arg *arg);
void editor_clear(const Arg *arg);
Buffer *getbuf(char *name);
void focusnext(const Arg *arg);
@@ -285,6 +286,14 @@ ecalloc(size_t nmemb, size_t size) {
}
void
+editor_chdel(const Arg *arg) {
+ if(!sel->cmdlen)
+ return;
+ sel->cmd[--sel->cmdlen] = '\0';
+ drawcmdln();
+}
+
+void
editor_clear(const Arg *arg) {
sel->cmd[0] = '\0';
sel->cmdlen = 0;
@@ -329,8 +338,12 @@ int
getkey(void) {
int key = getchar(), c;
- if(key != '\x1b' || getchar() != '[')
+ if(key != '\x1b' || getchar() != '[') {
+ switch(key) {
+ case 127: key = KeyBackspace; break;
+ }
return key;
+ }
switch((c = getchar())) {
case 'A': key = KeyUp; break;
case 'B': key = KeyDown; break;
@@ -345,10 +358,6 @@ getkey(void) {
case '6': key = KeyPgDw; break;
case '7': key = KeyHome; break;
case '8': key = KeyEnd; break;
- default:
- /* debug */
- mvprintf(1, rows, "Unknown char: %c (%d)", c, c);
- break;
}
return key;
}
diff --git a/config.def.h b/config.def.h
@@ -1,18 +1,19 @@
/* See LICENSE file for copyright and license details. */
Command commands[] = {
- { "connect", server },
- { "msg", msg },
- { "quit", quit },
- { "server", server },
+ { "connect", cmd_server },
+ { "msg", cmd_msg },
+ { "quit", cmd_quit },
+ { "server", cmd_server },
};
/* key definitions */
static Key keys[] = {
/* key function argument */
{ CTRL('u'), editor_clear, {0} },
+ { KeyBackspace,editor_chdel, {0} },
{ CTRL('n'), focusnext, {0} },
{ CTRL('p'), focusprev, {0} },
- { KeyPgUp, scroll, {.i = +20} },
- { KeyPgDw, scroll, {.i = -20} },
+ { KeyPgUp, scroll, {.i = -20} },
+ { KeyPgDw, scroll, {.i = +20} },
};