trilobite
November 21st, 2010, 01:27 AM
Hi all -
I'm writing a small text-editor in C using curses. I've got a problem with getting the backspace key working as it should (I'm on Ubuntu 10.04).
On the command-line, typing Ctrl-V then <backspace> shows ^? . Ctrl-V and <Delete> gives ^[[3~ .
However, in my little editor, when I press backspace, it shows ^G.
Also- the test for KEY_BACKSPACE in the code below is not working. The following is the relevant code for my app -
#include <curses.h>
/* Declare our window */
WINDOW *mywin;
/* Number of rows and cols */
int r, c, nrows, ncols;
void backspace()
{
noecho();
nocbreak();
getyx(mywin, r, c);
move(r, c-1);
delch();
cbreak();
refresh();
}
/* Handle the keyboard input */
void keyhandler()
{
getyx(mywin, r, c);
ch = getch();
if (ch == KEY_BACKSPACE) backspace();
else addch(ch);
}
int main(int argc, char *argv[])
{
/* Initialise the screen */
mywin = initscr();
noecho();
raw();
keypad(stdscr, TRUE);
scrollok(mywin,1);
idcok(mywin, 1);
idlok(mywin, 1);
getmaxyx(mywin, nrows, ncols);
clear();
refresh();
/* Set row and col */
r=0; c=0;
/* The main loop */
while(1)
{
keyhandler();
}
echo();
keypad(mywin, 0);
endwin();
return 0;
}
Btw - typing "echo $TERM" on the command-line gives me "xterm". Not hugely helpful, as there are about two dozen entries with "xterm" in their name in the terminfo directory.
So, if anyone is able to let me know how the backspace key can be made to work, that'll be great! I'm sure others must have come across similar problems - I'm keen to hear how they were solved.
Many thanks in advance -
- Andy
I'm writing a small text-editor in C using curses. I've got a problem with getting the backspace key working as it should (I'm on Ubuntu 10.04).
On the command-line, typing Ctrl-V then <backspace> shows ^? . Ctrl-V and <Delete> gives ^[[3~ .
However, in my little editor, when I press backspace, it shows ^G.
Also- the test for KEY_BACKSPACE in the code below is not working. The following is the relevant code for my app -
#include <curses.h>
/* Declare our window */
WINDOW *mywin;
/* Number of rows and cols */
int r, c, nrows, ncols;
void backspace()
{
noecho();
nocbreak();
getyx(mywin, r, c);
move(r, c-1);
delch();
cbreak();
refresh();
}
/* Handle the keyboard input */
void keyhandler()
{
getyx(mywin, r, c);
ch = getch();
if (ch == KEY_BACKSPACE) backspace();
else addch(ch);
}
int main(int argc, char *argv[])
{
/* Initialise the screen */
mywin = initscr();
noecho();
raw();
keypad(stdscr, TRUE);
scrollok(mywin,1);
idcok(mywin, 1);
idlok(mywin, 1);
getmaxyx(mywin, nrows, ncols);
clear();
refresh();
/* Set row and col */
r=0; c=0;
/* The main loop */
while(1)
{
keyhandler();
}
echo();
keypad(mywin, 0);
endwin();
return 0;
}
Btw - typing "echo $TERM" on the command-line gives me "xterm". Not hugely helpful, as there are about two dozen entries with "xterm" in their name in the terminfo directory.
So, if anyone is able to let me know how the backspace key can be made to work, that'll be great! I'm sure others must have come across similar problems - I'm keen to hear how they were solved.
Many thanks in advance -
- Andy