当前位置: 首页 > news >正文

单位网站建设情况总结微网站自己怎么做

单位网站建设情况总结,微网站自己怎么做,中文网址和中文域名区别,手机网站框架java-推荐一个控制台输出颜色ANSI字符的类 背景代码调用输出 背景 这个类是来自hive的一段代码,大家可以参考一下,这个类名是ColorBuffer 代码 /** Licensed to the Apache Software Foundation (ASF) under one* or more contributor license agreem…

java-推荐一个控制台输出颜色ANSI字符的类

    • 背景
    • 代码
    • 调用
    • 输出

背景

这个类是来自hive的一段代码,大家可以参考一下,这个类名是ColorBuffer

代码

/** Licensed to the Apache Software Foundation (ASF) under one* or more contributor license agreements.  See the NOTICE file* distributed with this work for additional information* regarding copyright ownership.  The ASF licenses this file* to you under the Apache License, Version 2.0 (the* "License"); you may not use this file except in compliance* with the License.  You may obtain a copy of the License at**     http://www.apache.org/licenses/LICENSE-2.0** Unless required by applicable law or agreed to in writing, software* distributed under the License is distributed on an "AS IS" BASIS,* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.* See the License for the specific language governing permissions and* limitations under the License.*//** This source file is based on code taken from SQLLine 1.0.2* See SQLLine notice in LICENSE*/
package MyCollections;import java.util.Iterator;
import java.util.LinkedList;
import java.util.List;/*** A buffer that can output segments using ANSI color.**/
final class ColorBuffer implements Comparable<Object> {private static final ColorAttr BOLD = new ColorAttr("\033[1m");private static final ColorAttr NORMAL = new ColorAttr("\033[m");private static final ColorAttr REVERS = new ColorAttr("\033[7m");private static final ColorAttr LINED = new ColorAttr("\033[4m");private static final ColorAttr GREY = new ColorAttr("\033[1;30m");private static final ColorAttr RED = new ColorAttr("\033[1;31m");private static final ColorAttr GREEN = new ColorAttr("\033[1;32m");private static final ColorAttr BLUE = new ColorAttr("\033[1;34m");private static final ColorAttr CYAN = new ColorAttr("\033[1;36m");private static final ColorAttr YELLOW = new ColorAttr("\033[1;33m");private static final ColorAttr MAGENTA = new ColorAttr("\033[1;35m");private static final ColorAttr INVISIBLE = new ColorAttr("\033[8m");private final List<Object> parts = new LinkedList<Object>();private int visibleLength = 0;private final boolean useColor;public ColorBuffer(boolean useColor) {this.useColor = useColor;append("");}public ColorBuffer(String str, boolean useColor) {this.useColor = useColor;append(str);}/*** Pad the specified String with spaces to the indicated length** @param str*          the String to pad* @param len*          the length we want the return String to be* @return the passed in String with spaces appended until the*         length matches the specified length.*/ColorBuffer pad(ColorBuffer str, int len) {while (str.getVisibleLength() < len) {str.append(" ");}return append(str);}ColorBuffer center(String str, int len) {StringBuilder buf = new StringBuilder(str);while (buf.length() < len) {buf.append(" ");if (buf.length() < len) {buf.insert(0, " ");}}return append(buf.toString());}ColorBuffer pad(String str, int len) {if (str == null) {str = "";}return pad(new ColorBuffer(str, false), len);}public String getColor() {return getBuffer(useColor);}public String getMono() {return getBuffer(false);}String getBuffer(boolean color) {StringBuilder buf = new StringBuilder();for (Object part : parts) {if (!color && part instanceof ColorAttr) {continue;}buf.append(part.toString());}return buf.toString();}/*** Truncate the ColorBuffer to the specified length and return* the new ColorBuffer. Any open color tags will be closed.* Do nothing if the specified length is <= 0.*/public ColorBuffer truncate(int len) {if (len <= 0) {return this;}ColorBuffer cbuff = new ColorBuffer(useColor);ColorAttr lastAttr = null;for (Iterator<Object> i = parts.iterator(); cbuff.getVisibleLength() < len && i.hasNext();) {Object next = i.next();if (next instanceof ColorAttr) {lastAttr = (ColorAttr) next;cbuff.append((ColorAttr) next);continue;}String val = next.toString();if (cbuff.getVisibleLength() + val.length() > len) {int partLen = len - cbuff.getVisibleLength();val = val.substring(0, partLen);}cbuff.append(val);}// close off the buffer with a normal tagif (lastAttr != null && lastAttr != NORMAL) {cbuff.append(NORMAL);}return cbuff;}@Overridepublic String toString() {return getColor();}public ColorBuffer append(String str) {parts.add(str);visibleLength += str.length();return this;}public ColorBuffer append(ColorBuffer buf) {parts.addAll(buf.parts);visibleLength += buf.getVisibleLength();return this;}private ColorBuffer append(ColorAttr attr) {parts.add(attr);return this;}public int getVisibleLength() {return visibleLength;}private ColorBuffer append(ColorAttr attr, String val) {parts.add(attr);parts.add(val);parts.add(NORMAL);visibleLength += val.length();return this;}public ColorBuffer bold(String str) {return append(BOLD, str);}public ColorBuffer lined(String str) {return append(LINED, str);}public ColorBuffer grey(String str) {return append(GREY, str);}public ColorBuffer red(String str) {return append(RED, str);}public ColorBuffer blue(String str) {return append(BLUE, str);}public ColorBuffer green(String str) {return append(GREEN, str);}public ColorBuffer cyan(String str) {return append(CYAN, str);}public ColorBuffer yellow(String str) {return append(YELLOW, str);}public ColorBuffer magenta(String str) {return append(MAGENTA, str);}private static class ColorAttr {private final String attr;public ColorAttr(String attr) {this.attr = attr;}@Overridepublic String toString() {return attr;}}public int compareTo(Object other) {return getMono().compareTo(((ColorBuffer) other).getMono());}
}

调用

ColorBuffer color = new ColorBuffer("sdfsdf", true);    
ColorBuffer color1 = new ColorBuffer( true);    
System.out.println(color.yellow("234234").magenta("77777").bold("55555").center("66666",9));
System.out.println(color1.yellow("234234").magenta("77777").bold("55555").center("66666",9));

输出

直接复制的文本,颜色显示不出来,自己可以尝试

sdfsdf2342347777755555  66666  
http://www.yayakq.cn/news/562141/

相关文章:

