first commit
This commit is contained in:
94
光标操作/Print_Esc.c
Normal file
94
光标操作/Print_Esc.c
Normal file
@@ -0,0 +1,94 @@
|
||||
#include "Print_Esc.h"
|
||||
|
||||
//<2F><><EFBFBD><EFBFBD>
|
||||
void clear_screen(void)
|
||||
{// ESC[2J
|
||||
printf("\033[2J");
|
||||
fflush(stdout);
|
||||
}
|
||||
|
||||
//<2F><><EFBFBD><EFBFBD><EFBFBD>ӹ<EFBFBD><D3B9><EFBFBD>λ<EFBFBD>õ<EFBFBD><C3B5><EFBFBD>ĩ<EFBFBD><C4A9><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||
void clear_to_end(void)
|
||||
{// ESC[K
|
||||
printf("\033[K");
|
||||
fflush(stdout);
|
||||
|
||||
} //<2F><><EFBFBD><EFBFBD><EFBFBD>ƶ<EFBFBD><C6B6><EFBFBD>(x,y)
|
||||
|
||||
void cusor_moveto(int x, int y)
|
||||
{// ESC[y;xH
|
||||
printf("\033[%d;%dH",y,x);
|
||||
fflush(stdout);
|
||||
}
|
||||
|
||||
//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>λ<EFBFBD><CEBB>
|
||||
void cusor_get_pos(void)
|
||||
{// ESC[s
|
||||
printf("\033[s");
|
||||
fflush(stdout);
|
||||
}
|
||||
|
||||
//<2F>ָ<EFBFBD><D6B8><EFBFBD><EFBFBD><EFBFBD>λ<EFBFBD><CEBB>
|
||||
void cusor_set_pos(void)
|
||||
{// ESC[u
|
||||
printf("\033[u");
|
||||
fflush(stdout);
|
||||
}
|
||||
|
||||
//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>num<75><6D>
|
||||
void cusor_up(int num)
|
||||
{
|
||||
while(num--)
|
||||
{ // up = ESC[A
|
||||
printf("\033[A");
|
||||
}
|
||||
fflush(stdout);
|
||||
}
|
||||
|
||||
//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>num<75><6D>
|
||||
void cusor_down(int num)
|
||||
{
|
||||
while(num--)
|
||||
{// down = ESC[B
|
||||
printf("\033[B");
|
||||
}
|
||||
fflush(stdout);
|
||||
}
|
||||
|
||||
//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>num<75><6D><EFBFBD>ַ<EFBFBD>
|
||||
void cusor_lift(int num)
|
||||
{
|
||||
while(num--)
|
||||
{// lift = ESC[D
|
||||
printf("\033[D");
|
||||
}
|
||||
fflush(stdout);
|
||||
}
|
||||
|
||||
//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>num<75><6D><EFBFBD>ַ<EFBFBD>
|
||||
void cusor_right(int num)
|
||||
{
|
||||
while(num--)
|
||||
{ // right = ESC[C
|
||||
printf("\033[C");
|
||||
}
|
||||
fflush(stdout);
|
||||
}
|
||||
|
||||
//<2F><><EFBFBD><EFBFBD>ǰ<EFBFBD><C7B0><EFBFBD><EFBFBD>ɫ
|
||||
void set_fg_color(int color)
|
||||
{// ESC[#m
|
||||
printf("\033[%dm",color);
|
||||
fflush(stdout);
|
||||
}
|
||||
|
||||
//<2F><><EFBFBD>ñ<EFBFBD><C3B1><EFBFBD><EFBFBD><EFBFBD>ɫ
|
||||
void set_bg_color(int color)
|
||||
{// ESC[#m
|
||||
printf("\033[%dm",(color+10));
|
||||
fflush(stdout);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
34
光标操作/Print_Esc.h
Normal file
34
光标操作/Print_Esc.h
Normal file
@@ -0,0 +1,34 @@
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
#define COLOR_RED 31
|
||||
#define COLOR_BLACK 30
|
||||
#define COLOR_GREEN 32
|
||||
#define COLOR_BLUE 34
|
||||
#define COLOR_YELLOW 33
|
||||
#define COLOR_WHITE 37
|
||||
#define COLOR_CYAN 36
|
||||
#define COLOR_MAGENTA 35
|
||||
|
||||
//<2F><><EFBFBD><EFBFBD>
|
||||
void clear_screen(void);
|
||||
//<2F><><EFBFBD><EFBFBD><EFBFBD>ӹ<EFBFBD><D3B9><EFBFBD>λ<EFBFBD>õ<EFBFBD><C3B5><EFBFBD>ĩ<EFBFBD><C4A9><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||
void clear_to_end(void);
|
||||
//<2F><><EFBFBD><EFBFBD><EFBFBD>ƶ<EFBFBD><C6B6><EFBFBD>(x,y)
|
||||
void cusor_moveto(int x, int y);
|
||||
//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>λ<EFBFBD><CEBB>
|
||||
void cusor_get_pos(void);
|
||||
//<2F>ָ<EFBFBD><D6B8><EFBFBD><EFBFBD><EFBFBD>λ<EFBFBD><CEBB>
|
||||
void cusor_set_pos(void);
|
||||
//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>num<75><6D>
|
||||
void cusor_up(int num);
|
||||
//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>num<75><6D>
|
||||
void cusor_down(int num);
|
||||
//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>num<75><6D><EFBFBD>ַ<EFBFBD>
|
||||
void cusor_lift(int num);
|
||||
//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>num<75><6D><EFBFBD>ַ<EFBFBD>
|
||||
void cusor_right(int num);
|
||||
//<2F><><EFBFBD><EFBFBD>ǰ<EFBFBD><C7B0><EFBFBD><EFBFBD>ɫ
|
||||
void set_fg_color(int color);
|
||||
//<2F><><EFBFBD>ñ<EFBFBD><C3B1><EFBFBD><EFBFBD><EFBFBD>ɫ
|
||||
void set_bg_color(int color);
|
57
光标操作/console.c
Normal file
57
光标操作/console.c
Normal file
@@ -0,0 +1,57 @@
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include "console.h"
|
||||
|
||||
void cusor_moveto(int x, int y)
|
||||
{// ESC[y;xH
|
||||
printf("\033[%d;%dH",y,x);
|
||||
fflush(stdout);
|
||||
}
|
||||
|
||||
//保存光标位置
|
||||
void cusor_get_pos(void)
|
||||
{// ESC[s
|
||||
printf("\033[s");
|
||||
fflush(stdout);
|
||||
}
|
||||
|
||||
//恢复光标位置
|
||||
void cusor_set_pos(void)
|
||||
{// ESC[u
|
||||
printf("\033[u");
|
||||
fflush(stdout);
|
||||
}
|
||||
void cusor_hide(void)
|
||||
{
|
||||
printf("\033[?25l");
|
||||
}
|
||||
//清屏
|
||||
void clear_screen(void)
|
||||
{// ESC[2J
|
||||
printf("\033[2J");
|
||||
fflush(stdout);
|
||||
}
|
||||
|
||||
/*
|
||||
COLOR_RED 红
|
||||
COLOR_BLACK 黑
|
||||
COLOR_GREEN 绿
|
||||
COLOR_BLUE 蓝
|
||||
COLOR_YELLOW 黄
|
||||
COLOR_WHITE 白
|
||||
COLOR_CYAN 青
|
||||
COLOR_MAGENTA 洋红
|
||||
*/
|
||||
//设置前景颜色
|
||||
void set_fg_color(int color)
|
||||
{// ESC[#m
|
||||
printf("\033[%dm",color);
|
||||
fflush(stdout);
|
||||
}
|
||||
|
||||
//设置背景颜色
|
||||
void set_bg_color(int color)
|
||||
{// ESC[#m
|
||||
printf("\033[%dm",(color+10));
|
||||
fflush(stdout);
|
||||
}
|
33
光标操作/console.h
Normal file
33
光标操作/console.h
Normal file
@@ -0,0 +1,33 @@
|
||||
#ifndef _CONSOLE_H_
|
||||
#define _CONSOLE_H_
|
||||
|
||||
#define COLOR_RED 31
|
||||
#define COLOR_BLACK 30
|
||||
#define COLOR_GREEN 32
|
||||
#define COLOR_BLUE 34
|
||||
#define COLOR_YELLOW 33
|
||||
#define COLOR_WHITE 37
|
||||
#define COLOR_CYAN 36
|
||||
#define COLOR_MAGENTA 35
|
||||
/*
|
||||
COLOR_RED 红
|
||||
COLOR_BLACK 黑
|
||||
COLOR_GREEN 绿
|
||||
COLOR_BLUE 蓝
|
||||
COLOR_YELLOW 黄
|
||||
COLOR_WHITE 白
|
||||
COLOR_CYAN 青
|
||||
COLOR_MAGENTA 洋红
|
||||
*/
|
||||
|
||||
extern void cusor_moveto(int x, int y);//光标跳转到 y行 x列
|
||||
extern void cusor_get_pos(void);//保存光标位置
|
||||
extern void cusor_hide(void);
|
||||
extern void cusor_set_pos(void);//恢复光标位置
|
||||
extern void clear_screen(void);//清屏
|
||||
extern void set_fg_color(int color);//设置字体前景色
|
||||
extern void set_bg_color(int color);//设置字体背景色
|
||||
|
||||
#endif //_CONSOLE_H_
|
||||
|
||||
|
15
光标操作/cursor_demo/Makefile
Normal file
15
光标操作/cursor_demo/Makefile
Normal file
@@ -0,0 +1,15 @@
|
||||
CC=gcc
|
||||
obj=console.o test.o
|
||||
target=test
|
||||
CFLAGS=-Wall
|
||||
|
||||
$(target):$(obj)
|
||||
@$(CC) $^ -o $@ $(CFLAGS)
|
||||
test.o:test.c
|
||||
@$(CC) -c $< -o $@ $(CFLAGS)
|
||||
console.o:console.c
|
||||
@$(CC) -c $< -o $@ $(CFLAGS)
|
||||
|
||||
|
||||
clean:
|
||||
@rm $(obj) $(target)
|
63
光标操作/cursor_demo/console.c
Normal file
63
光标操作/cursor_demo/console.c
Normal file
@@ -0,0 +1,63 @@
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include "console.h"
|
||||
|
||||
void cusor_moveto(int x, int y)
|
||||
{// ESC[y;xH
|
||||
printf("\033[%d;%dH",y,x);
|
||||
fflush(stdout);
|
||||
}
|
||||
|
||||
//保存光标位置
|
||||
void cusor_get_pos(void)
|
||||
{// ESC[s
|
||||
printf("\033[s");
|
||||
fflush(stdout);
|
||||
}
|
||||
|
||||
//恢复光标位置
|
||||
void cusor_set_pos(void)
|
||||
{// ESC[u
|
||||
printf("\033[u");
|
||||
fflush(stdout);
|
||||
}
|
||||
//隐藏光标
|
||||
void cusor_hide(void)
|
||||
{
|
||||
printf("\033[?25l");
|
||||
}
|
||||
//显示光标
|
||||
void cusor_show(void)
|
||||
{
|
||||
printf("\33[?25h");
|
||||
}
|
||||
//清屏
|
||||
void clear_screen(void)
|
||||
{// ESC[2J
|
||||
printf("\033[2J");
|
||||
fflush(stdout);
|
||||
}
|
||||
|
||||
/*
|
||||
COLOR_RED 红
|
||||
COLOR_BLACK 黑
|
||||
COLOR_GREEN 绿
|
||||
COLOR_BLUE 蓝
|
||||
COLOR_YELLOW 黄
|
||||
COLOR_WHITE 白
|
||||
COLOR_CYAN 青
|
||||
COLOR_MAGENTA 洋红
|
||||
*/
|
||||
//设置前景颜色
|
||||
void set_fg_color(int color)
|
||||
{// ESC[#m
|
||||
printf("\033[%dm",color);
|
||||
fflush(stdout);
|
||||
}
|
||||
|
||||
//设置背景颜色
|
||||
void set_bg_color(int color)
|
||||
{// ESC[#m
|
||||
printf("\033[%dm",(color+10));
|
||||
fflush(stdout);
|
||||
}
|
34
光标操作/cursor_demo/console.h
Normal file
34
光标操作/cursor_demo/console.h
Normal file
@@ -0,0 +1,34 @@
|
||||
#ifndef _CONSOLE_H_
|
||||
#define _CONSOLE_H_
|
||||
|
||||
#define COLOR_RED 31
|
||||
#define COLOR_BLACK 30
|
||||
#define COLOR_GREEN 32
|
||||
#define COLOR_BLUE 34
|
||||
#define COLOR_YELLOW 33
|
||||
#define COLOR_WHITE 37
|
||||
#define COLOR_CYAN 36
|
||||
#define COLOR_MAGENTA 35
|
||||
/*
|
||||
COLOR_RED 红
|
||||
COLOR_BLACK 黑
|
||||
COLOR_GREEN 绿
|
||||
COLOR_BLUE 蓝
|
||||
COLOR_YELLOW 黄
|
||||
COLOR_WHITE 白
|
||||
COLOR_CYAN 青
|
||||
COLOR_MAGENTA 洋红
|
||||
*/
|
||||
|
||||
extern void cusor_moveto(int x, int y);//光标跳转到 y行 x列
|
||||
extern void cusor_get_pos(void);//保存光标位置
|
||||
extern void cusor_hide(void);//隐藏光标
|
||||
extern void cusor_show(void);//显示光标
|
||||
extern void cusor_set_pos(void);//恢复光标位置
|
||||
extern void clear_screen(void);//清屏
|
||||
extern void set_fg_color(int color);//设置字体前景色
|
||||
extern void set_bg_color(int color);//设置字体背景色
|
||||
|
||||
#endif //_CONSOLE_H_
|
||||
|
||||
|
BIN
光标操作/cursor_demo/test
Normal file
BIN
光标操作/cursor_demo/test
Normal file
Binary file not shown.
14
光标操作/cursor_demo/test.c
Normal file
14
光标操作/cursor_demo/test.c
Normal file
@@ -0,0 +1,14 @@
|
||||
#include<stdio.h>
|
||||
#include"console.h"
|
||||
int main()
|
||||
{
|
||||
clear_screen();//<2F><><EFBFBD><EFBFBD>Ļ<EFBFBD><C4BB><EFBFBD><EFBFBD>
|
||||
cusor_moveto(20, 4);//<2F><><EFBFBD><EFBFBD><EFBFBD>Ƶ<EFBFBD> <20><>4<EFBFBD>У<EFBFBD><D0A3><EFBFBD>20<32><30>
|
||||
set_fg_color(COLOR_RED);//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ɫΪ<C9AB><CEAA>ɫ
|
||||
printf("hello ,i love China!!!\n");
|
||||
|
||||
cusor_moveto(20, 2);//<2F><><EFBFBD><EFBFBD><EFBFBD>Ƶ<EFBFBD> <20><>2<EFBFBD>У<EFBFBD><D0A3><EFBFBD>20<32><30>
|
||||
set_fg_color(COLOR_BLUE);//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ɫΪ<C9AB><CEAA>ɫ
|
||||
printf("hello ,i love sunplusapp!!\n");
|
||||
return 0;
|
||||
}
|
Reference in New Issue
Block a user