C#编程,Console控制台输出的功能强化类的使用说明

FluentConsole是一个托管在github的C#开源组件,地址:https://github.com/ashmind/FluentConsole
这个组件类库可以:

  • 控制Console输入的背景,以及字体的颜色
  • 可以使用条件输出和控制

1、安装

通过nuget控制台:

Install-Package FluentConsole

或者管理nuget包来进行安装

2、使用

可以使用 FluentConsole.Instance 或者 FluentConsole 来使用静态方法直接操作对应颜色和文字。

其中:

  • Line 代表换行输出,效果等同于 Console.WriteLine
  • Text 代表直接输出,不换行,效果等同于 Console.Write
  • Background 代表文字背景色

代码1

            FluentConsole.White.Background.Black.Line("Black");
            FluentConsole
                        .Cyan.Line("Cyan")
                        .Gray.Line("Gray")
                        .Green.Line("Green")
                        .Magenta.Line("Magenta")
                        .Red.Line("Red")
                        .White.Line("White")
                        .Yellow.Line("Yellow");

效果1

在这里插入图片描述

代码2

            //将控制台的颜色直接用于输出的Text
            FluentConsole.Yellow.Text("输入黄色字体");

            FluentConsole.Black.Line("");

            FluentConsole.Yellow.Background
                         .Blue.Line("设置黄色背景,和蓝色文字");

            FluentConsole.Yellow.Text("黄色")
                         .Red.Line("红色");

            var console = FluentConsole.Instance;
            console.Red.Text("另一种用法");

            //条件用法
            FluentConsole.Yellow.Line("当前对象状态:")
                         .With(c => 10 > 8 ? c.Red : c.Blue)
                         .Text("成功");

效果2

在这里插入图片描述

猜你喜欢

转载自blog.csdn.net/qq_43307934/article/details/108811155