Move the cursor in a C program

后端 未结 4 1880
Happy的楠姐
Happy的楠姐 2020-12-14 18:01

I\'d like to move the cursor forward and backwards in a C program. I\'m reading the whole line in a loop, but i would like that if a cursor key gets pressed the cursor on th

4条回答
  •  小蘑菇
    小蘑菇 (楼主)
    2020-12-14 18:44

    ANSI escape sequences allow you to move the cursor around the screen at will. This can be useful for full screen user interfaces generated by program running under shell, but can also be used in prompts. This will NOT work on the terminal emulators that don't accept the save and restore cursor position codes. More information of the escape sequences to move the cursor, please see cursor movement.

    If you need a more portable solution, use curses, it's a terminal control library that manage an application's display on character-cell terminals for Unix-like systems. The curses library on the executing system sends the correct control characters based on the terminal type. Use int wmove(WINDOW* win, int y, int x) in ncurses, to move the cursor to a new position. More information about how to program under ncurses, see NCurses-programing-howto.

提交回复
热议问题