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 开发工具箱
Toast 工具类: SmartToastUtils.java import android.content.Context; import android.widget.Toast; /** * T ...
- C语言:存取结构体成员的点运算符(.)和箭头运算符(->)的区别
转自:http://blog.csdn.net/taric_ma/article/details/7397362 一直以为这两个是没有什么区别的,可以相互替换,今天又翻了一下<C语言核心技术&g ...
- jar依赖
https://blog.csdn.net/honghailiang888/article/details/53019635
- vim学习笔记(10):vim命令大全
进入vim的命令: vim filename :打开或新建文件,并将光标置于第一行首 vim +n filename :打开文件,并将光标置于第n行首 vim + filename :打开文件,并将光 ...
- DIOCP开源项目-DIOCP3重写笔记-1
这几天在在重新DIOCP3,基本工作已经初步完成,进入测试阶段,今天加入排队投递,本认为是个很简单的工作,稍微不注意,留了两个坑,调了7,8个小时,刚刚总算找到问题,记录一下, 关于排队投递的流程 这 ...
- VS2015打开项目慢、死机和卡顿解决方案
VS2015功能强大,但是经常慢 网上有解决方案如下几个,留着备用: 1.选项-环境-基于客户端性能自动调整视觉体验,去掉选项. 2.选项-源代码管理-插件选无. 3.选项-文本编辑器-所有语言-滚动 ...
- Android开发(八)——Android组件
参考: [1] Android开发教程:理解Intent和Intent Filter.http://liuzhichao.com/p/506.html
- Git CMD连接,管理(remote,add,commit,push)github repository
git initmd testcd testgit statusgit add test //git add test/a.txtgit status git remote add origin g ...
- WebApi增删改查Demo
1.新建webapi项目 2.配置WebApiConfig public const string DEFAULT_ROUTE_NAME = "MyDefaultRoute"; p ...
- ubuntu 12.04下编译安装nginx-1.9.3
1,下载nginx-1.9.3.tar.gz 两种方式: (1).ubuntu 下终端中(ctrl+alt+t) 运行命令: wget http://nginx.org/download/nginx- ...