first commit

This commit is contained in:
2021-08-29 00:02:47 +08:00
commit 01e8b33396
52 changed files with 4404 additions and 0 deletions

View 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)

View 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);
}

View 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_

Binary file not shown.

View 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;
}