  • 电子商务网站建设可用性五个方面wordpress 注册表单 自定义
  • 做网站怎么添加背景图片北京王府井房价多少钱一平
  • 能打开的网站你了解的宁夏电力建设工程公司门户网站
  • 范湖网站建设团队怎么在百度上做广告
  • 网站logo修改专业做国外网站
  • 张掖交通建设投资有限责任公司网站网页程序开发学什么语言
  • 快速搭建网站的工具有哪些如何创建一个个人网页
  • 网站风格设计惠州专业做网站公司
  • 网站开发html书籍下载正规的拼多多运营哪里找
  • 滑县网站建设服务邢台网络问政
  • 网站设计公司如何做好网站建设cloudfare wordpress
  • 深圳网站制作问wordpress 分享 赞
  • 吉林网络公司网站建设中车建设工程有限公司网站
  • 优秀网页设计作品网站app store免费下载
  • 新泰网站定制东莞市住房建设网站
  • 网站开发可能性分析东莞网站建设-信科网络
  • 网站建设公司网站定制开发工作努力加油的句子
  • 教育局网站建设管理工作意见wordpress 主题哪个好
  • 网站建设 月光博客品牌推广成功案例
  • 内网网站开发衡阳网站建设衡阳千度网络
  • 西宁市网站设计ICP备案不停网站
  • 广东省城乡和建设厅网站网站建设与管理学习什么
  • 怎么做挖矿网站做h5的网站
  • 在线考试类网站怎么做域名注册好了 怎么做网站
  • 陕西省城乡建设网站网站添加白名单
  • wordpress 鼠标点击网店seo排名优化
  • 网站被黑怎么恢复电子商务网站有哪几种
  • 网站建设阶段推广策略做网站要具备些什么
  • 义乌外贸网站开发北京文化墙设计公司
  • 企业网站怎么做毕业设计wordpress wp super