用代码实现光标的移动

  1. #include <stdio.h>    
  2. #include <unistd.h>    
  3.     
  4. // 清除屏幕    
  5. #define CLEAR() printf("\033[2J")    
  6.     
  7. // 上移光标    
  8. #define MOVEUP(x) printf("\033[%dA", (x))    
  9.     
  10. // 下移光标    
  11. #define MOVEDOWN(x) printf("\033[%dB", (x))    
  12.     
  13. // 左移光标    
  14. #define MOVELEFT(y) printf("\033[%dD", (y))    
  15.     
  16. // 右移光标    
  17. #define MOVERIGHT(y) printf("\033[%dC",(y))    
  18.     
  19. // 定位光标    
  20. #define MOVETO(x,y) printf("\033[%d;%dH", (x), (y))    
  21.     
  22. // 光标复位    
  23. #define RESET_CURSOR() printf("\033[H")    
  24.     
  25. // 隐藏光标    
  26. #define HIDE_CURSOR() printf("\033[?25l")    
  27.     
  28. // 显示光标    
  29. #define SHOW_CURSOR() printf("\033[?25h")    
  30.     
  31. //反显    
  32. #define HIGHT_LIGHT() printf("\033[7m")    
  33. #define UN_HIGHT_LIGHT() printf("\033[27m")    
  34.     
  35. int main(int argc,char **argv)    
  36. {    
  37. printf("\033[31mThe color,%s!\033[1m\n","haha");    
  38. printf("\033[31mThe color,%s!\033[4m\n","haha");    
  39. printf("\033[31mThe color,%s!\033[5m\n","haha");    
  40. printf("\033[31mThe color,%s!\033[7m\n","haha");    
  41. printf("\033[31mThe color,%s!\033[8m\n","haha");    
  42. printf("\033[31mThe color,%s!\033[0m\n","haha");    
  43. printf("\033[47;31mThe color,%s!\033[0m\n","haha");    
  44. printf("\033[47mThe color,%s!\033[0m\n","haha");    
  45. sleep(2);    
  46. printf("\033[47m%s!\033[5A\n","up 5");    
  47. sleep(2);    
  48. printf("\033[47m%s!\033[9B\n","down 9");    
  49. sleep(2);    
  50. printf("\033[47m%s!\033[19C\n","right 19");    
  51. printf("right19");    
  52. sleep(2);    
  53. printf("\033[47m%s!\033[10D\n","left 10");    
  54. printf("left 10");    
  55. sleep(2);    
  56. printf("\033[47m%s!\033[50;20H\n","move to y:50,x 20");    
  57. printf("y50 x 20");    
  58. sleep(2);    
  59. printf("\033[47m%s!\033[?25l\n","hide cursor");    
  60. sleep(2);    
  61. printf("\033[47m%s!\033[?25h\n","sow cursor");    
  62. sleep(2);    
  63. printf("\033[47m%s!\033[2J\n","clear scleen");    
  64. sleep(2);    
  65. system("reset");  
  66. return 0;    
  67. }
  • 0
    点赞
  • 7
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值