linux 程序创建控制台,linux 用c程序写整个控制台

linux 用c程序写整个控制台

我们知道使用

printf("test \n");

这样只能输出一行。而我们看到过很多程序,启动后程序占满整个控制台窗口,这是怎么做到的呢?

原理就是先清掉整个整个屏幕

system( "clear");

让后画满整个屏幕

这个也是通过

printf()

这个函数实现。

然后

画完一屏之后,

再次调用 system("clear");清屏,然后再画。

这个过程可以在工作线程中实现,主线程读取用户输入,用来控制屏幕画什么样的内容。

直接上程序,下面的程序使用下面的命令,编译

$ gcc draw_console.c -lpthread -o draw_console

运行程序:

$ ./draw_console

按s停止刷新,按r继续刷新,按q退出程序。

代码:

#include

#include

#include // for future trials with wide chars

#include // to set Unicode locale

#include

#include

#include

#include

#include

#define RB "\e(0\x6a\e(B" // 188 Right Bottom corner

#define RT "\e(0\x6b\e(B" // 187 Right Top corner

#define LT "\e(0\x6c\e(B" // 201 Left Top cornet

#define LB "\e(0\x6d\e(B" // 200 Left Bottom corner

#define MC "\e(0\x6e\e(B" // 206 Midle Cross

#define HL "\e(0\x71\e(B" // 205 Horizontal Line

#define LC "\e(0\x74\e(B" // 204 Left Cross

#define RC "\e(0\x75\e(B" // 185 Right Cross

#define BC "\e(0\x76\e(B" // 202 Bottom Cross

#define TC "\e(0\x77\e(B" // 203 Top Cross

#define VL "\e(0\x78\e(B" // 186 Vertical Line

#define SP " " // space string

#define TRUE 1

#define FALSE 0

// Move the whole box to the right 'RIGHT' number of spaces

#define RIGHT 8

// IF DBL_BOX TRUE draw a second box around

#define DBL_BOX TRUE

int g_bUpdate = 1;

/*

*/

//print number of box chars – two string variables

// if different able to print mixed box chars

// eg. first right cross, horizontal, right cross ect

// 'i' times.

void box_print(char *def_str1, char *def_str2, int i);

void print_nl(int i); // print 'i' number of newlines

// print string cgars withi

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值