Reading the Device Status Report ANSI escape sequence reply

前端 未结 4 1163
独厮守ぢ
独厮守ぢ 2020-12-19 02:08

I\'m trying to retrieve the coordinates of cursor in a VT100 terminal using the following code:

void getCursor(int* x, int* y) {
  printf(\"\\033[6n\");
   s         


        
4条回答
  •  無奈伤痛
    2020-12-19 02:49

    Your program is working but is waiting for an EOL character.

    scanf is line oriented so it waits for a new line before processing. Try running your program and then hit the enter key.

    The solution is to use something else that doesn't need a new line to read the input and then use sscanf to parse the values out.

    You will also need to make stdin non-blocking or you won't get the input until the buffer is full or stdin is closed. See this question Making stdin non-blocking

    You should also call fflush(stdout); after your printf to ensure it is actually written (printf is often line buffered so without a newline it may not flush the buffer).

提交回复
热议问题