java如何设置控制台打印的字体颜色、背景、字体样式(idea设置打印字体样式)工具类 - 附插件方式
效果:
设置控制台打印字体颜色、背景、字体样式,java工具类
package org.dxl.log;import java.util.Arrays;/*** 在控制台按照传入格式输出 ** @author IT_CREAT* @date 2021 2021/1/17/017 4:49 */
public class ColorPrint {/*** 分号*/private static final String SEMICOLON = ";";/*** 默认黑色打印** @param txt 信息*/public static void outPrintln(String txt) {System.out.println(format(txt, PrintCode.BLACK));}/*** 换行打印** @param txt 信息* @param codes 格式化参数*/public static void outPrintln(String txt, PrintCode... codes) {System.out.println(format(txt, codes));}/*** 不换行打印** @param txt 打印内容* @param codes 格式化参数*/public static void outPrint(String txt, PrintCode... codes) {System.out.print(format(txt, codes));}/*** 默认红色打印** @param txt 信息*/public static void errorPrintln(String txt) {System.err.println(format(txt, PrintCode.RED));}/*** 换行打印** @param txt 信息* @param codes 格式化参数*/public static void errorPrintln(String txt, PrintCode... codes) {System.err.println(format(txt, codes));}/*** 不换行打印** @param txt 打印内容* @param codes 格式化参数*/public static void errorPrint(String txt, PrintCode... codes) {System.err.print(format(txt, codes));}/*** 格式化信息** @param txt 信息* @param codes 参数集合* @return 格式化后的信息*/private static String format(String txt, PrintCode... codes) {String codeStr = String.join(SEMICOLON, Arrays.stream(codes).map((printCode) -> String.valueOf(printCode.getCode())).toArray(String[]::new));return (char) 27 + "[" + codeStr + "m" + txt + (char) 27 + "[0m";}/*** 打印样例*/public static void printExample() {ColorPrint.outPrintln("样例提示:黑色字体和黑色背景是一个取反色,和整体控制台主题背景有关,主题背景如果为深色,则相应的字体和背景变为白色,反之黑色",ColorPrint.PrintCode.BOLD, ColorPrint.PrintCode.UNDERLINE);ColorPrint.outPrintln("");ColorPrint.outPrintln("灰色(ColorPrint.PrintCode.GREY)", ColorPrint.PrintCode.GREY);ColorPrint.outPrintln("黑色(ColorPrint.PrintCode.BLACK)", ColorPrint.PrintCode.BLACK);ColorPrint.outPrintln("红色(ColorPrint.PrintCode.RED)", ColorPrint.PrintCode.RED);ColorPrint.outPrintln("绿色(ColorPrint.PrintCode.GREEN)", ColorPrint.PrintCode.GREEN);ColorPrint.outPrintln("黄色(ColorPrint.PrintCode.YELLOW)", ColorPrint.PrintCode.YELLOW);ColorPrint.outPrintln("蓝色(ColorPrint.PrintCode.BLUE)", ColorPrint.PrintCode.BLUE);ColorPrint.outPrintln("品红(ColorPrint.PrintCode.MAGENTA)", ColorPrint.PrintCode.MAGENTA);ColorPrint.outPrintln("蓝绿(ColorPrint.PrintCode.CYAN)", ColorPrint.PrintCode.CYAN);ColorPrint.outPrintln("黑色背景(ColorPrint.PrintCode.BLACK_BACKGROUND)",ColorPrint.PrintCode.GREY, ColorPrint.PrintCode.BLACK_BACKGROUND);ColorPrint.outPrintln("红色背景(ColorPrint.PrintCode.RED_BACKGROUND)",ColorPrint.PrintCode.BLACK, ColorPrint.PrintCode.RED_BACKGROUND);ColorPrint.outPrintln("绿色背景(ColorPrint.PrintCode.GREEN_BACKGROUND)",ColorPrint.PrintCode.BLACK, ColorPrint.PrintCode.GREEN_BACKGROUND);ColorPrint.outPrintln("黄色背景(ColorPrint.PrintCode.YELLOW_BACKGROUND)",ColorPrint.PrintCode.BLACK, ColorPrint.PrintCode.YELLOW_BACKGROUND);ColorPrint.outPrintln("蓝色背景(ColorPrint.PrintCode.BLUE_BACKGROUND)",ColorPrint.PrintCode.BLACK, ColorPrint.PrintCode.BLUE_BACKGROUND);ColorPrint.outPrintln("品红背景(ColorPrint.PrintCode.MAGENTA_BACKGROUND)",ColorPrint.PrintCode.BLACK, ColorPrint.PrintCode.MAGENTA_BACKGROUND);ColorPrint.outPrintln("蓝绿背景(ColorPrint.PrintCode.CYAN_BACKGROUND)",ColorPrint.PrintCode.BLACK, ColorPrint.PrintCode.CYAN_BACKGROUND);ColorPrint.outPrintln("灰色背景(ColorPrint.PrintCode.GREY_BACKGROUND)",ColorPrint.PrintCode.BLACK, ColorPrint.PrintCode.GREY_BACKGROUND);ColorPrint.outPrintln("默认字体(不传入其它参数)");ColorPrint.outPrintln("加粗(ColorPrint.PrintCode.BOLD)", ColorPrint.PrintCode.BOLD);ColorPrint.outPrintln("斜体(ColorPrint.PrintCode.ITALIC)", ColorPrint.PrintCode.ITALIC);ColorPrint.outPrintln("下划线(ColorPrint.PrintCode.UNDERLINE)", ColorPrint.PrintCode.UNDERLINE);ColorPrint.outPrintln("示例:灰底/黑字/加粗/下划线/倾斜(ColorPrint.PrintCode.GREY_BACKGROUND," +"ColorPrint.PrintCode.BLACK,ColorPrint.PrintCode.BOLD," +"ColorPrint.PrintCode.UNDERLINE,ColorPrint.PrintCode.ITALIC)",ColorPrint.PrintCode.GREY_BACKGROUND, ColorPrint.PrintCode.BLACK,ColorPrint.PrintCode.BOLD, ColorPrint.PrintCode.UNDERLINE, ColorPrint.PrintCode.ITALIC);}/*** 控制台信息格式化参数*/public enum PrintCode {/*** 黑色*/BLACK(30),/*** 黑色背景*/BLACK_BACKGROUND(40),/*** 红色*/RED(31),/*** 红色背景*/RED_BACKGROUND(41),/*** 绿色*/GREEN(32),/*** 绿色背景*/GREEN_BACKGROUND(42),/*** 黄色*/YELLOW(33),/*** 黄色背景*/YELLOW_BACKGROUND(43),/*** 蓝色*/BLUE(34),/*** 蓝色背景*/BLUE_BACKGROUND(44),/*** 品红(洋红)*/MAGENTA(35),/*** 品红背景*/MAGENTA_BACKGROUND(45),/*** 蓝绿*/CYAN(36),/*** 蓝绿背景*/CYAN_BACKGROUND(46),/*** 灰色*/GREY(37),/*** 灰色背景*/GREY_BACKGROUND(47),/*** 粗体*/BOLD(1),/*** 斜体*/ITALIC(3),/*** 下划线*/UNDERLINE(4);private final int code;PrintCode(int code) {this.code = code;}public int getCode() {return code;}}
}
Grep Console
或者安装插件:Grep Console(主要针对日志打印,插件是对打印内容正则匹配)
该插件是利用正则进行匹配,比如默认配置中的关键字,也就是Expression这一列,默认是大写的日志级别关键字,所以我们只需要在打印的字符中含有关键字,就会匹配到
public static void main(String[] args) {System.out.println("测试警告[WARN]");}
效果:
插件搜索安装:settings–》plugins
设置样式:
java如何设置控制台打印的字体颜色、背景、字体样式(idea设置打印字体样式)工具类 - 附插件方式相关推荐
- phpexcel中文教程-设置表格字体颜色背景样式、数据格式、对齐方式、添加图片、批注、文字块、合并拆分单元格、单元格密码保护
转载连接:http://www.cnblogs.com/huangcong/p/3687665.html phpexcel中文教程-设置表格字体颜色背景样式.数据格式.对齐方式.添加图片.批注.文字块 ...
- printf log管理终极版本——printf字体颜色格式与log级别设置
1.printf字体格式设置与printf颜色设置 在平常的调试中,printf字体格式与颜色都是默认一致的. 如果可以根据log信息的重要程度,配以不同的颜色与格式,可以很方便的查找到要点. pri ...
- java字体颜色编程_java Applet 程序设计讲解2 字体,颜色的使用
java Applet 程序设计讲解2 字体,颜色的使用 关键词: 字体 颜色 图形界面输出用到的字体,颜色的使用 1.字体类 (Font类) 构造方法: Font(String fontnam ...
- python3-xlwt-Excel设置表格基础(字体颜色 背景颜色 设置边框 边框颜色 冻结窗口 字体大小 字体高度 字体加粗 下划线 斜体字 单元格对齐方式 自动换行 删除线 超链接 插入公式)
文章目录 引入xlwt和创建workboos对象 初始化样式和创建设置字体,赋值给style 保存文件 自定义样式 字体颜色 背景颜色 设置边框 边框颜色 冻结窗口 字体大小 字体高度 字体加粗 下划 ...
- JAVA之旅(五)——this,static,关键字,main函数,封装工具类,生成javadoc说明书,静态代码块...
JAVA之旅(五)--this,static,关键字,main函数,封装工具类,生成javadoc说明书,静态代码块 周末收获颇多,继续学习 一.this关键字 用于区分局部变量和成员变量同名的情况 ...
- java 怎样设置文本域的字体颜色_java的JTextArea中怎么改变字体颜色
展开全部 java swing 中JTEXTAREA不能改变字体颜色,它是纯文本组件,可以使用JTEXTPANE,通过操作DOCUMENT文档来控制JTEXTPANE显示的内容,下面的代码在一个323 ...
- phpexcel 设置批注_PHPExcel-设置表格字体颜色背景样式、数据格式、对齐方式、添加图片、批注、文字块、合并拆分单元格、单元格密码保护...
首先到phpexcel官网上下载最新的phpexcel类,下周解压缩一个classes文件夹,里面包含了PHPExcel.php和PHPExcel的文件夹,这个类文件和文件夹是我们需要的,把class ...
- 黄聪:phpexcel中文教程-设置表格字体颜色背景样式、数据
首先到phpexcel官网上下载最新的phpexcel类,下周解压缩一个classes文件夹,里面包含了PHPExcel.php和PHPExcel的文件夹,这个类文件和文件夹是我们需要的,把class ...
- phpexcel 设置批注_phpexcel中文教程-设置表格字体颜色背景样式、数据格式、对齐方式、添加图片、批注、文字块、合并拆分单元格、单元格密码保护...
转:http://www.cnblogs.com/huangcong/p/3687665.html 首先到phpexcel官网上下载最新的phpexcel类,下周解压缩一个classes文件夹,里面包 ...
最新文章
- Python 实现 csv文件转换成json文件
- Android之drawlayout使用和总结
- 漂亮又好用的Redis可视化客户端汇总
- POJ2750 Potted Flower (线段树+动态规划)
- DC学院学习笔记 (十):SQLite及MongoDB
- (转)200亿美元比特币找不到主人,这个邪恶职业一夜爆火
- Python 实现定时任务
- 【Django】(一)django的下载、安装、配置及创建项目等
- android不透明度对应的值
- SpringBoot中的SearchStrategy介绍
- 关于ruby on rails启动服务器 Webpacker configuration file not found问题
- ios 出现log不打印 was compiled with optimization - stepping may behave oddly; variables may not be availa
- opencart seo优化_「opencart seo插件」wordpress SEO插件都有哪些好用的?...
- Transformer如何用于大规模图像识别?
- 用JavaScript查找斜边
- 数据库原理-SQL Server版(期末复习)
- 利用PS快速抠图的5个超实用技巧
- 阵列信号DOA估计系列(二).导向矢量与空间FFT(附代码)
- 步进电机的技术参数 控制及其应用
- python私活平台_【Python兼职】,Python开发接单接私活,Python程序员外包平台-程序员客栈...
热门文章
- 巧妙的通过二维码在手机和电脑传递小量数据
- Java实现输出特殊偏旁的汉字的功能
- 基于AST抽象语法树的SQL注入检测 (2) -- 每周小结(01-02~01-08) - .Little Hann
- odoo:开源 ERP/CRM 入门与实践
- 哎,为了在vs上开发或调试linux,各种跪啊。而且后面还有更多……
- STM32CUBEIDE使用说明
- 关于7z各种不能用的操作解决办法 7za 7z x Error: Can not open file as archive there is no such archive
- springBoot使用poi导出Excel
- 怎么恢复qq空间删除的日志文件呢
- mysql数据库存储引擎