ConsoleHelper 类
//Writes colored text to the console and allows to clear previously written lines
//as long a not line break is present //Sample - screenshot at http://img299.imageshack.us/img299/3931/consolex.png C.InfoLine("Non-colored text..."); C.Error("Outch, an error.");
Thread.CurrentThread.Join();
C.ClearLine();
C.Warn("Ok, only a warning.");
Thread.CurrentThread.Join();
C.ClearLine();
C.SuccessLine("OK."); C.InfoColor = ConsoleColor.Blue;
C.InfoLine("I'm feeling blue"); /* ********************************************************** */ /// <summary>
/// Console helper class.
/// </summary>
public static class C
{
/// <summary>
/// The color that is used to print out errors to the console.
/// </summary>
public static ConsoleColor ErrorColor = ConsoleColor.Red; /// <summary>
/// The color that is used to print out warnings to the console.
/// </summary>
public static ConsoleColor WarningColor = ConsoleColor.Yellow; /// <summary>
/// The color that is used to print out infos to the console.
/// </summary>
public static ConsoleColor SuccessColor = ConsoleColor.Green; /// <summary>
/// The color that is used to print out infos to the console.
/// If set to null, the current console color is used.
/// </summary>
public static ConsoleColor? InfoColor; public static void ErrorLine(string msg, params object[] args)
{
WriteLine(ErrorColor, msg, args);
} public static void Error(string msg, params object[] args)
{
Write(ErrorColor, msg, args);
} public static void WarnLine(string msg, params object[] args)
{
WriteLine(WarningColor, msg, args);
} public static void Warn(string msg, params object[] args)
{
Write(WarningColor, msg, args);
} public static void InfoLine(string msg, params object[] args)
{
WriteLine(InfoColor ?? Console.ForegroundColor, msg, args);
} public static void Info(string msg, params object[] args)
{
Write(InfoColor ?? Console.ForegroundColor, msg, args);
} public static void SuccessLine(string msg, params object[] args)
{
WriteLine(SuccessColor, msg, args);
} public static void Success(string msg, params object[] args)
{
Write(SuccessColor, msg, args);
} /// <summary>
/// Clears the current line.
/// </summary>
public static void ClearLine()
{
var position = Console.CursorLeft; //overwrite with white space (backspace doesn't really clear the buffer,
//would need a hacky combination of \b\b and single whitespace)
Console.SetCursorPosition(, Console.CursorTop);
Console.Write("".PadRight(position));
Console.SetCursorPosition(, Console.CursorTop);
} public static void Write(string msg, params object[] args)
{
Console.Write(msg, args);
} public static void WriteLine(ConsoleColor color, string msg, params object[] args)
{
Write(color, msg, args);
Console.Out.WriteLine();
} public static void Write(ConsoleColor color, string msg, params object[] args)
{
try
{
Console.ForegroundColor = color;
Console.Write(msg, args);
}
finally
{
Console.ResetColor();
}
} }
ConsoleHelper 类的更多相关文章
- Java类的继承与多态特性-入门笔记
相信对于继承和多态的概念性我就不在怎么解释啦!不管你是.Net还是Java面向对象编程都是比不缺少一堂课~~Net如此Java亦也有同样的思想成分包含其中. 继承,多态,封装是Java面向对象的3大特 ...
- ML.NET 示例:多类分类之鸢尾花分类
写在前面 准备近期将微软的machinelearning-samples翻译成中文,水平有限,如有错漏,请大家多多指正. 如果有朋友对此感兴趣,可以加入我:https://github.com/fei ...
- 分享一个自定义的 console 类,让你不再纠结JS中的调试代码的兼容
问题的产生 在写JS的过程中,为了调试我们常常会写很多 console.log.console.info.console.group.console.warn.console.error代码来查看JS ...
- C++ 可配置的类工厂
项目中常用到工厂模式,工厂模式可以把创建对象的具体细节封装到Create函数中,减少重复代码,增强可读和可维护性.传统的工厂实现如下: class Widget { public: virtual i ...
- Android请求网络共通类——Hi_博客 Android App 开发笔记
今天 ,来分享一下 ,一个博客App的开发过程,以前也没开发过这种类型App 的经验,求大神们轻点喷. 首先我们要创建一个Andriod 项目 因为要从网络请求数据所以我们先来一个请求网络的共通类. ...
- ASP.NET MVC with Entity Framework and CSS一书翻译系列文章之第二章:利用模型类创建视图、控制器和数据库
在这一章中,我们将直接进入项目,并且为产品和分类添加一些基本的模型类.我们将在Entity Framework的代码优先模式下,利用这些模型类创建一个数据库.我们还将学习如何在代码中创建数据库上下文类 ...
- ASP.NET Core 折腾笔记二:自己写个完整的Cache缓存类来支持.NET Core
背景: 1:.NET Core 已经没System.Web,也木有了HttpRuntime.Cache,因此,该空间下Cache也木有了. 2:.NET Core 有新的Memory Cache提供, ...
- .NET Core中间件的注册和管道的构建(2)---- 用UseMiddleware扩展方法注册中间件类
.NET Core中间件的注册和管道的构建(2)---- 用UseMiddleware扩展方法注册中间件类 0x00 为什么要引入扩展方法 有的中间件功能比较简单,有的则比较复杂,并且依赖其它组件.除 ...
- Java基础Map接口+Collections工具类
1.Map中我们主要讲两个接口 HashMap 与 LinkedHashMap (1)其中LinkedHashMap是有序的 怎么存怎么取出来 我们讲一下Map的增删改查功能: /* * Ma ...
随机推荐
- Android应用中创建绑定服务使得用户可以与服务交互
原文:http://android.eoe.cn/topic/android_sdk 一个绑定的服务是客户服务器接口上的一个服务器.一个绑定的服务允许组件(如:活动)来绑定一个服务,传送请求,接收响应 ...
- Atitit 架构的原则attilax总结
Atitit 架构的原则attilax总结 1.1. Rule of three称为"三次原则",指的是当某个功能第三次出现时,才进行"抽象化".是DRY原则和 ...
- jQuery页面引导插件 jquery-pagewalkthrough
http://jwarby.github.io/jquery-pagewalkthrough/ 源码 https://github.com/jwarby/jquery-pagewalkthrough
- iphone开发之解决viewWillAppear失效
转自:http://linuxstuding.iteye.com/blog/1224399 你可曾遇到过viewWillAppear没有被调用到的情况 产生原因是用了UINavigationContr ...
- [AWS vs Azure] 云计算里AWS和Azure的探究(2.1)
云计算里AWS和Azure的探究(2.1) ——Amazon EC2 和 WindowsAzure Virtual Machine 刚发表了就发现Amazon的价格下降了,第一代Linux的EC2价格 ...
- 每天一个linux命令(4) df命令
linux中df命令的功能是用来检查linux服务器的文件系统的磁盘空间占用情况.可以利用该命令来获取硬盘被占用了多少空间,目前还剩下多少空间等信息. 1.命令格式: df [选项] [文件] 2.命 ...
- 关于SimpleMsgPack中swap引发的问题大端法和小端法研究笔记
今天diocp裙中[珠海]-芒果反应了一个关于SimpleMsgPack的问题 msgPack.AsFloat = 2.507182; 经过编码再解码后,会直接触发异常. 因为msgPack的标准,在 ...
- 关于emoji表情
/** /* 表情编码 /* @param emoji:表情符号 **/ encodeEmoji: function (content) { var imgHtml = ""; v ...
- http post multipart/mixed的文件.
依赖. <dependency> <groupId>org.apache.httpcomponents</groupId> <artifactId>ht ...
- oracle中for循环
DECLARE );-- 定义一个字符串变量str BEGIN .. loop -- INSERT INTO FW_TEST(NAME) VALUES('bbb' + i);DECODE('1','' ...