From b2173522cddbb0c6502804702cce914807c8a2a3 Mon Sep 17 00:00:00 2001 From: James Booth Date: Mon, 6 Feb 2012 22:04:30 +0000 Subject: [PATCH] Handle delete char in command win --- profanity.c | 19 ++++++++++++++++--- windows.c | 1 + 2 files changed, 17 insertions(+), 3 deletions(-) diff --git a/profanity.c b/profanity.c index c13dfb9c..74b4eeaa 100644 --- a/profanity.c +++ b/profanity.c @@ -106,7 +106,7 @@ void event_loop(xmpp_ctx_t *ctx, xmpp_conn_t *conn) wtimeout(cmd_win, 0); while(TRUE) { - char ch = 0; + int ch = ERR; char command[100]; int size = 0; @@ -120,11 +120,24 @@ void event_loop(xmpp_ctx_t *ctx, xmpp_conn_t *conn) getyx(cmd_win, cmd_y, cmd_x); wmove(cmd_win, cmd_y, cmd_x); - // get some more input + // echo off, and get some more input + noecho(); ch = wgetch(cmd_win); - if (ch > 0 && ch != '\n') { + + // if delete pressed, go back and delete it + if (ch == 127) { + getyx(cmd_win, cmd_y, cmd_x); + wmove(cmd_win, cmd_y, cmd_x-1); + wdelch(cmd_win); + size--; + } + // else if not error or newline, show it and store it + else if (ch != ERR && ch != '\n') { + waddch(cmd_win, ch); command[size++] = ch; } + + echo(); } command[size++] = '\0'; diff --git a/windows.c b/windows.c index 2a7f220b..a34c2ee0 100644 --- a/windows.c +++ b/windows.c @@ -69,6 +69,7 @@ static void create_command_window(void) getmaxyx(stdscr, rows, cols); cmd_win = newwin(1, cols, rows-1, 0); + keypad(cmd_win, TRUE); } static void create_main_window(void)