⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 cusor_ctrl.c

📁 cusor_ctrl : 利用 ESC code实现linux下光标位置控制的模块
💻 C
字号:
//cusor_ctrl.c
#include"cusor_ctrl.h"

int ESC = 27; 

//清屏
void clear_screen(void)
{// ESC[2J
    printf("%c[2J",ESC);
    fflush(stdout);
}

//清除从光标位置到行末的内容
void clear_to_end(void)
{// ESC[K
    printf("%c[K",ESC); fflush(stdout);} //光标移动到(x,y)
void cusor_moveto(int x, int y)
{// ESC[y;xH
    printf("%c[%d;%dH",ESC,y,x);
    fflush(stdout);
} 

//保存光标位置
void cusor_get_pos(void)
{// ESC[s
    printf("%c[s",ESC);
    fflush(stdout);
} 

//恢复光标位置
void cusor_set_pos(void)
{// ESC[u
    printf("%c[u",ESC);
    fflush(stdout);
} 

//光标上移num行
void cusor_up(int num)
{
    while(num--)
    { // up =  ESC[A 
        printf("%c[A",ESC);
    }    
    fflush(stdout);
} 

//光标下移num行
void cusor_down(int num)
{
    while(num--)
    {// down = ESC[B
        printf("%c[B",ESC);                
    }
    fflush(stdout);
} 

//光标左移num个字符
void cusor_lift(int num)
{
    while(num--)
    {// lift = ESC[D
        printf("%c[D",ESC);                
    }
    fflush(stdout);
} 

//光标右移num个字符
void cusor_right(int num)
{
    while(num--)
    {// right = ESC[C
        printf("%c[C",ESC);                
    }
    fflush(stdout);
}

//设置前景颜色
void set_fg_color(int color)
{// ESC[#m
    printf("%c[%dm",ESC,color);
    fflush(stdout);
} 

//设置背景颜色
void set_bg_color(int color)
{// ESC[#m
    printf("%c[%dm",ESC,(color+10));
    fflush(stdout);
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -