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终端下调试程序时,有时需要输出大量信息.若能控制字体的颜色和显示方式,可使输出 ...
随机推荐
- MFC对话框中解决回车键、ESC键退出的方法
BOOL CYourDlg::PreTranslateMessage(MSG* pMsg) { if(pMsg->message==WM_KEYDOWN&&pMsg->wP ...
- js常用DOM操作
在博客园看到了苏夏写的常用DOM整理文章,地址:http://www.cnblogs.com/cabbagen/p/4579412.html,然后抽时间都试了一下这些常用的DOM操作.在这里记录一下. ...
- 关于css3的边框的border-radius和border-image用法的详解
一.圆角边框:IE9.0以前版本不支持 border-radius: 接受8个属性,前四个为x轴,后四个为y轴,以斜杠划分x轴.y轴,即border-radius:左上较 右上角 右下角 左下 ...
- scroll运用、图片悬浮
scroll 滚动条 长话短说进入正题: scrollTOP==0 内容置于顶部: scrollTOP()>=$(document).height-$(window).height 内容置于底部 ...
- react native调试
进入安卓终端 /usr/local/android-sdk-linux/platform-tools/adb shell 网络错误,模拟器不能连接主机,主要问题有2个: 移动端网络设置错误 服务没有启 ...
- Python学习路径和个人增值(整合版)
PS:内容来源于网络 一.简介 Python是一种面向对象.直译式计算机程序设计语言,由Guido van Rossum于1989年底发明.由于他简单.易学.免费开源.可移植性.可扩展 ...
- 根据群ID和用户Id查询 + string QueryQunByUserIdAndQunId(int userId, int qunId) V1.0
#region 根据群ID和用户Id查询 + string QueryQunByUserIdAndQunId(int userId, int qunId) V1.0 /// <summary ...
- Struts2技术详解(转)
1, 当Action设置了某个属性后,Struts将这些属性封装一个叫做Struts.valueStack的属性里.获取valueStack对象: ValueStack vs = (ValueStac ...
- InputStream读取文件到string后OutputStream到文件,按String和Bytes拷贝
http://www.iteye.com/problems/72150 写了一段代码 大体是 InputStream读取文件到string后OutputStream到文件 遇到的问题为TXT文件大小格 ...
- #include <process.h>
1 _beginthread 单进程,单线程,必须干完一件事情后干另一件事情 #define _CRT_SECURE_NO_WARNINGS #include<stdio.h> #incl ...