//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. RecyclerView 与 ItemTouchHelper 实现拖拽效果

    截图 需求 App 开发新的需求,要求 RecyclerView 实现的九宫格样式可以拖拽,松手以后变更位置,类似于手机桌面拖动 app 变更位置. 分析 经过搜索,发现 support 中带有一个类 ...

  2. Atitit 路径规划法attilax总结 扫描线路法

    Atitit 路径规划法attilax总结 扫描线路法 2017/2/8 20:43:37[吐槽]深圳-小 2017/2/8 20:43:37 群主做什么的2017/2/10 10:03:15系统消  ...

  3. 简单修改文件名python脚本

    import os import sys path = "D:\emojis" for (path,dirs,files) in os.walk(path): for filena ...

  4. HTML杂记

    1.URL  uniform resource locator 遵循格式: scheme://host.domain:port/path/filename scheme - 定义因特网服务的类型.最常 ...

  5. 关于chrome的开发调试方式

    chrome://inspect/#devices 调试移动设备app chrome://version 查看chrome浏览器版本信息 chrome://components/ 查看组件信息 上面的 ...

  6. [CoreOS 转载]CoreOS实践指南(二):架设CoreOS集群

    转载:http://www.csdn.net/article/2015-01-04/2823399 摘要:CoreOS是一个采用了高度精简的系统内核及外围定制的操作系统.ThoughtWorks的软件 ...

  7. 【Java】Java复习笔记-三大排序算法,堆栈队列,生成无重复的随机数列

    冒泡排序 package com.lcw.bubble; public class BubbleSort { /** * 冒泡排序 * @param args * @author 成鹏致远 */ pu ...

  8. Docker 构建网络服务后本机不能访问

    Docker 构建网络服务后本机不能访问 起因 使用tornado构建了一个服务,测试都没有问题 使用docker构建镜像,使用docker run image_name启动服务 使用浏览器访问 12 ...

  9. chmod 权限 命令详细用法

    指令名称 : chmod 使用权限 : 所有使用者 使用方式 : chmod [-cfvR] [--help] [--version] mode file... 说明 : Linux/Unix 的档案 ...

  10. php 找出异常发生的地方

    多层嵌套发生异常,找到异常最早发生的地方. final public int Exception::getLine ( void ) final public string Exception::ge ...