标签:RichPrint 封装 打印输出 Color Style js content print null
/**
* 字体样式
*/
class Style {
}
Style.DEFAULT = 0;
Style.HIGHLIGHT = 1;
Style.NOTBOLD = 22;
Style.UNDERLINE = 4;
Style.NOTUNDERLINE = 24;
Style.BLINK = 5;
Style.NOTBLINK = 25;
Style.ANTIDISPLAY = 7
Style.NOTANTIDISPLAY = 27;
/**
* 颜色类枚举,因为前景色和背景色相同颜色差值10,所以颜色用同一个枚举表示
*/
class Color {
}
Color.BLACK = 30;
Color.RED = 31;
Color.GREEN = 32;
Color.YELLOW = 33;
Color.BLUE = 34;
Color.PINK = 35;
Color.AQUA = 36;
Color.WHITE = 37;
/**
* 打印到控制台时可以同时设置样式
*/
class RichPrint {
static generateCmdContent(content,style,foregroundColor,backgroundColor) {
const temp = [];
if(style) {
temp.push(style);
}
if (foregroundColor) {
temp.push(foregroundColor);
}
if (backgroundColor) {
temp.push(backgroundColor + 10);
}
return '\x1b['+temp.join(';')+'m' + content+'\x1b[0m';
}
static print(content,style,foregroundColor,backgroundColor) {
console.log(RichPrint.generateCmdContent(content,style,foregroundColor,backgroundColor));
}
static printBlack(content) {
RichPrint.print(content,null,Color.BLACK,null);
}
static printRed(content) {
RichPrint.print(content,null,Color.RED,null);
}
static printGreen(content) {
RichPrint.print(content,null,Color.GREEN,null);
}
static printYellow(content) {
RichPrint.print(content,null,Color.YELLOW,null);
}
static printBlue(content) {
RichPrint.print(content,null,Color.BLUE,null);
}
static printPink(content) {
RichPrint.print(content,null,Color.PINK,null);
}
static printAqua(content) {
RichPrint.print(content,null,Color.AQUA,null);
}
static printWhite(content) {
RichPrint.print(content,null,Color.WHITE,null);
}
}
RichPrint.print("这是一段测试文本",Style.UNDERLINE, Color.AQUA,Color.PINK);
RichPrint.print("这是一段测试文本",null, Color.BLUE,Color.RED);
RichPrint.printGreen("测试文本2");
测试结果
标签:RichPrint,封装,打印输出,Color,Style,js,content,print,null 来源: https://blog.csdn.net/weixin_43069875/article/details/111712459
本站声明: 1. iCode9 技术分享网(下文简称本站)提供的所有内容,仅供技术学习、探讨和分享; 2. 关于本站的所有留言、评论、转载及引用,纯属内容发起人的个人观点,与本站观点和立场无关; 3. 关于本站的所有言论和文字,纯属内容发起人的个人观点,与本站观点和立场无关; 4. 本站文章均是网友提供,不完全保证技术分享内容的完整性、准确性、时效性、风险性和版权归属;如您发现该文章侵犯了您的权益,可联系我们第一时间进行删除; 5. 本站为非盈利性的个人网站,所有内容不会用来进行牟利,也不会利用任何形式的广告来间接获益,纯粹是为了广大技术爱好者提供技术内容和技术思想的分享性交流网站。