当前位置:网站首页>A cool "ghost" console tool

A cool "ghost" console tool

2022-07-07 05:20:00 InfoQ

brief introduction

A console plug-in mentioned yesterday to be introduced , Today it comes !
  • Full name :
    Spectre.Console
  • Translated names ( unofficial ): Ghost console ( Hereinafter referred to as ghost )
Why write this ! Hey , Because of course , There is no sorting , It's really a busy job ,
Forced migrant workers
/(ㄒoㄒ)/~~
And these are commonly used things at hand , As the anchor with goods said , I used it myself , It's really easy to use , And cool enough , Dare to recommend it to you .
In fact, there are many beautiful console tools , such as ColorfulConsole,ConsoleTables etc. , Even the built-in console style is enough in most scenarios , What's special about this tool ?

features

  • New enough
    : The tools mentioned above , Or some did not mention , But tools with a large number of downloads , The update frequency is very slow , I want to be very angry ColorfulConsole, The last update has stopped 2020 year , So despite its powerful functions , But the vitality is not good . Ghosts are different , Look at the official release records , He is now in rapid iterative update , Abreast of the times 0.44.x edition , It has been updated 13 It's a small version , Yes, of course , Frequent updates are not necessarily a good thing , It also reflects many problems , Mending , But that's exactly what happened , It proves that it is energetic , It's worth affirming !
  • Cool
    I don't want to explain that , Look at the picture

  • null

  • Strong enough :
    It can also be seen from the above figure , Ghost offers a variety of console printing styles , In addition to the processing of text style , And support , form , Trees , Progress bar , Even emoji expression ( The system configuration needs to be modified )
Three points above , It's enough for me to choose it . If there are any shortcomings , There are no Chinese documents at present , Of course , I have Jinshan drug bully , incorrect , ICIBA ! therefore , It's nothing !

Use

Actually , About use , Official documents give enough cases , Here I will simply list a few use cases .

typeface

Use ghosts to print fonts of various styles , A bit like an editor Html file , Just go through markup(Line) Method , Write special keywords and placeholders in the text to be output .
For example, you need to print colored words
AnsiConsole.MarkupLine($"[Yellow] I am the first 2 Middleware , I come from the entry file , I'm coming -{DateTime.Now}[/]");
Make it bold
AnsiConsole.MarkupLine("[bold]World[/]");
Be bold and have color
AnsiConsole.MarkupLine("[bold Yellow]World[/]");
Basic keywords and html The style is very similar , And underline , Escape, etc , I won't list them all .

form

Ghost's support for forms , In addition to supporting static tables , It also supports dynamic tables
  • Static tables
Just recently, I made a tool to monitor table changes , Constructed a table , Take it as an example
 var table = new Table().Centered();
table.AddColumn(" Authorized person ID");
table.AddColumn(" Authorized events ID");
table.AddColumn(" Authorized person ");
while (sdr.Read())
{
 string column1 = Convert.ToString(sdr["UserID"]);
 string column2 = Convert.ToString(sdr["TypeID"]);
 string column3 = Convert.ToString(sdr["UserNam"]);
 table.AddRow(column1, column2, column3);
}
AnsiConsole.Write(table);
In fact, it is to construct tables , Define column headers , Then print the contents of each line in sequence .
Of course, I'm just printing here , Ghost also supports adjusting the structure of the table , For example, the display is centered , Set borders , Set cell width, etc .
The code is also very simple
// Set width
table.Width(50);
// Set offset
table.Columns[0].PadLeft(3);
// Set borders , Draw a circle
table.Border(TableBorder.Square);
Official documents
There are more cases in , You can go and have a look
  • Dynamic tables
I haven't arrived yet , But official documents give several examples , It's very cool , Recording Gif to glance at .

null

FIGlet Text

I don't know how to translate this Chinese name , The effect is to make the text effect of dotted lines , Just like this.

null
It's very easy to use
AnsiConsole.Write(
 new FigletText("Tony's Box")
 .Centered()
 .Color(Color.Blue)
 );

choice

Like the screenshot above , The selection operation can be realized , As in the Bios The parameters set in the interface are the same
var cmd = AnsiConsole.Prompt(
 new SelectionPrompt<string>()
 .Title(&quot; The following are the operations temporarily supported by the toolkit ?&quot;)
 .PageSize(10)
 .MoreChoicesText(&quot;[grey]( Please select the operation to be performed )[/]&quot;)
 .AddChoices(new[] {
 &quot;1. monitor 【User_ProgramTypeLink】 Permissions on the table &quot;,&quot;2. Clear the log data half a year ago &quot;, &quot;3. Delete the specified index data &quot; 
 }));


Okay , That's basically it . Good night, !



原网站

版权声明
本文为[InfoQ]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/188/202207062244218991.html