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终端下调试程序时,有时需要输出大量信息.若能控制字体的颜色和显示方式,可使输出 ...
随机推荐
- php变量的引用及函数的引用
Php变量的引用及函数的引用放回 变量的引用 $a="ABC"; $b =&$a; echo $a;//这里输出:ABC echo $b;//这里输 ...
- php 生成唯一的订单
/** * 生成唯一的订单号 20110809111259232312 * 2011-年日期 * 08-月份 * 09-日期 * 11-小时 * 12-分 * 59-秒 * 2323-微秒 * 12- ...
- ES6新特性-----变量和字符串
一.变量 1. LET 我们都习惯用var 来声明变量,现在还可以用let来声明变量,两者的主要区别是作用域:var声明的变量作用域为包围它的函数,而let声明的变量作用域仅在它所在的块中.(在ES5 ...
- Java日期时间使用(转)
Java日期时间使用总结 转自:http://lavasoft.blog.51cto.com/62575/52975/ 一.Java中的日期概述 日期在Java中是一块非常复杂的内容,对于一个 ...
- EditPlus自动执行出结果设置
- Ajax学习教程在线阅读
1.什么是AJAX ?(1) 2.什么是AJAX ?(2) 3.什么是AJAX ?(3) 4.什么是AJAX ?(4) 5.Ajax基础教程(1)-Ajax简介 1.1 Web应用简史 6.Aja ...
- 畅通工程续(dijskra+SPFA)
畅通工程续 Time Limit : 3000/1000ms (Java/Other) Memory Limit : 32768/32768K (Java/Other) Total Submiss ...
- Java中Return和Finally运行顺序的实现
以下这段代码的运行结果是如何的呢? [java] view plaincopyprint? publc int test(){ int x; try{ ; return x; }catch(Excep ...
- STL的移动算法
要在自己定义类型中使用移动算法.须要在元素中提供移动赋值运算符.移动赋值运算符和std::move()详见<c++高级编程>第9章 class mystring { public: str ...
- C# 学习笔记 C#基础
今天第一天开通博客.恰好在学习C#,所以就准备把学到的知识要点记录下来. 基础类型 类型定义了值得蓝图.值是一个被变量或者常量所指定的存储位置,变量是指可以被改变的,而常量则相反,其值不可以便改变, ...