Termcaps : 获取光标位置 [英] Termcaps : Get cursor position
问题描述
我需要使用 C 中的 termcaps 获取终端光标的 (Y, X) 位置.
I need to get my (Y, X) position of my terminal's cursor with the termcaps in C.
使用 ioctl()
我得到了终端屏幕的大小,但我仍然需要得到我的光标所在的位置.
With ioctl()
i get the size of my terminal screen, but i still need to get where my cursor is.
我发现了这个:
CSI 6 n DSR – 设备状态报告将光标位置报告给应用程序(就像在键盘上输入一样)ESC[n;mR,其中 n 是行,m 是列.(可能不适用于 MS-DOS.)
CSI 6 n DSR – Device Status Report Reports the cursor position to the application as (as though typed at the keyboard) ESC[n;mR, where n is the row and m is the column. (May not work on MS-DOS.)
但我不知道如何在 C 中使用它...
But i have no idea how to use it in C ...
推荐答案
您将命令序列 (
) 写入终端使用 stdout的正常输出
代码>.然后使用来自 stdin
的普通输入读取响应.
You write the command sequence (<ESC>[6n
) to the terminal using normal output to stdout
. Then you read the response using normal input from stdin
.
你需要解析回复"来挑选位置.
You need to parse the "reply" to pick out the position.
这篇关于Termcaps : 获取光标位置的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!