Linux彩色输出
在linux下,可以使用一些宏,加上自定义格式输出,让输出更易于调试:
排版出来可能有些乱,注意do{ }while(0);是在一行里就可以了。
- #include <stdio.h>
- #include <stdlib.h>
- #define DEBUG1( fmt, arg ... ) \
- do{printf("[DEBUG] " fmt , ##arg ); }while(0);
- #define DEBUG2( fmt, arg ... ) \
- do{printf("[%s: %s: line %d]" fmt ,\
- __FILE__, __FUNCTION__, __LINE__, ##arg ); }while(0);
- #define PrintColor1( fmt, arg ... ) \
- do{printf("\033[30m""[%s: %s: line %d]" fmt"\033[0m" ,\
- __FILE__, __FUNCTION__, __LINE__, ##arg ); }while(0);
- #define PrintColor2( fmt, arg ... ) \
- do{printf("\033[31m""[%s: %s: line %d]" fmt"\033[0m" ,\
- __FILE__, __FUNCTION__, __LINE__, ##arg ); }while(0);
- #define PrintColor3( fmt, arg ... ) \
- do{printf("\033[32m""[%s: %s: line %d]" fmt"\033[0m" ,\
- __FILE__, __FUNCTION__, __LINE__, ##arg ); }while(0);
- #define PrintColor4( fmt, arg ... ) \
- do{printf("\033[33m""[%s: %s: line %d]" fmt"\033[0m" ,\
- __FILE__, __FUNCTION__, __LINE__, ##arg ); }while(0);
- #define PrintColor5( fmt, arg ... ) \
- do{printf("\033[34m""[%s: %s: line %d]" fmt"\033[0m" ,\
- __FILE__, __FUNCTION__, __LINE__, ##arg ); }while(0);
- #define PrintColor6( fmt, arg ... ) \
- do{printf("\033[35m""[%s: %s: line %d]" fmt"\033[0m" ,\
- __FILE__, __FUNCTION__, __LINE__, ##arg ); }while(0);
- #define PrintColor7( fmt, arg ... ) \
- do{printf("\033[36m""[%s: %s: line %d]" fmt"\033[0m" ,\
- __FILE__, __FUNCTION__, __LINE__, ##arg ); }while(0);
- int main()
- {
- printf("I AM IN macro.c\n");
- DEBUG1("I AM IN macro.c\n");
- DEBUG2("I AM IN macro.c\n");
- PrintColor1("I AM IN macro.c\n");
- PrintColor2("I AM IN macro.c\n");
- PrintColor3("I AM IN macro.c\n");
- PrintColor4("I AM IN macro.c\n");
- PrintColor5("I AM IN macro.c\n");
- PrintColor6("I AM IN macro.c\n");
- PrintColor7("I AM IN macro.c\n");
- return 0;
- }
输出结果:
- http://blog.csdn.net/xiangpingli/article/details/7914133
Linux彩色输出的更多相关文章
- linux打印彩色输出
在终端生成彩色输出,我们可以使用转义序列来实现. 每种颜色都有对应的颜色码.比如:重置=0,黑色=30,红色=31,绿色=32,黄色=33,蓝色=34,洋红=35,青色=36,白色=37 要打印彩色文 ...
- std::cout彩色输出
Mac OS效果 Windows 效果 想写这个东西其实是因为最近要写个命令行的工具,但是有个问题是什么呢?就是传统的那个黑漆漆的窗口看起来很蛋疼.并且完全看不到重点,于是就想起 来这么一个东西.相对 ...
- SpringBoot之彩色输出
spring.output.ansi.enabled NEVER:禁用ANSI-colored输出(默认项) DETECT:会检查终端是否支持ANSI,是的话就采用彩色输出(推荐项) ALWAYS:总 ...
- Linux seq_printf输出内容不完整的问题
Linux seq_printf输出内容不完整的问题 写在前面的话:这是多年前在项目中遇到的问题,作为博客的开篇之作,有不足之处,请各位大侠斧正!谢谢! seq_file接口介绍 有许多种方法能够实现 ...
- Git设置彩色输出
彩色输出 git config --global color.status auto git config --global color.diff auto git config --global c ...
- Linux下输出 excel文件
Linux下输出 excel文件 今日提供给产品需求,需excel文件,故总结要点如下: 1.默认间隔是space_20 2.修改为TAB \t _09 awk ' BEGIN { OFS=&quo ...
- Linux命令输出头(标题)、输出结果排序技巧
原文:http://blog.csdn.net/hongweigg/article/details/65446007 ----------------------------------------- ...
- 花里胡哨,如何在Linux终端输出带有颜色的字体,将带颜色的字体赋值给变量
背景 在日常操作Linux的情况下,总会遇到一些需求,比如说,把输出的内容用不同颜色标注出来,以达到醒目.提示的目的,那么如何在Linux终端输出带有颜色的字体呢? Linux终端输出字符颜色 ...
- 通过printf设置Linux终端输出的颜色和显示方式
转载自:http://www.cnblogs.com/clover-toeic/p/4031618.html 在Linux终端下调试程序时,有时需要输出大量信息.若能控制字体的颜色和显示方式,可使输出 ...
随机推荐
- 启动程序的c++方法
#include <Windows.h> void main() { WinExec( "notepad.exe fitdata.txt", SW_SHOW ); // ...
- HTML5 canvas绘制线条曲线
HTML5 canvas入门 线条例子 1.简单线条 2.三角形 3.填充三角形背景颜色 4.线条颜色以及线条大小 5.二次贝塞尔曲线 6.三次贝塞尔曲线 <!doctype html> ...
- 以Ajax的方式访问数据库
一:以Ajax的方式显示数据 我们都知道,如果用Ajax程序去加载一个动态页,则加载的实际上是这个动态页执行完毕后生成的静态HTML代码字符串. 1.以原有的格式显示数据 <?php heade ...
- codevs 1913 数字梯形问题 费用流
题目链接 给你一个数字梯形, 最上面一层m个数字, 然后m+1,......m+n-1个. n是层数. 在每个位置, 可以向左下或右下走.然后让你从最顶端的m个数字开始, 走出m条路径, 使得路过的数 ...
- SpringDataRedis事务处理
public Long leftPush(V value) { return this.ops.leftPush(this.getKey(), value); } public Long leftPu ...
- elasticsearch 索引 类型 id
zjtest7-frontend:/usr/local/logstash-2.3.4/config# cat logstash_indexer01.conf input { redi ...
- POJ——位查询
3:位查询 查看 提交 统计 提问 总时间限制: 5000ms 内存限制: 65536kB 描述 给出N个范围在[0, 65535]的整数,编程支持以下的操作: (1)修改操作:C d,所有的数 ...
- 弗洛伊德(Floyd)算法
#include <stdio.h> #define MAXVEX 20 //最大顶点数 #define INFINITY 65535 //∞ typedef struct {/* 图结构 ...
- iOS使用sqlite3原生语法进行增删改查以及FMDB的使用
首先要导入libsqlite3.dylib并且加入头文件#import <sqlite3.h>,在进行增删改查之前还要先把数据库搞进去. 一种方法是从外面拷贝到程序里:http://www ...
- [置顶] hdu2815 扩展Baby step,Giant step入门
题意:求满足a^x=b(mod n)的最小的整数x. 分析:很多地方写到n是素数的时候可以用Baby step,Giant step, 其实研究过Baby step,Giant step算法以后,你会 ...