Get the App
SLTechnology News&Howtos  ›  Development  › 

How to use C# to develop interactive command line

Shulou Source: shulou.com Published: 2022-05-31 16:36:32 09月14日 Update

This article mainly introduces the relevant knowledge of "how to develop interactive command line application in C #". The editor shows you the operation process through an actual case. The operation method is simple, fast and practical. I hope this article "how to develop interactive command line applications in C #" can help you solve the problem.

Preface

If you have developed vue applications, you should be impressed by its interactive command line:

It allows you to create vue applications without any programming experience and just answer questions.

Although as .NET, we don't use the command line most of the time, we still want to be able to develop such interactive command-line applications, such as code generators, in C #.

Sharprompt introduction

Sharprompt is an interactive command line application framework based on C #, which has the following characteristics:

Multi-platform support

Support common prompts (normal input / password / options, etc.)

Model-based prompts are supported (in preview)

Verification of input valu

Automatically generate data sources using enumerated values

Customizable symbols and color modes

Unicode support

It provides the following common API:

Prompt.Input simple input prompt to return data of the specified type

Prompt.Password password prompt

Prompt.Confirm confirmation prompt, returns the value of Bool

Prompt.Select Radio Tip

Prompt.ColorSchema specifies the color scheme

Demo

Let's demonstrate how to use Sharprompt to generate an interactive command-line application.

The code is as follows:

Console.OutputEncoding = Encoding.UTF8;Prompt.ColorSchema.Select = ConsoleColor.DarkCyan;var type = Prompt.Select ("database type", new [] {"Oracle", "SQL Server", "MySQL", "PostgreSQL", "MariaDB"}, defaultValue: "MySQL", pageSize: 3); var server = Prompt.Input ("service address"); Prompt.ColorSchema.Answer = ConsoleColor.DarkRed;var name = Prompt.Input ("user name"); var password = Prompt.Password ("password") Console.WriteLine ($"you typed {type} {server} {name} {password}"); var confirm = Prompt.Confirm ("continue"); Console.WriteLine ($"your choice is {confirm}!"); this is the end of the introduction on "how to develop interactive command line applications in C#". Thank you for reading. If you want to know more about the industry, you can follow the industry information channel. The editor will update different knowledge points for you every day.

Tags: Commands applications interactive prompts caches development input support passwords data knowledge generation code commonly used types industries questions choices different ordinary Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Shulou Tech Info MySQL Linux OPPO Reno NVidia