C# programming, instructions for using enhanced functions of Console output

FluentConsole is a C# open source component hosted on github, address: https://github.com/ashmind/FluentConsole
This component library can:

  • Control the background of the console input and the color of the font
  • Can use conditional output and control

1. Installation

Through the nuget console:

Install-Package FluentConsole

Or manage nuget package to install

2. Use

You can use FluentConsole.Instance or FluentConsole to use static methods to directly manipulate the corresponding colors and text.

among them:

  • Line represents line feed output, the effect is equivalent to Console.WriteLine
  • Text stands for direct output, no line break, the effect is equivalent to Console.Write
  • Background represents the text background color

Code 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");

Effect 1

Insert picture description here

Code 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("成功");

Effect 2

Insert picture description here

Guess you like

Origin blog.csdn.net/qq_43307934/article/details/108811155