wmcbrine / PDCurses

A curses library for environments that don't fit the termcap/terminfo model.
https://pdcurses.org/
1.04k stars 176 forks source link

Cursor on pads won't display in the right position. #128

Closed GiorgosXou closed 1 year ago

GiorgosXou commented 2 years ago

Every time I insert a character inside the pad, for a very tiny moment of time the cursor moves where it is supposed to move and adds the charachter as it should BUT the moment after the insertion of the character, immediately after, the cursor returns back to 0,0; when i read the position of the cursor in the pad (getyx(pad)) the value is correct (not 0,0) but for a weird reason the cursor gets displayed at 0,0 (This does not happen with stdscr or NCurses)

pdcursesbug4_CURSOR_PAD2 gif

Examples

int main( void) { int ch =-1; initscr(); noecho (); keypad(stdscr, TRUE);

while(ch != 'Q')
{
    ch = getch();
    addch(ch);
}
endwin( );
return(0);

}

* **With PAD:**
```c++
#include <curses.h>

int main( void)
{
    int y, x;
    int ch =-1;
    int TLINES, TCOLS;
    WINDOW *pad1;

    initscr();
    noecho ();
    keypad(stdscr, TRUE);
    refresh();

    getmaxyx(stdscr,TLINES,TCOLS);
    pad1 = newpad(TLINES, TCOLS);

    while(ch != 'Q')
    {
        ch = getch();
        waddch(pad1,ch);
        prefresh(pad1, 0, 0, 0, 0, TLINES -1, TCOLS -1);
    }
    endwin( );
    return(0);
} 

Why I really care about this issue

I am building a prototype of a terminal based edditor for the unicurses library and the momment i switched from stdscr to pads I found out that there was this issue, and i can't figure out how to fix it and it really bothers me pdcursesbug4_CURSOR_PAD gif

Any Idea?

wmcbrine commented 2 years ago

Remember that getch() is really wgetch(stdscr). When you call wgetch(), PDCurses moves the cursor to the spot where the input will appear (or would, if not for noecho()... hmm). My usual advice is to alter getch() calls to wgetch() on the appropriate window instead. But, perhaps noecho() should be having more of an effect here. I'll look into that...

ncurses does something different where, IIRC, it doesn't update the cursor position until there's actually input (or rather, output of that input). I intentionally didn't copy that behavior, because I thought the cursor should indicate where the input would appear. But, that really only should apply to echo mode.

GiorgosXou commented 2 years ago

@wmcbrine doing wget_wch(editorpad) instead of get_wch() fixed the issue with the currsor, but another issue appeared: arrow keys won't get read\captured when i do wget_wch(editorpad) for some reason...

GiorgosXou commented 2 years ago

An issue with the arrow keys and wget_wch(editorpad) seems to occure with NCurses too (where it just crushes)

wmcbrine commented 2 years ago

@wmcbrine doing wget_wch(editorpad) instead of get_wch() fixed the issue with the currsor, but another issue appeared: arrow keys won't get read\captured when i do wget_wch(editorpad) for some reason...

Remember, keypad() is also per-window.

GiorgosXou commented 2 years ago

Remember, keypad() is also per-window.

I wasn't aware of this, thanks!! everything works fine now.