私の(2つの)バージョンの同じ...
関数として、ncurses のユーザー定義コマンドを使用して、特定の変数を設定します。
getCPos () {
local v=() t=$(stty -g)
stty -echo
tput u7
IFS='[;' read -rd R -a v
stty $t
CPos=(${v[@]:1})
}
今より:
getCPos
echo $CPos
21
echo ${CPos[1]}
1
echo ${CPos[@]}
21 1
declare -p CPos
declare -a CPos=([0]="48" [1]="1")
注:私はncurses
command: tput u7
at 行を使用します。これは、 string by command:を使用するよりも移植性#4
が高くなることを期待しています ... わかりません: とにかく、これはそれらのいずれでも機能します:VT220
printf "\033[6n"
getCPos () {
local v=() t=$(stty -g)
stty -echo
printf "\033[6n"
IFS='[;' read -ra v -d R
stty $t
CPos=(${v[@]:1})
}
VT220互換の TERMの下では、まったく同じように動作します。
より詳しい情報
そこにいくつかのドキュメントが見つかるかもしれません:
VT220 プログラマ リファレンス マニュアル - 第 4 章
4.17.2 デバイス ステータス レポート (DSR)
...
Host to VT220 (Req 4 cur pos) CSI 6 n "Please report your cursor position using a CPR (not DSR) control sequence."
VT220 to host (CPR response) CSI Pv; Ph R "My cursor is positioned at _____ (Pv); _____ (Ph)."
Pv = vertical position (row)
Ph = horizontal position (column)