如果光標在按下b(刪除)鍵時位於行首,我想將光標移到上一行。 將光標移動到ncurses中的上一行
void processKey()
{
char ch = getch();
char *check = unctrl(ch);
int safe = (check != 0 && strlen(check) == 1);
int Trow,Tcol; //Terminal's full rows and columns.
getmaxyx(stdscr,Trow,Tcol);
int row,col; //Current row and columns.
getyx(stdscr,row,col);
switch(ch)
{
case 0x11: //Ctrl + Q
closee();
break;
case 'b': //pressing "b" deletes the previous character.
if(col==0)
{
//This should move the cursor to the previous line. But that doesn't work.
move(row-1,Tcol);
addstr("\b \b");
refresh();
break;
}
else
{
addstr("\b \b");
break;
}
default:
if(safe)
{
addch(ch);
}
}
}
我想將光標移動到上一行。但是這並沒有發生,光標只停留在當前位置。我試圖通過使用mvcur()來做到這一點,但也顯示了相同的結果。 請告訴我什麼是正確的方法來完成這?
僅供參考:getch()返回一個「int」,而不是「char」。 – TonyB