⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 logterm.h

📁 日志类封装日志类封装日志类封装日志类封装日志类封装日志类封装
💻 H
字号:
/*============================================================================. | Copyright (C) 2006 Gareth Buxton                                           | |----------------------------------------------------------------------------| | LogPlusPlus is free software; you can redistribute it and/or               | | modify it under the terms of the GNU Lesser General Public                 | | License as published by the Free Software Foundation; either               | | version 2.1 of the License, or (at your option) any later version.         | |                                                                            | | LogPlusPlus is distributed in the hope that it will be useful,             | | but WITHOUT ANY WARRANTY; without even the implied warranty of             | | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU          | | Lesser General Public License for more details.                            | |                                                                            | | You should have received a copy of the GNU Lesser General Public           | | License along with this library; if not, write to the Free Software        | | Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA | '============================================================================*/#ifndef _LPP_LOG_TERM_H_#define _LPP_LOG_TERM_H_#include <liblpp/Types.h>#include <string>//=============================================================================LPP_NAMESPACE_BEGIN//=============================================================================class LogTerm{public:	static const std::string ESC_XTERM = std::string((char) 0x1B);	enum Color	{		BLACK = 0		, RED		, GREEN		, YELLOW		, BLUE		, MAGENTA		, CYAN		, WHITE	};		enum ColorType	{		FOREGROUND = 0		, BACKGROUND	};		enum Attribute	{		CLEAR = 0		, BOLD		, BLINK		, UNDERLINE_ON		, UNDERLINE_OFF	};		class Type	{		NONE("")		, XTERM("xterm")		, VT100("vt100");				std::string name;				Type(const std::string& name)		: name(name)		{		}	};		public static Term instantiate(String type)	{		if(Type.NONE.name.equalsIgnoreCase(type))		{			return instantiate(Type.NONE);		}		else if(Type.VT100.name.equalsIgnoreCase(type))		{			return instantiate(Type.VT100);		}		else if(Type.XTERM.name.equalsIgnoreCase(type))		{			return instantiate(Type.XTERM);		}		else		{			return instantiate(Type.NONE);		}	}		public static Term instantiate(Type type)	{		switch(type)		{			case XTERM: return new XTerm();			case VT100: return new XTerm();			default: return new NoTerm();		}	}		protected abstract String[][] getColType();	protected abstract String[] getAttType();	protected abstract String getEscSeq();	protected abstract String getColValue(Color color);		public void setTerm(OutputStream os, Term.Color color)	throws IOException	{		setTerm(os, ColorType.FOREGROUND, color);	}		public void setTerm(OutputStream os, Term.ColorType colorType, Term.Color color)	throws IOException	{		clearTerm(os);		setColor(os, colorType, color);	}		public void setTerm(OutputStream os, Term.Color color, Term.Attribute attribute)	throws IOException	{		setTerm(os, ColorType.FOREGROUND, color, attribute);	}		public void setTerm(OutputStream os, Term.ColorType colorType, Term.Color color	                    , Term.Attribute attribute)	throws IOException	{		setAttribute(os, attribute);		setColor(os, colorType, color);	}		public void clearTerm(OutputStream os)	throws IOException	{		setAttribute(os, Attribute.CLEAR);	}		public void setAttribute(OutputStream os, Term.Attribute attribute)	throws IOException	{		os.write(getAttType()[Attribute.CLEAR.value].getBytes());		os.write(getAttType()[attribute.value].getBytes());	}		public void setColor(OutputStream os, Term.ColorType colorType, Term.Color color)	throws IOException	{		String sColor = getColType()[colorType.value][0];		String eColor = getColType()[colorType.value][1];		String esc = getEscSeq();		os.write((esc + sColor + getColValue(color) + eColor).getBytes());	}	}package org.dbud.term;public class NoTerm extends Term{	private static final String[][] colType = new String[][]	{		{"", ""} // FOREGROUND	,	{"", ""} // BACKGROUND	};		private static final String[] attType = new String[]  	{  		""	// CLEAR  	,	""	// BOLD  	,	""	// BLINK  	,	""	// UNDERLINE_ON  	,	""	// UNDERLINE_OFF  	};	protected String getEscSeq()	{		return "";	}		protected String getColValue(Color color)	{		return "";	}		@Override	protected String[] getAttType()	{		return attType;	}	@Override	protected String[][] getColType()	{		return colType;	}}package org.dbud.term;public class XTerm extends Term{	private static final String[][] colType = new String[][]	{		{"[3", "m"} // FOREGROUND	,	{"[4", "m"} // BACKGROUND	};		private static final String[] attType = new String[]  	{		ESC_XTERM + "(B" + ESC_XTERM + "[m"							// CLEAR  	,	ESC_XTERM + "[1m"											// BOLD  	,	ESC_XTERM + "[5m"											// BLINK  	,	ESC_XTERM + "[[5m" + ESC_XTERM + "[4m"						// UNDERLINE_ON  	,	ESC_XTERM + "[[5m" + ESC_XTERM + "[4m" + ESC_XTERM + "[24m"	// UNDERLINE_OFF  	};	protected String getEscSeq()	{		return ESC_XTERM;	}		protected String (Color color)	{		return String.valueOf(color.value);	}		@Override	protected String[] getAttType()	{		return attType;	}	@Override	protected String[][] getColType()	{		return colType;	}}//=============================================================================LPP_NAMESPACE_END//=============================================================================#endif /*_LPP_LOG_TERM_H_*/

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -