//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 类的更多相关文章

  1. Java类的继承与多态特性-入门笔记

    相信对于继承和多态的概念性我就不在怎么解释啦!不管你是.Net还是Java面向对象编程都是比不缺少一堂课~~Net如此Java亦也有同样的思想成分包含其中. 继承,多态,封装是Java面向对象的3大特 ...

  2. ML.NET 示例:多类分类之鸢尾花分类

    写在前面 准备近期将微软的machinelearning-samples翻译成中文,水平有限,如有错漏,请大家多多指正. 如果有朋友对此感兴趣,可以加入我:https://github.com/fei ...

  3. 分享一个自定义的 console 类,让你不再纠结JS中的调试代码的兼容

    问题的产生 在写JS的过程中,为了调试我们常常会写很多 console.log.console.info.console.group.console.warn.console.error代码来查看JS ...

  4. C++ 可配置的类工厂

    项目中常用到工厂模式,工厂模式可以把创建对象的具体细节封装到Create函数中,减少重复代码,增强可读和可维护性.传统的工厂实现如下: class Widget { public: virtual i ...

  5. Android请求网络共通类——Hi_博客 Android App 开发笔记

    今天 ,来分享一下 ,一个博客App的开发过程,以前也没开发过这种类型App 的经验,求大神们轻点喷. 首先我们要创建一个Andriod 项目 因为要从网络请求数据所以我们先来一个请求网络的共通类. ...

  6. ASP.NET MVC with Entity Framework and CSS一书翻译系列文章之第二章:利用模型类创建视图、控制器和数据库

    在这一章中,我们将直接进入项目,并且为产品和分类添加一些基本的模型类.我们将在Entity Framework的代码优先模式下,利用这些模型类创建一个数据库.我们还将学习如何在代码中创建数据库上下文类 ...

  7. ASP.NET Core 折腾笔记二:自己写个完整的Cache缓存类来支持.NET Core

    背景: 1:.NET Core 已经没System.Web,也木有了HttpRuntime.Cache,因此,该空间下Cache也木有了. 2:.NET Core 有新的Memory Cache提供, ...

  8. .NET Core中间件的注册和管道的构建(2)---- 用UseMiddleware扩展方法注册中间件类

    .NET Core中间件的注册和管道的构建(2)---- 用UseMiddleware扩展方法注册中间件类 0x00 为什么要引入扩展方法 有的中间件功能比较简单,有的则比较复杂,并且依赖其它组件.除 ...

  9. Java基础Map接口+Collections工具类

    1.Map中我们主要讲两个接口 HashMap  与   LinkedHashMap (1)其中LinkedHashMap是有序的  怎么存怎么取出来 我们讲一下Map的增删改查功能: /* * Ma ...

随机推荐

  1. 直接获取摄像头传回的图像数据(人脸、微笑、眨眼: 识别--&gt;第一步):图像识别第一步

    转:ios通过摄像头获取特定数据(http://www.2cto.com/kf/201404/290777.html) 凝视: 因为近期项目需求,须要一个可以实现对摄像头图片获取当中部分内容的功能,类 ...

  2. 用bundler安装jeklly

    为什么要写这篇文章呢?因为官方的安装文档里,ruby的很多库没有说明怎么安装.所以需要重点说明一下.1.我的安装环境是vultr的16.04版的ubuntu.2.因为ruby的扩展库好多都是Gcc编译 ...

  3. Vue 常见问题汇总

    Q:我给组件内的原生控件添加事件,怎么不生效了!!! <!--比如用了第三方框架,或者一些封装的内置组件; 然后想绑定事件--> <!--// 错误例子1--> <el- ...

  4. cmd命令操作Oracle数据库

    //注意cmd命令执行的密码字符不能过于复杂 不能带有特殊符号 以免执行不通过 譬如有!@#¥%……&*之类的  所以在Oracle数据库设置密码是不要太复杂 /String Database ...

  5. IIS写权限漏洞 (HTTP PUT方法利用)

    该漏洞的产生原因来源于服务器配置不当造成,利用IIS PUT Scaner扫描有漏洞的iis,此漏洞主要是因为服务器开启了 webdav的组件导致的可以扫描到当前的操作,具体操作其实是通过webdav ...

  6. Android Service GetSystemService

    http://blog.sina.com.cn/s/blog_71d1e4fc0100o8qr.html http://blog.csdn.net/bianhaohui/article/details ...

  7. Silverlight 控件

    http://www.cnblogs.com/yangfan/archive/2010/03/11/1683580.html

  8. Swiper.js的腾讯新闻演示

    演示效果地址:https://www.swiper.com.cn/demo/indexsample/: 代码: <!DOCTYPE html> <html> <head& ...

  9. hive查询遇到java.io.EOFException: Unexpected end of input stream错误

    hive查询遇到java.io.EOFException: Unexpected end of input stream错误 原因基本上有两个: 空文件 不完整的文件 解决办法: 删除对应文件- 参考 ...

  10. Oracle sql%rowcount 返回影响行数;sql server @@RowCount返回影响行数

    sql server中,返回影响行数是:If @@RowCount<1 Oracle中,返回影响行数是:If sql%rowcount<1 例: sqlserver: create pro ...