Commands written in the form of Esc sequences are widely used on the Linux console. It is very simple to send a similar command from a console application, just write something like print (screen, "E [6n") and the command "Show current cursor position" will go exactly where it should be, and the console will respond immediately by displaying the message - ^ [[20; 30R - which begins just at the current cursor position and means "line 20, column 30".

But I need to intercept this console report so that it doesn’t get on the screen, and the donkey is in any variable in my console application in order to use this data to organize further output of text in the console window.

The problem arose because, if you output Russian text in the utf-8 encoding to the console, the usual functions like get_cursor_position () on the two-byte encoding are lost and output the wrong cursor position value, and the Esc command gives you exactly what I need.


  • And all sorts of ncurces can not help here? (I just didn’t deal with them, so I won’t write in more detail). In addition, esc-sequences are specific for a specific terminal and it is not recommended to put them on their own program. - alexlz

1 answer 1

Specifically, 6n only returns a “column” to me ... I don’t know if this is suitable for you, but this option works directly in the shell (bash):

$~ POSITION="15;25"; RETURN=$(echo -ne "\033[${POSITION}H\033[6n") ; echo ${RETURN} ~> ;25R