简单的,通过代码,实现光标的移动和定位

#include <stdio.h>  
#include <unistd.h>  
  
// 清除屏幕  
#define CLEAR() printf("\033[2J")  
  
// 上移光标  
#define MOVEUP(x) printf("\033[%dA", (x))  
  
// 下移光标  
#define MOVEDOWN(x) printf("\033[%dB", (x))  
  
// 左移光标  
#define MOVELEFT(y) printf("\033[%dD", (y))  
  
// 右移光标  
#define MOVERIGHT(y) printf("\033[%dC",(y))  
  
// 定位光标  
#define MOVETO(x,y) printf("\033[%d;%dH", (x), (y))  
  
// 光标复位  
#define RESET_CURSOR() printf("\033[H")  
  
// 隐藏光标  
#define HIDE_CURSOR() printf("\033[?25l")  
  
// 显示光标  
#define SHOW_CURSOR() printf("\033[?25h")  
  
//反显  
#define HIGHT_LIGHT() printf("\033[7m")  
#define UN_HIGHT_LIGHT() printf("\033[27m")  
  
int main(int argc,char **argv)  
{  
printf("\033[31mThe color,%s!\033[1m\n","haha");  
printf("\033[31mThe color,%s!\033[4m\n","haha");  
printf("\033[31mThe color,%s!\033[5m\n","haha");  
printf("\033[31mThe color,%s!\033[7m\n","haha");  
printf("\033[31mThe color,%s!\033[8m\n","haha");  
printf("\033[31mThe color,%s!\033[0m\n","haha");  
printf("\033[47;31mThe color,%s!\033[0m\n","haha");  
printf("\033[47mThe color,%s!\033[0m\n","haha");  
sleep(2);  
printf("\033[47m%s!\033[5A\n","up 5");  
sleep(2);  
printf("\033[47m%s!\033[9B\n","down 9");  
sleep(2);  
printf("\033[47m%s!\033[19C\n","right 19");  
printf("right19");  
sleep(2);  
printf("\033[47m%s!\033[10D\n","left 10");  
printf("left 10");  
sleep(2);  
printf("\033[47m%s!\033[50;20H\n","move to y:50,x 20");  
printf("y50 x 20");  
sleep(2);  
printf("\033[47m%s!\033[?25l\n","hide cursor");  
sleep(2);  
printf("\033[47m%s!\033[?25h\n","sow cursor");  
sleep(2);  
printf("\033[47m%s!\033[2J\n","clear scleen");  
sleep(2);  
system("reset");
return 0;  
}  

  • 0
    点赞
  • 4
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值