获取终端下光标的位置

本文详细介绍了如何使用bash脚本结合xterm终端特性实现特定功能,包括禁用回显、改变输入方式、从一进制转零进制等。通过脚本操作,用户可以更好地控制终端交互体验。

1 #!/bin/bash
2 #based on a script from http://invisible-island.net/xterm/xterm.faq.html
3 exec < /dev/tty
4 oldstty=$(stty -g)
5 stty raw -echo min 0
6 # on my system, the following line can be replaced by the line below it
7 echo -en "\033[6n" > /dev/tty
8 # tput u7 > /dev/tty # when TERM=xterm (and relatives)
9 IFS=';' read -r -d R -a pos
10 stty $oldstty
11 # change from one-based to zero based so they work with: tput cup $row $col
12 row=$((${pos[0]:2} - 1)) # strip off the esc-[
13 col=$((${pos[1]} - 1))
14
15 echo "(row,col): $row,$col"

转载于:https://www.cnblogs.com/ggaaooppeennngg/p/3740138.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值