-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
28 changed files
with
649 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,18 +1,39 @@ | ||
# Trivial Toolkit for Windows App | ||
|
||
## [Trivial.WindowsKit](./Common) | ||
|
||
![.NET 6 - Windows 10](./docs/assets/badge_NET_6_Win10.svg) | ||
![.NET 7 - Windows 10](./docs/assets/badge_NET_7_Win10.svg) | ||
![.NET 8 - Windows 10](./docs/assets/badge_NET_8_Win10.svg) | ||
![.NET 9 - Windows 10](./docs/assets/badge_NET_9_Win10.svg) | ||
|
||
[![NuGet package](https://img.shields.io/nuget/dt/Trivial.WindowsKit?label=nuget+downloads)](https://www.nuget.org/packages/Trivial.WindowsKit) | ||
|
||
## Controls | ||
- Controls: A set of useful controls including tiles, collections and tabbed web view. | ||
- Local web app: A way to launch H5 app locally with native capability and auto-update. | ||
- Utilities: Helper class of visual element, dependency object and JSON HTTP client. | ||
|
||
## [Trivial.Console](./Console) | ||
|
||
The rich UX CLI controls. | ||
|
||
[![NuGet package](https://img.shields.io/nuget/dt/Trivial.Console?label=nuget+downloads)](https://www.nuget.org/packages/Trivial.Console) | ||
|
||
![.NET 9](./docs/assets/badge_NET_9.svg) | ||
![.NET 8](./docs/assets/badge_NET_8.svg) | ||
![.NET 6](./docs/assets/badge_NET_6.svg) | ||
![.NET Framework 4.8](./docs/assets/badge_NET_Fx_4_8.svg) | ||
![.NET Framework 4.6.1](./docs/assets/badge_NET_Fx_4_6_1.svg) | ||
|
||
- [Console utilities and components](./docs/console) | ||
|
||
A set of useful controls including tiles, collections and tabbed web view. | ||
## [Trivial.Web](./Web) | ||
|
||
## Local web app | ||
The useful utilities for ASP.NET application. | ||
|
||
A way to launch H5 app locally with native capability and auto-update. | ||
[![NuGet package](https://img.shields.io/nuget/dt/Trivial.Web?label=nuget+downloads)](https://www.nuget.org/packages/Trivial.Web) | ||
|
||
## Utilities | ||
![ASP.NET Core 9.0](./docs/assets/badge_ASPNET_9_0.svg) | ||
![ASP.NET Core 8.0](./docs/assets/badge_ASPNET_8_0.svg) | ||
![ASP.NET Core 6.0](./docs/assets/badge_ASPNET_6_0.svg) | ||
|
||
Helper class of visual element, dependency object and JSON HTTP client. | ||
- [Controller extensions for ASP.NET Core](./docs/web/controller) |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
# CommandLine | ||
|
||
In `Trivial.CommandLine` namespace of `Trivial.dll` [library](../). | ||
Some useful utilities for console application. | ||
|
||
- [Arguments](./arguments) An instance provided a way to access values from the arguments and dispatch the command verbs. | ||
- [CLI](./console) An adaptive command line interface for both terminal and command prompt. | ||
|
||
In `Trivial.CommandLine` namespace of `Trivial.Console.dll` library. | ||
A lot of useful rich command line controls. | ||
|
||
![Sample screenshot](./controls/sample.jpg) | ||
|
||
- [Selection](./selection) A visual console control that allow user select item by pressing keyboard. | ||
- [Progress bar](./progress) A visual console control that update the state of a task. | ||
- [Prettier](./prettier) The text prettier. | ||
- [Data formatter](./data) Format and output object like JSON object, JSON array, exception, etc. | ||
|
||
# `Trivial.Console` library | ||
|
||
The rich user interface console controls for terminal and Command Prompt. | ||
|
||
This library targets .NET 6, .NET 5, .NET Core 3.1, .NET Standard 2.0, .NET Framework 4.6.1 and .NET Framework 4.8. | ||
|
||
You can install the package from [NuGet](https://www.nuget.org/packages/Trivial.Console) to your project. | ||
|
||
```sh | ||
PM > Install-Package Trivial.Console | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,101 @@ | ||
# Console arguments | ||
|
||
A console component to let user write text. | ||
|
||
In `Trivial.CommandLine` [namespace](../) of `Trivial.dll` [library](../../). | ||
|
||
## Arguments | ||
|
||
The command arguments is an array of string. You can parse it to a program readable object with structured information. | ||
|
||
```csharp | ||
void Main(string[] args) | ||
{ | ||
// Parse arguments from a string array. | ||
var arguments = new Arguments(args); | ||
|
||
// You can get the value of each parameter by key (case-insensitive). | ||
Console.WriteLine("{0} {1}", arguments["say"], arguments["name"]); | ||
|
||
// Parse arguments from a string. | ||
var str = Console.ReadLine(); | ||
arguments = new Arguments(str); | ||
|
||
// You can get the value by index. | ||
Console.WriteLine("{0} {1}", arguments[1], arguments[0]); | ||
} | ||
``` | ||
|
||
Console: | ||
|
||
```sh | ||
> a.exe --name Kingcean Tuan --say Hello | ||
Hello Kingcean Tuan | ||
> hijklmn abcdefg | ||
abcdefg hijklmn | ||
``` | ||
|
||
## Verb | ||
|
||
If your application contains a set of functionality, you may need verbs to help you to build a more flexible console application. Each verb can has its own business logic. The arguments will be filled into the property with attribute `ArgumentAttribute`. | ||
|
||
```csharp | ||
class FirstVerb : Verb | ||
{ | ||
[Argument("name")] | ||
public string Name { get; set; } | ||
|
||
public bool HasName => HasParameter("name"); | ||
|
||
public override string Description => "Test 1"; | ||
|
||
public override void Process() | ||
{ | ||
Console.WriteLine("This is the verb handler 1."); | ||
Console.WriteLine("Name is {0}.", Name); | ||
Console.WriteLine("Name is {0}.", Arguments["name"]); | ||
} | ||
} | ||
``` | ||
|
||
And you can also define a verb handler with async process method. | ||
|
||
```csharp | ||
class SecondVerb : AsyncVerb | ||
{ | ||
public override string Description => "Test 2"; | ||
|
||
public override async Task Process() | ||
{ | ||
Console.WriteLine("This is the verb handler 2. Step 1."); | ||
await Task.Run(() => { | ||
Console.WriteLine("This is the verb handler 2. Step 2."); | ||
}); | ||
} | ||
} | ||
``` | ||
|
||
Then you can use dispatcher to dispatch the correct verb handler to process. | ||
|
||
```csharp | ||
void Main(string[] args) | ||
{ | ||
var dispatcher = new Dispatcher(); | ||
dispatcher.Register<FirstVerb>("one"); | ||
dispatcher.Register<SecondVerb>("two"); | ||
|
||
dispatcher.Process(args); | ||
} | ||
``` | ||
|
||
Console: | ||
|
||
```sh | ||
> a.exe one --name Test | ||
This is the verb handler 1. | ||
Name is Test. | ||
Name is Test. | ||
> a.exe two | ||
This is the verb handler 2. Step 1. | ||
This is the verb handler 2. Step 2. | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
# CLI | ||
|
||
An adaptive command line interface for both terminal and command prompt. | ||
|
||
In `Trivial.CommandLine` [namespace](../) of `Trivial.dll` [library](../../). | ||
|
||
## Console | ||
|
||
We provide an interface for the standard output stream that you can write a string which you can update before the line terminator. | ||
It supports both terminal and command prompt. | ||
Following is a sample. | ||
|
||
```csharp | ||
var cli = StyleConsole.Default; | ||
|
||
// Write something. | ||
cli.Write("Loading {0}......", "something"); | ||
|
||
// Remove some charactors and add other string with color. | ||
cli.Backspace(3); | ||
cli.Write(ConsoleColor.Green, " Done!"); | ||
|
||
// And you can append other string following above in the same line and in the default color. | ||
cli.Write(" This is only for test."); | ||
|
||
// Add terminator. | ||
cli.Write(Environment.NewLine); | ||
|
||
// So following will be in a new cli. | ||
cli.Write("Next cli. "); | ||
|
||
// We can turn off the auto flush so that all strings write later will be in an output queue. | ||
cli.AutoFlush = false; | ||
cli.Write(ConsoleColor.Red, ConsoleColor.Yellow, "Red foreground and yellow background"); | ||
cli.Write(Environment.NewLine); | ||
cli.Write("This will not be output immediately, neither."); | ||
|
||
// Now let's write them. | ||
cli.Flush(); | ||
|
||
// Following will not output until we call Flush member method or set AutoFlush property as true. | ||
cli.Write(" Hello?"); | ||
cli.AutoFlush = true; | ||
cli.Write(Environment.NewLine); | ||
``` | ||
|
||
And you can also read the password into a `SecureString` with the optional text mask. | ||
|
||
```csharp | ||
// Read password. | ||
cli.Write("Type password: "); | ||
var password = cli.ReadPassword(ConsoleColor.Yellow, '*'); | ||
cli.WriteLine(); | ||
|
||
// Write a secure string to the standard output stream. | ||
cli.Write("Your password is "); | ||
cli.Write(ConsoleColor.Magenta, password.ToUnsecureString()); | ||
cli.WriteLine('.'); | ||
``` |
Oops, something went wrong.