//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. SQL Server 的动态语句(SQLServer 的String.format用法)(SQLServer的调用SQL占位符的使用)

    直接上代码好了: --建表语句if exists(select 1 from [你的测试数据库名字].sys.tables where name='TDepartment') BEGIN print ...

  2. FFmpeg(2)-avformat_open_input()函数详解并示例打开mp4文件

    一. 解封装 pts 是显示的时间 dts是解码的时间, 这个时间是用来做同步. av_register_all(), 注册所有的格式.包括解封装格式和加封装格式. avformat_network_ ...

  3. my stackoverflow

    https://stackoverflow.com/questions/48017641/how-to-monitor-elastic-stack-without-x-pack https://sta ...

  4. Vue.js简介及指令

    1.Vue.js的特点 Vue.js是一个Javascript MVVM(Model-View-ViewModel)库,与传统Jquery的区别在于,Vue.js舍弃了繁杂的DOM操作, 如取DOM值 ...

  5. linux命令(37):paste,合并两个文件,对应行为一行

    paste的格式为: paste -d -s -file1 file2 选项的含义如下: -d 指定不同于空格或t a b键的域分隔符.例如用@分隔域,使用- d @.如果不指定,默认用空格分割 -s ...

  6. 【Socket】linux网络多路复用IO技术

      1.mystery引入      1)Select是一种多路复用IO输入输出模式,在linux的输入输出编程中通过select的轮询机制,发现可用/可读或可写的接口.    2)低级socket程 ...

  7. 【Mysql】Fedora下 Mysql 安装及配置

    1.安装 Mysql Server # yum install mysql mysql-server 可以到mysql官网去下载,我下载的是通用版本.你需要下载下面四个文件就可以了. mysql-cl ...

  8. crontab格式,命令

    http://www.blogjava.net/xiaomage234/archive/2007/12/26/170490.html crontab格式: 第1列分钟1-59 第2列小时1-23(0表 ...

  9. repo常用指令

    下载 repo 的地址: http://android.git.kernel.org/repo ,可以用 wget http://android.git.kernel.org/repo 或者 curl ...

  10. 让cpu跑到100%的bat文件

    请你新建一个叫“virus.bat”的批处理文件,里面填写上如下三段命令: Echo "welcom to the aqjava's world"Tree /fCall virus ...