Compare commits

...

49 Commits

Author SHA1 Message Date
Phil Scott
f5a9c0ca26 Removes automatic registration of settings
Original intention was to register Settings automatically for DI. This ran into problem when the container verifies the configuration is valid for a settings using the constructor for initialization. It tries to resolve the parameters and fails.

This removes the automatic registration and falls back ActivatorCreateInstance when no Setting is registered.
2021-04-18 22:41:05 +02:00
Loïc Sharma
23564612c1 Make AsyncCommand a little more discoverable (#375) 2021-04-18 09:35:37 +02:00
Phil Scott
f2b8afffb3 Marks Spectre.Console.Testing as not a test project
Probably something that only bothers me, but I'm in a habit of running dotnet test at the solution level. It was discovering this project as a test project even though it isn't. This produces an error complaining about not having a testhost.dll. I'm pretty sure this comes in via a props when xunit is referenced. 

This attribute in the csproj marks the project explicitly as not a test project
2021-04-17 09:30:33 +02:00
Patrik Svensson
3e2eea730b Add output abstraction and reorganize profile
* Moves ColorSystem from Profile to Capabilities
* Renames Tty to IsTerminal
* Adds IAnsiConsoleOutput to make output more flexible

Closes #343
Closes #359
Closes #369
2021-04-13 21:39:54 -04:00
Phil Scott
bc9f610258 Added "--hidden" param to explain feature
Probably shouldn't include the hidden commands by default. This lets the user show them if needed.
2021-04-13 17:40:55 +02:00
Phil Scott
ae96606ab7 Adds default command to explain feature 2021-04-13 17:40:55 +02:00
Phil Scott
41ccc0b464 Adds CLI explain command
Wanted a command to break down how Spectre views the command model. This outputs all the relevant settings in a tree. You can get a short explanation for all the commands, or a detailed explanation for all commands (there is a flag to go vice versa on the detailed view if you want)

app cli explain
app cli explain myappcommand
app cli explain -d
2021-04-12 17:40:31 +02:00
Patrik Svensson
3545e0f6b5 Add example infrastructure
* Add "Shared" projects for all examples
* Update "Colors" example with better TrueColor demo
* Use same namespace for all examples
2021-04-11 22:03:13 -04:00
Patrik Svensson
2fe2bb3c32 Add parameterless Clear method for IAnsiConsole
Closes #338
2021-04-11 22:01:14 -04:00
Patrik Svensson
1fc6f22ea9 Remove Style.Clone method
Closes #362
2021-04-11 21:58:58 -04:00
Patrik Svensson
6a5c507936 Rename 'Demo' example to 'Showcase' 2021-04-09 22:01:05 +02:00
Patrik Svensson
efa3d3b130 Add NuGet.Config 2021-04-09 08:45:30 -04:00
Patrik Svensson
6007fcaafc Update to .NET SDK 5.0.202 2021-04-09 07:48:10 -04:00
Patrik Svensson
13ac38ed04 Fix color system mapping bug
Closes #342
2021-04-08 12:18:54 -04:00
Patrik Svensson
ca036f6543 Add demo example 2021-04-07 20:32:07 -04:00
Phil Scott
36ec3d1fd3 Adds rune width caching for cell length calculations 2021-04-07 23:59:23 +02:00
Patrik Svensson
fe5096dceb Fixes color system detection bug
If an application runs on Windows 10.0.15063 or above, on a
runtime prior to net5.0, the color system detection will fail
and fall back to 8-bit color support.

The reason for this is because the behavior of
Environment.OSVersion.Version differs between runtimes. Unless you're
running on net5.0, both the major and build version components will
not reflect those in the actual Windows version.
2021-04-07 11:15:45 -04:00
Christian Wischenbart
39b59c8d4a Cleanup AnsiSequences.cs
1. Update CSI constant to include the [ character.
See ECMA-48 Section 8.3.16
https://www.ecma-international.org/wp-content/uploads/ECMA-48_5th_edition_june_1991.pdf

2. Use string interpolation, because it's easier to read
(and internally uses a StringBuilder)

3. Add ESC constant, because the AnsiBuilder needs it to create links.

4. Remove unused SGR overload.
2021-04-06 22:51:42 +02:00
Phil Scott
8cf7794852 Adding unit tests for settings constructor 2021-04-06 22:48:51 +02:00
Phil Scott
4edc647fdd Falls back to null for settings constructor 2021-04-06 22:48:51 +02:00
Christian Wischenbart
be45a0ff4e Fix AnsiConsoleBackend.Clear
1. Add an ED3 command to clear the scroll buffer.

This command is not in the original ANSI terminal control sequences but
was added later to XTerm to account for the fact that most modern
terminals have a scroll-buffer.

https://invisible-island.net/xterm/ctlseqs/ctlseqs.html#h4-Functions-using-CSI-_-ordered-by-the-final-character-lparen-s-rparen:CSI-Ps-J.1C8A

This command is now awailable in basically
all terminals with scroll-buffers

2. Change CUP coordinates to 1, 1

The coordinates 0, 0 also worked, but strictly speaking they are outside
the available screen area and are capped to 1, 1 anyways.

This commit fixes #337
2021-04-06 22:42:03 +02:00
Christian Wischenbart
256fcdd27f Remove redundant Style constructor. 2021-04-06 07:30:31 -04:00
Patrik Svensson
dafbfe63ba Update link to docs site 2021-04-05 17:54:32 +02:00
Patrik Svensson
a2ab522516 Add CNAME 2021-04-05 17:45:29 +02:00
Patrik Svensson
8778ab1739 Set new host for docs 2021-04-05 17:41:18 +02:00
Patrik Svensson
693e1fa170 Update links, references and copyright 2021-04-05 16:59:09 +02:00
Patrik Svensson
4b37a4708f Update documentation 2021-04-05 16:48:02 +02:00
Phil Scott
a690ce4955 Marks nullable bools as flags too 2021-04-05 16:14:13 +02:00
Andreia Gaita
759b16aed9 Fix OS version detection 2021-04-04 09:28:20 -04:00
Phil Scott
254880e93a Replaces emoji regex with ReadOnlySpan implementation
The RegEx runtime perf was never anything noticeable - it was the startup time that was eating over a third of time during initialization.

This shaves 200ms off the startup time.
2021-04-04 04:10:25 +02:00
Patrik Svensson
6f16081f42 Add support for indeterminate progress
This commit also changes the behavior of ProgressContext.IsFinished.
Only tasks that have been started will be taken into consideration,
and not indeterminate tasks.

Closes #329
Closes #331
2021-04-03 09:42:49 -04:00
MB
6121203fee Rename tree to root so the example compiles.
The 'root' variable does not exist in current context. Either should call Render(tree) or have it renamed to root. I've chosen root as it's more consistent with the examples later on.
2021-04-02 23:32:15 +02:00
Phil Scott
9204671b27 Uses Environment.TickCount for seed instead of DateTime.Now 2021-04-02 18:52:18 +02:00
Phil Scott
c765bbd0dd Uses OSVersion instead of RegEx to detect Windows Build info
Perf improvement.
2021-04-02 18:51:30 +02:00
Thomas Freudenberg
6bceac8a5e enable disposing ITypeResolver 2021-03-30 00:53:38 +02:00
Patrik Svensson
1ed7e65fcb Make VT-100 sequences easier to understand 2021-03-28 12:51:19 -04:00
Patrik Svensson
20650f1e7e Change IAnsiConsole to render IRenderable
This makes it possible for encoders to output better representation
of the actual objects instead of working with chopped up segments.

* IAnsiConsole.Write now takes an IRenderable instead of segments
* Calculating cell width does no longer require a render context
* Removed RenderContext.LegacyConsole
* Removed RenderContext.Encoding
* Added Capabilities.Unicode
2021-03-28 09:06:06 -04:00
Alexey Golub
2ba6da3514 Respect encoding of TextWriter provided to AnsiConsole.Create(...) 2021-03-25 21:19:49 +01:00
Alexey Golub
8830779875 Add params to ProgressExtensions.Columns(...)
This way you can omit `new ProgressColumn[] { ... }` and just list the columns separated by comma.
2021-03-25 21:11:51 +01:00
Patrik Svensson
9c46c21e27 Fix argument order
Closes #319
2021-03-24 18:58:17 -04:00
Reilly Wood
c643ec735d Fix documentation for ProgressContext.AddTask 2021-03-24 07:34:56 -04:00
Phil Scott
b17eabaa1f Adds helper overloads for Markup calls without args
Without specific overloads without the args string.format will get called even if it's not needed. 

This closes #309
2021-03-22 19:14:59 +01:00
Patrik Svensson
7f6f2437b1 Add support for exclusive mode 2021-03-15 13:14:40 -04:00
Patrik Svensson
c2bab0ebf8 Allow custom instructions for prompts
Closes #229
2021-03-14 21:27:44 -04:00
Patrik Svensson
9502aaf2b9 Allow markup in selection prompts
Closes #221
2021-03-14 21:27:44 -04:00
Patrik Svensson
57a8e6ccc1 Support Home, End, PgUp, and PgDown in prompts
Closes #296
2021-03-14 21:27:44 -04:00
Patrik Svensson
8c099a0038 Add Elmah.io as sponsor 2021-03-14 21:17:56 -04:00
Bastian Eicher
08b65cfa47 Fix Windows ANSI support detection with redirected stderr 2021-03-14 23:41:07 +01:00
Christopher-Marcel Esser
2540f48622 Hide examples of hidden commands 2021-03-13 23:21:48 +01:00
234 changed files with 2868 additions and 1214 deletions

View File

@@ -21,7 +21,7 @@ jobs:
- name: Setup dotnet
uses: actions/setup-dotnet@v1
with:
dotnet-version: 5.0.100
dotnet-version: 5.0.202
- name: Build
shell: bash
@@ -63,7 +63,7 @@ jobs:
- name: Setup dotnet 5.0.100
uses: actions/setup-dotnet@v1
with:
dotnet-version: 5.0.100
dotnet-version: 5.0.202
- name: Integration Tests
shell: bash

View File

@@ -24,7 +24,7 @@ jobs:
- name: Setup dotnet
uses: actions/setup-dotnet@v1
with:
dotnet-version: 5.0.100
dotnet-version: 5.0.202
- name: Publish
shell: bash

View File

@@ -29,7 +29,7 @@ jobs:
- name: Setup dotnet
uses: actions/setup-dotnet@v1
with:
dotnet-version: 5.0.100
dotnet-version: 5.0.202
- name: Build
shell: bash
@@ -72,7 +72,7 @@ jobs:
- name: Setup dotnet 5.0.100
uses: actions/setup-dotnet@v1
with:
dotnet-version: 5.0.100
dotnet-version: 5.0.202
- name: Build
shell: bash
@@ -103,7 +103,7 @@ jobs:
- name: Setup dotnet 5.0.100
uses: actions/setup-dotnet@v1
with:
dotnet-version: 5.0.100
dotnet-version: 5.0.202
- name: Publish
shell: bash

View File

@@ -22,8 +22,8 @@ By contributing to Spectre.Console, you assert that:
* The contribution is your own original work.
* You have the right to assign the copyright for the work (it is not owned by your employer, or
you have been given copyright assignment in writing).
* You [license](https://github.com/spectresystems/spectre.console/blob/main/LICENSE) the contribution under the terms applied to the rest of the Spectre.Console project.
* You agree to follow the [code of conduct](https://github.com/spectresystems/spectre.console/blob/main/CODE_OF_CONDUCT.md).
* You [license](https://github.com/spectreconsole/spectre.console/blob/main/LICENSE) the contribution under the terms applied to the rest of the Spectre.Console project.
* You agree to follow the [code of conduct](https://github.com/spectreconsole/spectre.console/blob/main/CODE_OF_CONDUCT.md).
## Definition of trivial contributions
It's hard to define what is a trivial contribution. Sometimes even a 1 character change can be considered significant.
@@ -53,19 +53,19 @@ Any new code should also have reasonable unit test coverage.
## Contributing process
### Get buyoff or find open community issues or features
* Through GitHub, or through the [GitHub discussions](https://github.com/spectresystems/spectre.console/discussions) (preferred),
* Through GitHub, or through the [GitHub discussions](https://github.com/spectreconsole/spectre.console/discussions) (preferred),
you talk about a feature you would like to see (or a bug), and why it should be in Spectre.Console.
* If approved through the GitHub discussions, ensure an accompanying GitHub issue is created with
information and a link back to the discussion.
* Once you get a nod from someone in the Spectre.Console Team, you can start on the feature.
* Alternatively, if a feature is on the issues list with the
[Up For Grabs](https://github.com/spectresystems/spectre.console/labels/up-for-grabs) label,
[Up For Grabs](https://github.com/spectreconsole/spectre.console/labels/up-for-grabs) label,
it is open for a community member (contributor) to patch. You should comment that you are signing up for it on
the issue so someone else doesn't also sign up for the work.
### Set up your environment
* You create, or update, a fork of `spectresystems/spectre.console` under your GitHub account.
* You create, or update, a fork of `spectreconsole/spectre.console` under your GitHub account.
* From there you create a branch named specific to the feature.
* In the branch you do work specific to the feature.
* Please also observe the following:
@@ -96,7 +96,7 @@ Prerequisites:
Submitting PR:
* Once you feel it is ready, submit the pull request to the `spectresystems/spectre.console` repository against the `main` branch
* Once you feel it is ready, submit the pull request to the `spectreconsole/spectre.console` repository against the `main` branch
unless specifically requested to submit it against another branch.
* In the case of a larger change that is going to require more discussion,
please submit a PR sooner. Waiting until you are ready may mean more changes than you are
@@ -129,7 +129,7 @@ the issue/open a new PR (referencing old one).
Sometimes we may need you to rebase your commit against the latest code before we can review it further.
If this happens, you can do the following:
* `git fetch upstream` (upstream remote would be `spectresystems/spectre.console`)
* `git fetch upstream` (upstream remote would be `spectreconsole/spectre.console`)
* `git checkout main`
* `git rebase upstream/main`
* `git checkout your-branch`

View File

@@ -1,6 +1,6 @@
MIT License
Copyright (c) 2020 Spectre Systems AB
Copyright (c) 2020 Patrik Svensson, Phil Scott
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal

6
NuGet.Config Normal file
View File

@@ -0,0 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<packageSources>
<add key="nuget.org" value="https://api.nuget.org/v3/index.json" protocolVersion="3" />
</packageSources>
</configuration>

View File

@@ -39,7 +39,7 @@ dotnet add package Spectre.Console
مستندات `Spectre.Console` را در اینجا می‌توایند پیدا کنید:
<div dir="ltr">
https://spectresystems.github.io/spectre.console/
https://spectreconsole.net/
</div>
<h2 id="examples">مثال‌ها</h2>
@@ -67,7 +67,7 @@ https://spectresystems.github.io/spectre.console/
<h2 id="license">مجوز</h2>
<div dir="ltr">
Copyright © Spectre Systems.
Copyright © Patrik Svensson, Phil Scott
</div>
همانطور که Spectre.Console تحت مجوز MIT ارائه شده است؛ برای کسب اطلاعات بیشتر به مجوز مراجعه کنید.

View File

@@ -40,7 +40,7 @@ dotnet add package Spectre.Console
## Documentation
The documentation for `Spectre.Console` can be found at
https://spectresystems.github.io/spectre.console/
https://spectreconsole.net/
## Examples
@@ -78,13 +78,14 @@ Spectre.Console to show their support and to ensure the longevity of the project
* [Viktor Elofsson](https://github.com/vktr)
* [Steven Knox](https://github.com/stevenknox)
* [David Pendray](https://github.com/dpen2000)
* [Elmah.io](https://github.com/elmahio)
I really appreciate it.
**Thank you very much!**
## License
Copyright © Spectre Systems.
Copyright © Patrik Svensson, Phil Scott
Spectre.Console is provided as-is under the MIT license. For more information see LICENSE.

View File

@@ -34,7 +34,7 @@ dotnet add package Spectre.Console
## 文档
`Spectre.Console`的文档可以在这里查看
https://spectresystems.github.io/spectre.console/
https://spectreconsole.net/
## 例子
@@ -58,7 +58,7 @@ https://spectresystems.github.io/spectre.console/
## License
版权所有 © Spectre Systems。
版权所有 © Patrik Svensson, Phil Scott
Spectre.Console 基于 MIT 协议提供。查看 LICENSE 文件了解更多信息。

View File

@@ -1 +1 @@
dotnet run -- preview --virtual-dir "spectre.console"
dotnet run -- preview

View File

@@ -11,11 +11,10 @@ namespace Docs
public static async Task<int> Main(string[] args) =>
await Bootstrapper.Factory
.CreateWeb(args)
.AddSetting(Keys.Host, "spectresystems.github.io")
.AddSetting(Keys.LinkRoot, "/spectre.console")
.AddSetting(Keys.Host, "spectreconsole.net")
.AddSetting(Keys.LinksUseHttps, true)
.AddSetting(Constants.EditLink, ConfigureEditLink())
.ConfigureSite("spectresystems", "spectre.console", "main")
.ConfigureSite("spectreconsole", "spectre.console", "main")
.ConfigureDeployment(deployBranch: "docs")
.AddShortcode("Children", typeof(ChildrenShortcode))
.AddShortcode("ColorTable", typeof(ColorTableShortcode))

View File

@@ -1,6 +1,6 @@
# Documentation
To start contributing to the [Spectre.Console](https://github.com/spectresystems/spectre.console) documentation, you will need the [.NET Core SDK](https://dot.net) 3.1 or higher.
To start contributing to the [Spectre.Console](https://github.com/spectreconsole/spectre.console) documentation, you will need the [.NET Core SDK](https://dot.net) 3.1 or higher.
## Running Preview Site
@@ -35,7 +35,7 @@ The documentation site has custom enhancements to Statiq located under the [./sr
MIT License
Copyright (c) 2020 Spectre Systems AB
Copyright (c) 2020 Patrik Svensson, Phil Scott
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

1
docs/input/CNAME Normal file
View File

@@ -0,0 +1 @@
spectreconsole.net

View File

@@ -41,7 +41,7 @@
<a class="nav-link font-weight-light font-size-lg text-red" href="https://github.com/sponsors/patriksvensson"><i class="far fa-heart"></i> Sponsor</a>
</li>
<li class="nav-item">
<a class="nav-link font-weight-light font-size-lg" href="https://github.com/spectresystems/spectre.console"><i class="fab fa-github"></i> GitHub</a>
<a class="nav-link font-weight-light font-size-lg" href="https://github.com/spectreconsole/spectre.console"><i class="fab fa-github"></i> GitHub</a>
</li>
</ul>
</div>
@@ -203,7 +203,7 @@
<div id="footer" class="p-3 text-white font-size-sm">
<div class="container">
<div>
<span>© @DateTime.Today.Year Spectre Systems AB</span>
<span>© @DateTime.Today.Year Patrik Svensson, Phil Scott</span>
<span class="float-right" style="color: #888888;">@VersionUtilities.GetVersion()</span>
</div>
</div>

View File

@@ -75,6 +75,8 @@ public class AddReferenceCommand : Command<AddReferenceSettings>
}
```
You can use `AsyncCommand` if you need async support.
## Let's tie it together
Now when we have our commands and settings implemented, we can compose a command tree

View File

@@ -0,0 +1,12 @@
Title: Live Displays
Order: 4
---
<h1>Sections</h1>
<ul>
@foreach (IDocument child in OutputPages.GetChildrenOf(Document))
{
<li>@Html.DocumentLink(child)</li>
}
</ul>

View File

@@ -1,16 +1,23 @@
Title: Progress
Order: 5
RedirectFrom: progress
---
Spectre.Console can display information about long running tasks in the console.
<img src="assets/images/progress.png" style="max-width: 100%;margin-bottom:20px;">
<img src="../assets/images/progress.png" style="max-width: 100%;margin-bottom:20px;">
<div class="alert alert-warning" role="alert">
<i class="fas fa-exclamation-triangle icon-web"></i> The progress display is not
thread safe, and using it together with other interactive components such as
prompts, status displays or other progress displays are not supported.
</div>
If the current terminal isn't considered "interactive", such as when running
in a continuous integration system, or the terminal can't display
ANSI control sequence, any progress will be displayed in a simpler way.
<img src="assets/images/progress_fallback.png" style="max-width: 100%;">
<img src="../assets/images/progress_fallback.png" style="max-width: 100%;">
# Usage

View File

@@ -1,10 +1,17 @@
Title: Status
Order: 6
RedirectFrom: status
---
Spectre.Console can display information about long running tasks in the console.
<img src="assets/images/status.gif" style="max-width: 100%;margin-bottom:20px;">
<img src="../assets/images/status.gif" style="max-width: 100%;margin-bottom:20px;">
<div class="alert alert-warning" role="alert">
<i class="fas fa-exclamation-triangle icon-web"></i> The status display is not
thread safe, and using it together with other interactive components such as
prompts, progress displays or other status displays are not supported.
</div>
If the current terminal isn't considered "interactive", such as when running
in a continuous integration system, or the terminal can't display

View File

@@ -7,6 +7,11 @@ one or many items from a provided list.
<img src="../assets/images/multiselection.gif" style="width: 100%;" />
<div class="alert alert-warning" role="alert" style="margin-top:20px;">
<i class="fas fa-exclamation-triangle icon-web"></i> The use of prompts
insides status or progress displays is not supported.
</div>
# Usage
```csharp
@@ -16,6 +21,10 @@ var fruits = AnsiConsole.Prompt(
.Title("What are your [green]favorite fruits[/]?")
.NotRequired() // Not required to have a favorite fruit
.PageSize(10)
.MoreChoicesText("[grey](Move up and down to reveal more fruits)[/]")
.InstructionsText(
"[grey](Press [blue]<space>[/] to toggle a fruit, " +
"[green]<enter>[/] to accept)[/]")
.AddChoice("Apple")
.AddChoices(new[] {
"Apricot", "Avocado",

View File

@@ -7,6 +7,11 @@ a single item from a provided list.
<img src="../assets/images/selection.gif" style="width: 100%;" />
<div class="alert alert-warning" role="alert" style="margin-top:20px;">
<i class="fas fa-exclamation-triangle icon-web"></i> Using prompts inside
status or progress displays, are not supported.
</div>
# Usage
```csharp
@@ -15,6 +20,7 @@ var fruit = AnsiConsole.Prompt(
new SelectionPrompt<string>()
.Title("What's your [green]favorite fruit[/]?")
.PageSize(10)
.MoreChoicesText("[grey](Move up and down to reveal more fruits)[/]")
.AddChoice("Apple")
.AddChoices(new[] {
"Apricot", "Avocado",

View File

@@ -1,4 +1,4 @@
Title: Text
Title: Text prompt
Order: 0
RedirectFrom: prompt
---
@@ -6,6 +6,11 @@ RedirectFrom: prompt
Sometimes you want to get some input from the user, and for this
you can use the `Prompt<TResult>`.
<div class="alert alert-warning" role="alert">
<i class="fas fa-exclamation-triangle icon-web"></i> The use of prompts
insides status or progress displays is not supported.
</div>
# Confirmation
```csharp

View File

@@ -14,6 +14,7 @@ Spectre.Console to show their support and to ensure the longevity of the project
* [Viktor Elofsson](https://github.com/vktr)
* [Steven Knox](https://github.com/stevenknox)
* [David Pendray](https://github.com/dpen2000)
* [Elmah.io](https://github.com/elmahio)
I really appreciate it.
**Thank you very much!**

View File

@@ -10,10 +10,10 @@ The `Tree` widget can be used to render hierarchical data.
```csharp
// Create the tree
var tree = new Tree("Root");
var root = new Tree("Root");
// Add some nodes
var foo = tree.AddNode("[yellow]Foo[/]");
var foo = root.AddNode("[yellow]Foo[/]");
var table = foo.AddNode(new Table()
.RoundedBorder()
.AddColumn("First")
@@ -25,7 +25,7 @@ var table = foo.AddNode(new Table()
table.AddNode("[blue]Baz[/]");
foo.AddNode("Qux");
var bar = tree.AddNode("[yellow]Bar[/]");
var bar = root.AddNode("[yellow]Bar[/]");
bar.AddNode(new Calendar(2020, 12)
.AddCalendarEvent(2020, 12, 12)
.HideHeader());
@@ -67,4 +67,4 @@ var root = new Tree("Root")
// Bold guide lines
var root = new Tree("Root")
.Guide(TreeGuide.BoldLine);
```
```

View File

@@ -17,7 +17,7 @@ namespace Docs
public static class Colors
{
public const string Url = "https://raw.githubusercontent.com/spectresystems/spectre.console/main/resources/scripts/Generator/Data/colors.json";
public const string Url = "https://raw.githubusercontent.com/spectreconsole/spectre.console/main/resources/scripts/Generator/Data/colors.json";
public const string Root = "COLORS_ROOT";
}

View File

@@ -3,7 +3,7 @@
"isRoot": true,
"tools": {
"cake.tool": {
"version": "1.0.0-rc0002",
"version": "1.1.0",
"commands": [
"dotnet-cake"
]

View File

@@ -1,7 +1,7 @@
using System.ComponentModel;
using Spectre.Console.Cli;
namespace Delegates
namespace Spectre.Console.Examples
{
public static partial class Program
{

View File

@@ -1,4 +1,4 @@
<Project Sdk="Microsoft.NET.Sdk">
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>Exe</OutputType>
@@ -11,7 +11,7 @@
</PropertyGroup>
<ItemGroup>
<ProjectReference Include="..\..\..\src\Spectre.Console\Spectre.Console.csproj" />
<ProjectReference Include="..\..\Shared\Shared.csproj" />
</ItemGroup>
</Project>

View File

@@ -1,7 +1,6 @@
using System;
using Spectre.Console.Cli;
namespace Delegates
namespace Spectre.Console.Examples
{
public static partial class Program
{
@@ -22,7 +21,7 @@ namespace Delegates
private static int Foo(CommandContext context)
{
Console.WriteLine("Foo");
AnsiConsole.WriteLine("Foo");
return 0;
}
@@ -30,7 +29,7 @@ namespace Delegates
{
for (var index = 0; index < settings.Count; index++)
{
Console.WriteLine("Bar");
AnsiConsole.WriteLine("Bar");
}
return 0;

View File

@@ -1,4 +1,4 @@
<Project Sdk="Microsoft.NET.Sdk">
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>Exe</OutputType>
@@ -11,7 +11,7 @@
</PropertyGroup>
<ItemGroup>
<ProjectReference Include="..\..\..\src\Spectre.Console\Spectre.Console.csproj" />
<ProjectReference Include="..\..\Shared\Shared.csproj" />
</ItemGroup>
</Project>

View File

@@ -1,7 +1,7 @@
using System;
using Spectre.Console.Cli;
namespace Dynamic
namespace Spectre.Console.Examples
{
public sealed class MyCommand : Command
{
@@ -13,7 +13,7 @@ namespace Dynamic
}
Console.WriteLine("Value = {0}", data);
AnsiConsole.WriteLine("Value = {0}", data);
return 0;
}
}

View File

@@ -1,7 +1,7 @@
using System.Linq;
using Spectre.Console.Cli;
namespace Dynamic
namespace Spectre.Console.Examples
{
public static class Program
{

View File

@@ -2,7 +2,7 @@ using System;
using System.ComponentModel;
using Spectre.Console.Cli;
namespace Injection.Commands
namespace Spectre.Console.Examples
{
public sealed class DefaultCommand : Command<DefaultCommand.Settings>
{

View File

@@ -1,6 +1,4 @@
using System;
namespace Injection
namespace Spectre.Console.Examples
{
public interface IGreeter
{
@@ -11,7 +9,7 @@ namespace Injection
{
public void Greet(string name)
{
Console.WriteLine($"Hello {name}!");
AnsiConsole.WriteLine($"Hello {name}!");
}
}
}

View File

@@ -2,7 +2,7 @@ using System;
using Microsoft.Extensions.DependencyInjection;
using Spectre.Console.Cli;
namespace Injection
namespace Spectre.Console.Examples
{
public sealed class TypeRegistrar : ITypeRegistrar
{

View File

@@ -2,9 +2,9 @@ using System;
using Microsoft.Extensions.DependencyInjection;
using Spectre.Console.Cli;
namespace Injection
namespace Spectre.Console.Examples
{
public sealed class TypeResolver : ITypeResolver
public sealed class TypeResolver : ITypeResolver, IDisposable
{
private readonly IServiceProvider _provider;
@@ -17,5 +17,13 @@ namespace Injection
{
return _provider.GetRequiredService(type);
}
public void Dispose()
{
if (_provider is IDisposable disposable)
{
disposable.Dispose();
}
}
}
}

View File

@@ -15,7 +15,7 @@
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\..\..\src\Spectre.Console\Spectre.Console.csproj" />
<ProjectReference Include="..\..\Shared\Shared.csproj" />
</ItemGroup>
</Project>

View File

@@ -1,8 +1,7 @@
using Injection.Commands;
using Microsoft.Extensions.DependencyInjection;
using Spectre.Console.Cli;
namespace Injection
namespace Spectre.Console.Examples
{
public class Program
{

View File

@@ -1,8 +1,7 @@
using Microsoft.Extensions.Logging;
using Spectre.Console;
using Microsoft.Extensions.Logging;
using Spectre.Console.Cli;
namespace Logging.Commands
namespace Spectre.Console.Examples
{
public class HelloCommand : Command<HelloCommand.Settings>
{

View File

@@ -1,11 +1,11 @@
using System;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Globalization;
using Serilog.Events;
using Spectre.Console.Cli;
namespace Logging.Commands
namespace Spectre.Console.Examples
{
public class LogCommandSettings : CommandSettings
{

View File

@@ -1,8 +1,7 @@
using Logging.Commands;
using Serilog.Core;
using Spectre.Console.Cli;
namespace Logging
namespace Spectre.Console.Examples
{
public class LogInterceptor : ICommandInterceptor
{

View File

@@ -1,7 +1,7 @@
using Serilog.Core;
using Serilog.Core;
using Serilog.Events;
namespace Logging
namespace Spectre.Console.Examples
{
internal class LoggingEnricher : ILogEventEnricher
{

View File

@@ -1,8 +1,8 @@
using System;
using System;
using Microsoft.Extensions.DependencyInjection;
using Spectre.Console.Cli;
namespace Logging
namespace Spectre.Console.Examples
{
public sealed class TypeRegistrar : ITypeRegistrar
{

View File

@@ -1,8 +1,8 @@
using System;
using System;
using Microsoft.Extensions.DependencyInjection;
using Spectre.Console.Cli;
namespace Logging
namespace Spectre.Console.Examples
{
public sealed class TypeResolver : ITypeResolver
{

View File

@@ -20,7 +20,7 @@
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\..\..\src\Spectre.Console\Spectre.Console.csproj" />
<ProjectReference Include="..\..\Shared\Shared.csproj" />
</ItemGroup>
</Project>

View File

@@ -1,4 +1,3 @@
using Logging.Commands;
using Microsoft.Extensions.DependencyInjection;
using Serilog;
using Spectre.Console.Cli;
@@ -13,7 +12,7 @@ using Spectre.Console.Cli;
* Spectre.Console CommandInterceptor
*/
namespace Logging
namespace Spectre.Console.Examples
{
public class Program
{

View File

@@ -9,7 +9,7 @@
</PropertyGroup>
<ItemGroup>
<ProjectReference Include="..\..\..\src\Spectre.Console\Spectre.Console.csproj" />
<ProjectReference Include="..\..\Shared\Shared.csproj" />
</ItemGroup>
</Project>

View File

@@ -1,7 +1,6 @@
using Spectre.Console;
using Spectre.Console.Rendering;
namespace BordersExample
namespace Spectre.Console.Examples
{
public static class Program
{

View File

@@ -9,7 +9,7 @@
</PropertyGroup>
<ItemGroup>
<ProjectReference Include="..\..\..\src\Spectre.Console\Spectre.Console.csproj" />
<ProjectReference Include="..\..\Shared\Shared.csproj" />
</ItemGroup>
</Project>

View File

@@ -1,6 +1,4 @@
using Spectre.Console;
namespace Calendars
namespace Spectre.Console.Examples
{
public static class Program
{

View File

@@ -9,8 +9,8 @@
</PropertyGroup>
<ItemGroup>
<ProjectReference Include="..\..\Shared\Shared.csproj" />
<ProjectReference Include="..\..\..\src\Spectre.Console.ImageSharp\Spectre.Console.ImageSharp.csproj" />
<ProjectReference Include="..\..\..\src\Spectre.Console\Spectre.Console.csproj" />
</ItemGroup>
<ItemGroup>

View File

@@ -4,9 +4,8 @@ Licensed under GNU Free Documentation License 1.2
*/
using System;
using Spectre.Console;
namespace CanvasExample
namespace Spectre.Console.Examples
{
public static class Mandelbrot
{

View File

@@ -1,10 +1,9 @@
using System.Diagnostics;
using System.Reflection;
using SixLabors.ImageSharp.Processing;
using Spectre.Console;
using Spectre.Console.Rendering;
namespace CanvasExample
namespace Spectre.Console.Examples
{
public static class Program
{

View File

@@ -9,7 +9,7 @@
</PropertyGroup>
<ItemGroup>
<ProjectReference Include="..\..\..\src\Spectre.Console\Spectre.Console.csproj" />
<ProjectReference Include="..\..\Shared\Shared.csproj" />
</ItemGroup>
</Project>

View File

@@ -1,7 +1,6 @@
using Spectre.Console;
using Spectre.Console.Rendering;
namespace Charts
namespace Spectre.Console.Examples
{
public static class Program
{

View File

@@ -9,7 +9,7 @@
</PropertyGroup>
<ItemGroup>
<ProjectReference Include="..\..\..\src\Spectre.Console\Spectre.Console.csproj" />
<ProjectReference Include="..\..\Shared\Shared.csproj" />
</ItemGroup>
</Project>

View File

@@ -1,27 +1,23 @@
using Spectre.Console;
namespace ColorExample
namespace Spectre.Console.Examples
{
public static class Program
{
public static void Main()
{
if (AnsiConsole.Profile.ColorSystem == ColorSystem.NoColors)
/////////////////////////////////////////////////////////////////
// No colors
/////////////////////////////////////////////////////////////////
if (AnsiConsole.Profile.Capabilities.ColorSystem == ColorSystem.NoColors)
{
/////////////////////////////////////////////////////////////////
// No colors
/////////////////////////////////////////////////////////////////
AnsiConsole.WriteLine("No colors are supported.");
return;
}
/////////////////////////////////////////////////////////////////
// 3-BIT
/////////////////////////////////////////////////////////////////
if (AnsiConsole.Profile.Supports(ColorSystem.Legacy))
{
/////////////////////////////////////////////////////////////////
// 3-BIT
/////////////////////////////////////////////////////////////////
AnsiConsole.ResetColors();
AnsiConsole.WriteLine();
AnsiConsole.Render(new Rule("[yellow bold underline]3-bit Colors[/]").RuleStyle("grey").LeftAligned());
@@ -30,6 +26,7 @@ namespace ColorExample
for (var i = 0; i < 8; i++)
{
AnsiConsole.Background = Color.FromInt32(i);
AnsiConsole.Foreground = AnsiConsole.Background.GetInvertedColor();
AnsiConsole.Write(string.Format(" {0,-9}", AnsiConsole.Background.ToString()));
AnsiConsole.ResetColors();
if ((i + 1) % 8 == 0)
@@ -39,12 +36,11 @@ namespace ColorExample
}
}
/////////////////////////////////////////////////////////////////
// 4-BIT
/////////////////////////////////////////////////////////////////
if (AnsiConsole.Profile.Supports(ColorSystem.Standard))
{
/////////////////////////////////////////////////////////////////
// 4-BIT
/////////////////////////////////////////////////////////////////
AnsiConsole.ResetColors();
AnsiConsole.WriteLine();
AnsiConsole.Render(new Rule("[yellow bold underline]4-bit Colors[/]").RuleStyle("grey").LeftAligned());
@@ -53,6 +49,7 @@ namespace ColorExample
for (var i = 0; i < 16; i++)
{
AnsiConsole.Background = Color.FromInt32(i);
AnsiConsole.Foreground = AnsiConsole.Background.GetInvertedColor();
AnsiConsole.Write(string.Format(" {0,-9}", AnsiConsole.Background.ToString()));
AnsiConsole.ResetColors();
if ((i + 1) % 8 == 0)
@@ -62,12 +59,11 @@ namespace ColorExample
}
}
/////////////////////////////////////////////////////////////////
// 8-BIT
/////////////////////////////////////////////////////////////////
if (AnsiConsole.Profile.Supports(ColorSystem.EightBit))
{
/////////////////////////////////////////////////////////////////
// 8-BIT
/////////////////////////////////////////////////////////////////
AnsiConsole.ResetColors();
AnsiConsole.WriteLine();
AnsiConsole.Render(new Rule("[yellow bold underline]8-bit Colors[/]").RuleStyle("grey").LeftAligned());
@@ -79,6 +75,7 @@ namespace ColorExample
{
var number = i * 16 + j;
AnsiConsole.Background = Color.FromInt32(number);
AnsiConsole.Foreground = AnsiConsole.Background.GetInvertedColor();
AnsiConsole.Write(string.Format(" {0,-4}", number));
AnsiConsole.ResetColors();
if ((number + 1) % 16 == 0)
@@ -89,31 +86,17 @@ namespace ColorExample
}
}
/////////////////////////////////////////////////////////////////
// 24-BIT
/////////////////////////////////////////////////////////////////
if (AnsiConsole.Profile.Supports(ColorSystem.TrueColor))
{
/////////////////////////////////////////////////////////////////
// 24-BIT
/////////////////////////////////////////////////////////////////
AnsiConsole.ResetColors();
AnsiConsole.WriteLine();
AnsiConsole.Render(new Rule("[yellow bold underline]24-bit Colors[/]").RuleStyle("grey").LeftAligned());
AnsiConsole.WriteLine();
var index = 0;
for (var i = 0.0005; i < 1; i += 0.0025)
{
index++;
var color = Utilities.HSL2RGB(i, 0.5, 0.5);
AnsiConsole.Background = new Color(color.R, color.G, color.B);
AnsiConsole.Write(" ");
if (index % 50 == 0)
{
AnsiConsole.WriteLine();
}
}
AnsiConsole.Render(new ColorBox(width: 80, height: 15));
}
}
}

View File

@@ -1,77 +0,0 @@
using System;
using Spectre.Console;
namespace ColorExample
{
public static class Utilities
{
// Borrowed from https://geekymonkey.com/Programming/CSharp/RGB2HSL_HSL2RGB.htm
public static Color HSL2RGB(double h, double sl, double l)
{
double v;
double r, g, b;
r = l; // default to gray
g = l;
b = l;
v = (l <= 0.5) ? (l * (1.0 + sl)) : (l + sl - l * sl);
if (v > 0)
{
double m;
double sv;
int sextant;
double fract, vsf, mid1, mid2;
m = l + l - v;
sv = (v - m) / v;
h *= 6.0;
sextant = (int)h;
fract = h - sextant;
vsf = v * sv * fract;
mid1 = m + vsf;
mid2 = v - vsf;
switch (sextant)
{
case 0:
r = v;
g = mid1;
b = m;
break;
case 1:
r = mid2;
g = v;
b = m;
break;
case 2:
r = m;
g = v;
b = mid1;
break;
case 3:
r = m;
g = mid2;
b = v;
break;
case 4:
r = mid1;
g = m;
b = v;
break;
case 5:
r = v;
g = m;
b = mid2;
break;
}
}
return new Color(
Convert.ToByte(r * 255.0f),
Convert.ToByte(g * 255.0f),
Convert.ToByte(b * 255.0f));
}
}
}

View File

@@ -13,7 +13,7 @@
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\..\..\src\Spectre.Console\Spectre.Console.csproj" />
<ProjectReference Include="..\..\Shared\Shared.csproj" />
</ItemGroup>
</Project>

View File

@@ -1,7 +1,6 @@
using System.Collections.Generic;
using Spectre.Console;
namespace ColumnsExample
namespace Spectre.Console.Examples
{
public static class Program
{

View File

@@ -1,6 +1,6 @@
using System.Collections.Generic;
namespace ColumnsExample
namespace Spectre.Console.Examples
{
public sealed class User
{
@@ -22,9 +22,9 @@ namespace ColumnsExample
},
new User
{
FirstName = "Brandon",
LastName = "Cole",
City = "Washington",
FirstName = "Phil",
LastName = "Scott",
City = "Dayton",
Country = "United States",
},
new User

View File

@@ -9,7 +9,7 @@
</PropertyGroup>
<ItemGroup>
<ProjectReference Include="..\..\..\src\Spectre.Console\Spectre.Console.csproj" />
<ProjectReference Include="..\..\Shared\Shared.csproj" />
</ItemGroup>
</Project>

View File

@@ -1,6 +1,4 @@
using Spectre.Console;
namespace Cursor
namespace Spectre.Console.Examples
{
public static class Program
{

View File

@@ -9,7 +9,7 @@
</PropertyGroup>
<ItemGroup>
<ProjectReference Include="..\..\..\src\Spectre.Console\Spectre.Console.csproj" />
<ProjectReference Include="..\..\Shared\Shared.csproj" />
</ItemGroup>
</Project>

View File

@@ -1,6 +1,4 @@
using Spectre.Console;
namespace EmojiExample
namespace Spectre.Console.Examples
{
public static class Program
{

View File

@@ -9,7 +9,7 @@
</PropertyGroup>
<ItemGroup>
<ProjectReference Include="..\..\..\src\Spectre.Console\Spectre.Console.csproj" />
<ProjectReference Include="..\..\Shared\Shared.csproj" />
</ItemGroup>
</Project>

View File

@@ -1,8 +1,7 @@
using System;
using System.Security.Authentication;
using Spectre.Console;
namespace Exceptions
namespace Spectre.Console.Examples
{
public static class Program
{

View File

@@ -9,7 +9,7 @@
</PropertyGroup>
<ItemGroup>
<ProjectReference Include="..\..\..\src\Spectre.Console\Spectre.Console.csproj" />
<ProjectReference Include="..\..\Shared\Shared.csproj" />
</ItemGroup>
</Project>

View File

@@ -1,6 +1,4 @@
using Spectre.Console;
namespace EmojiExample
namespace Spectre.Console.Examples
{
public static class Program
{

View File

@@ -9,7 +9,7 @@
</PropertyGroup>
<ItemGroup>
<ProjectReference Include="..\..\..\src\Spectre.Console\Spectre.Console.csproj" />
<ProjectReference Include="..\..\Shared\Shared.csproj" />
</ItemGroup>
</Project>

View File

@@ -1,6 +1,4 @@
using Spectre.Console;
namespace GridExample
namespace Spectre.Console.Examples
{
public static class Program
{

View File

@@ -9,7 +9,7 @@
</PropertyGroup>
<ItemGroup>
<ProjectReference Include="..\..\..\src\Spectre.Console\Spectre.Console.csproj" />
<ProjectReference Include="..\..\Shared\Shared.csproj" />
</ItemGroup>
</Project>

View File

@@ -1,6 +1,4 @@
using Spectre.Console;
namespace InfoExample
namespace Spectre.Console.Examples
{
public static class Program
{
@@ -10,12 +8,13 @@ namespace InfoExample
.AddColumn(new GridColumn().NoWrap().PadRight(4))
.AddColumn()
.AddRow("[b]Enrichers[/]", string.Join(", ", AnsiConsole.Profile.Enrichers))
.AddRow("[b]Color system[/]", $"{AnsiConsole.Profile.ColorSystem}")
.AddRow("[b]Color system[/]", $"{AnsiConsole.Profile.Capabilities.ColorSystem}")
.AddRow("[b]Unicode?[/]", $"{YesNo(AnsiConsole.Profile.Capabilities.Unicode)}")
.AddRow("[b]Supports ansi?[/]", $"{YesNo(AnsiConsole.Profile.Capabilities.Ansi)}")
.AddRow("[b]Supports links?[/]", $"{YesNo(AnsiConsole.Profile.Capabilities.Links)}")
.AddRow("[b]Legacy console?[/]", $"{YesNo(AnsiConsole.Profile.Capabilities.Legacy)}")
.AddRow("[b]Interactive?[/]", $"{YesNo(AnsiConsole.Profile.Capabilities.Interactive)}")
.AddRow("[b]TTY?[/]", $"{YesNo(AnsiConsole.Profile.Capabilities.Tty)}")
.AddRow("[b]Terminal?[/]", $"{YesNo(AnsiConsole.Profile.Out.IsTerminal)}")
.AddRow("[b]Buffer width[/]", $"{AnsiConsole.Console.Profile.Width}")
.AddRow("[b]Buffer height[/]", $"{AnsiConsole.Console.Profile.Height}")
.AddRow("[b]Encoding[/]", $"{AnsiConsole.Console.Profile.Encoding.EncodingName}");

View File

@@ -9,7 +9,7 @@
</PropertyGroup>
<ItemGroup>
<ProjectReference Include="..\..\..\src\Spectre.Console\Spectre.Console.csproj" />
<ProjectReference Include="..\..\Shared\Shared.csproj" />
</ItemGroup>
</Project>

View File

@@ -1,6 +1,4 @@
using Spectre.Console;
namespace LinkExample
namespace Spectre.Console.Examples
{
public static class Program
{

View File

@@ -9,7 +9,7 @@
</PropertyGroup>
<ItemGroup>
<ProjectReference Include="..\..\..\src\Spectre.Console\Spectre.Console.csproj" />
<ProjectReference Include="..\..\Shared\Shared.csproj" />
</ItemGroup>
</Project>

View File

@@ -1,6 +1,4 @@
using Spectre.Console;
namespace PanelExample
namespace Spectre.Console.Examples
{
public static class Program
{

View File

@@ -1,7 +1,7 @@
using System;
using System.Collections.Generic;
namespace ProgressExample
namespace Spectre.Console.Examples
{
public static class DescriptionGenerator
{

View File

@@ -1,9 +1,8 @@
using System;
using System.Collections.Generic;
using System.Threading;
using Spectre.Console;
namespace ProgressExample
namespace Spectre.Console.Examples
{
public static class Program
{
@@ -25,8 +24,12 @@ namespace ProgressExample
.Start(ctx =>
{
var random = new Random(DateTime.Now.Millisecond);
var tasks = CreateTasks(ctx, random);
// Create some tasks
var tasks = CreateTasks(ctx, random);
var warpTask = ctx.AddTask("Going to warp", autoStart: false).IsIndeterminate();
// Wait for all tasks (except the indeterminate one) to complete
while (!ctx.IsFinished)
{
// Increment progress
@@ -44,13 +47,24 @@ namespace ProgressExample
// Simulate some delay
Thread.Sleep(100);
}
// Now start the "warp" task
warpTask.StartTask();
warpTask.IsIndeterminate(false);
while (!ctx.IsFinished)
{
warpTask.Increment(12 * random.NextDouble());
// Simulate some delay
Thread.Sleep(100);
}
});
// Done
AnsiConsole.MarkupLine("[green]Done![/]");
}
private static List<(ProgressTask, int)> CreateTasks(ProgressContext progress, Random random)
private static List<(ProgressTask Task, int Delay)> CreateTasks(ProgressContext progress, Random random)
{
var tasks = new List<(ProgressTask, int)>();
while (tasks.Count < 5)

View File

@@ -13,7 +13,7 @@
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\..\..\src\Spectre.Console\Spectre.Console.csproj" />
<ProjectReference Include="..\..\Shared\Shared.csproj" />
</ItemGroup>
</Project>

View File

@@ -1,6 +1,4 @@
using Spectre.Console;
namespace Cursor
namespace Spectre.Console.Examples
{
public static class Program
{
@@ -59,6 +57,8 @@ namespace Cursor
new MultiSelectionPrompt<string>()
.PageSize(10)
.Title("What are your [green]favorite fruits[/]?")
.MoreChoicesText("[grey](Move up and down to reveal more fruits)[/]")
.InstructionsText("[grey](Press [blue]<space>[/] to toggle a fruit, [green]<enter>[/] to accept)[/]")
.AddChoices(new[]
{
"Apple", "Apricot", "Avocado", "Banana", "Blackcurrant", "Blueberry",
@@ -74,6 +74,7 @@ namespace Cursor
fruit = AnsiConsole.Prompt(
new SelectionPrompt<string>()
.Title("Ok, but if you could only choose [green]one[/]?")
.MoreChoicesText("[grey](Move up and down to reveal more fruits)[/]")
.AddChoices(favorites));
}
@@ -88,8 +89,8 @@ namespace Cursor
return AnsiConsole.Prompt(
new TextPrompt<string>("What's your [green]favorite sport[/]?")
.InvalidChoiceMessage("[red]That's not a valid fruit[/]")
.DefaultValue("Lol")
.InvalidChoiceMessage("[red]That's not a sport![/]")
.DefaultValue("Sport?")
.AddChoice("Soccer")
.AddChoice("Hockey")
.AddChoice("Basketball"));

View File

@@ -10,7 +10,7 @@
</PropertyGroup>
<ItemGroup>
<ProjectReference Include="..\..\..\src\Spectre.Console\Spectre.Console.csproj" />
<ProjectReference Include="..\..\Shared\Shared.csproj" />
</ItemGroup>
</Project>

View File

@@ -1,6 +1,4 @@
using Spectre.Console;
namespace EmojiExample
namespace Spectre.Console.Examples
{
public static class Program
{

View File

@@ -9,7 +9,7 @@
</PropertyGroup>
<ItemGroup>
<ProjectReference Include="..\..\..\src\Spectre.Console\Spectre.Console.csproj" />
<ProjectReference Include="..\..\Shared\Shared.csproj" />
</ItemGroup>
</Project>

View File

@@ -0,0 +1,30 @@
using System;
namespace Spectre.Console.Examples
{
public static class ExceptionGenerator
{
public static Exception GenerateException()
{
try
{
SomeOperation();
throw new InvalidOperationException();
}
catch (Exception ex)
{
return ex;
}
}
private static void SomeOperation()
{
SomeOperationGoingWrong();
}
private static void SomeOperationGoingWrong()
{
throw new InvalidOperationException("Something went very wrong!");
}
}
}

View File

@@ -0,0 +1,153 @@
using Spectre.Console.Rendering;
namespace Spectre.Console.Examples
{
public static partial class Program
{
public static void Main()
{
var table = new Table().HideHeaders().NoBorder();
table.Title("[u][yellow]Spectre.Console[/] [b]Features[/][/]");
table.AddColumn("Feature", c => c.NoWrap().RightAligned().Width(10).PadRight(3));
table.AddColumn("Demonstration", c => c.PadRight(0));
table.AddEmptyRow();
// Colors
table.AddRow(
new Markup("[red]Colors[/]"),
GetColorTable());
// Styles
table.AddEmptyRow();
table.AddRow(
new Markup("[red]OS[/]"),
new Grid().Expand().AddColumns(3)
.AddRow(
"[bold green]Windows[/]",
"[bold blue]macOS[/]",
"[bold yellow]Linux[/]"));
// Styles
table.AddEmptyRow();
table.AddRow(
"[red]Styles[/]",
"All ansi styles: [bold]bold[/], [dim]dim[/], [italic]italic[/], [underline]underline[/], "
+ "[strikethrough]strikethrough[/], [reverse]reverse[/], and even [blink]blink[/].");
// Text
table.AddEmptyRow();
table.AddRow(
new Markup("[red]Text[/]"),
new Markup("Word wrap text. Justify [green]left[/], [yellow]center[/] or [blue]right[/]."));
table.AddEmptyRow();
table.AddRow(
Text.Empty,
GetTextGrid());
// Markup
table.AddEmptyRow();
table.AddRow(
"[red]Markup[/]",
"[bold purple]Spectre.Console[/] supports a simple [i]bbcode[/] like "
+ "[b]markup[/] for [yellow]color[/], [underline]style[/], and emoji! "
+ ":thumbs_up: :red_apple: :ant: :bear: :baguette_bread: :bus:");
// Trees and tables
table.AddEmptyRow();
table.AddRow(
new Markup("[red]Tables and Trees[/]"),
GetTreeTable());
// Charts
table.AddRow(
new Markup("[red]Charts[/]"),
new Grid().Collapse().AddColumns(2).AddRow(
new Panel(GetBreakdownChart()).BorderColor(Color.Grey),
new Panel(GetBarChart()).BorderColor(Color.Grey)));
// Exceptions
table.AddEmptyRow();
table.AddRow(
new Markup("[red]Exceptions[/]"),
ExceptionGenerator.GenerateException().GetRenderable());
// Much more
table.AddEmptyRow();
table.AddRow(
"[red]+ Much more![/]",
"Tables, Grids, Trees, Progress bars, Status, Bar charts, Calendars, Figlet, Images, Text prompts, "
+ "List boxes, Separators, Pretty exceptions, Canvas, CLI parsing");
table.AddEmptyRow();
// Render the table
AnsiConsole.WriteLine();
AnsiConsole.Render(table);
}
private static IRenderable GetColorTable()
{
var colorTable = new Table().Collapse().HideHeaders().NoBorder();
colorTable.AddColumn("Desc", c => c.PadRight(3)).AddColumn("Colors", c => c.PadRight(0));
colorTable.AddRow(
new Markup(
"✓ [bold grey]NO_COLOR support[/]\n" +
"✓ [bold green]3-bit color[/]\n" +
"✓ [bold blue]4-bit color[/]\n" +
"✓ [bold purple]8-bit color[/]\n" +
"✓ [bold yellow]Truecolor (16.7 million)[/]\n" +
"✓ [bold aqua]Automatic color conversion[/]"),
new ColorBox(height: 6));
return colorTable;
}
private static IRenderable GetTextGrid()
{
var loremTable = new Grid();
var lorem = "Lorem ipsum dolor sit amet, consectetur adipiscing elit. Quisque in metus sed sapien ultricies pretium a at justo. Maecenas luctus velit et auctor maximus.";
loremTable.AddColumn(new GridColumn().LeftAligned());
loremTable.AddColumn(new GridColumn().Centered());
loremTable.AddColumn(new GridColumn().RightAligned());
loremTable.AddRow($"[green]{lorem}[/]", $"[yellow]{lorem}[/]", $"[blue]{lorem}[/]");
return loremTable;
}
private static IRenderable GetTreeTable()
{
var tree = new Tree("📁 src");
tree.AddNode("📁 foo").AddNode("📄 bar.cs");
tree.AddNode("📁 baz").AddNode("📁 qux").AddNode("📄 corgi.txt");
tree.AddNode("📄 waldo.xml");
var table = new Table().SimpleBorder().BorderColor(Color.Grey);
table.AddColumn(new TableColumn("Overview"));
table.AddColumn(new TableColumn("").Footer("[grey]3 Files, 225 KiB[/]"));
table.AddRow(new Markup("[yellow]Files[/]"), tree);
return new Table().RoundedBorder().Collapse().BorderColor(Color.Yellow)
.AddColumn("Foo").AddColumn("Bar")
.AddRow(new Text("Baz"), table)
.AddRow("Qux", "Corgi");
}
private static IRenderable GetBarChart()
{
return new BarChart()
.AddItem("Apple", 32, Color.Green)
.AddItem("Oranges", 13, Color.Orange1)
.AddItem("Bananas", 22, Color.Yellow);
}
private static IRenderable GetBreakdownChart()
{
return new BreakdownChart()
.ShowPercentage()
.FullSize()
.AddItem("C#", 82, Color.Green)
.AddItem("PowerShell", 13, Color.Red)
.AddItem("Bash", 5, Color.Blue);
}
}
}

View File

@@ -0,0 +1,15 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net5.0</TargetFramework>
<ExampleTitle>Showcase</ExampleTitle>
<ExampleDescription>Demonstation of Spectre.Console.</ExampleDescription>
<ExampleGroup>Misc</ExampleGroup>
</PropertyGroup>
<ItemGroup>
<ProjectReference Include="..\..\Shared\Shared.csproj" />
</ItemGroup>
</Project>

View File

@@ -1,7 +1,6 @@
using System.Threading;
using Spectre.Console;
namespace ProgressExample
namespace Spectre.Console.Examples
{
public static class Program
{

View File

@@ -13,7 +13,7 @@
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\..\..\src\Spectre.Console\Spectre.Console.csproj" />
<ProjectReference Include="..\..\Shared\Shared.csproj" />
</ItemGroup>
</Project>

View File

@@ -1,6 +1,4 @@
using Spectre.Console;
namespace TableExample
namespace Spectre.Console.Examples
{
public static class Program
{

View File

@@ -9,7 +9,7 @@
</PropertyGroup>
<ItemGroup>
<ProjectReference Include="..\..\..\src\Spectre.Console\Spectre.Console.csproj" />
<ProjectReference Include="..\..\Shared\Shared.csproj" />
</ItemGroup>
</Project>

View File

@@ -1,6 +1,4 @@
using Spectre.Console;
namespace TableExample
namespace Spectre.Console.Examples
{
public static class Program
{

View File

@@ -9,7 +9,7 @@
</PropertyGroup>
<ItemGroup>
<ProjectReference Include="..\..\..\src\Spectre.Console\Spectre.Console.csproj" />
<ProjectReference Include="..\..\Shared\Shared.csproj" />
</ItemGroup>
</Project>

124
examples/Shared/ColorBox.cs Normal file
View File

@@ -0,0 +1,124 @@
using System;
using System.Collections.Generic;
using Spectre.Console.Rendering;
namespace Spectre.Console.Examples
{
public sealed class ColorBox : Renderable
{
private readonly int _height;
private int? _width;
public ColorBox(int height)
{
_height = height;
}
public ColorBox(int width, int height)
: this(height)
{
_width = width;
}
protected override Measurement Measure(RenderContext context, int maxWidth)
{
return new Measurement(1, GetWidth(maxWidth));
}
protected override IEnumerable<Segment> Render(RenderContext context, int maxWidth)
{
maxWidth = GetWidth(maxWidth);
for (var y = 0; y < _height; y++)
{
for (var x = 0; x < maxWidth; x++)
{
var h = x / (float)maxWidth;
var l = 0.1f + ((y / (float)_height) * 0.7f);
var (r1, g1, b1) = ColorFromHSL(h, l, 1.0f);
var (r2, g2, b2) = ColorFromHSL(h, l + (0.7f / 10), 1.0f);
var background = new Color((byte)(r1 * 255), (byte)(g1 * 255), (byte)(b1 * 255));
var foreground = new Color((byte)(r2 * 255), (byte)(g2 * 255), (byte)(b2 * 255));
yield return new Segment("▄", new Style(foreground, background));
}
yield return Segment.LineBreak;
}
}
private int GetWidth(int maxWidth)
{
var width = maxWidth;
if (_width != null)
{
width = Math.Min(_width.Value, width);
}
return width;
}
private static (float, float, float) ColorFromHSL(double h, double l, double s)
{
double r = 0, g = 0, b = 0;
if (l != 0)
{
if (s == 0)
{
r = g = b = l;
}
else
{
double temp2;
if (l < 0.5)
{
temp2 = l * (1.0 + s);
}
else
{
temp2 = l + s - (l * s);
}
var temp1 = 2.0 * l - temp2;
r = GetColorComponent(temp1, temp2, h + 1.0 / 3.0);
g = GetColorComponent(temp1, temp2, h);
b = GetColorComponent(temp1, temp2, h - 1.0 / 3.0);
}
}
return ((float)r, (float)g, (float)b);
}
private static double GetColorComponent(double temp1, double temp2, double temp3)
{
if (temp3 < 0.0)
{
temp3 += 1.0;
}
else if (temp3 > 1.0)
{
temp3 -= 1.0;
}
if (temp3 < 1.0 / 6.0)
{
return temp1 + (temp2 - temp1) * 6.0 * temp3;
}
else if (temp3 < 0.5)
{
return temp2;
}
else if (temp3 < 2.0 / 3.0)
{
return temp1 + ((temp2 - temp1) * ((2.0 / 3.0) - temp3) * 6.0);
}
else
{
return temp1;
}
}
}
}

View File

@@ -0,0 +1,15 @@
namespace Spectre.Console.Examples
{
public static class ColorExtensions
{
public static Color GetInvertedColor(this Color color)
{
return GetLuminance(color) < 140 ? Color.White : Color.Black;
}
private static float GetLuminance(this Color color)
{
return (float)((0.2126 * color.R) + (0.7152 * color.G) + (0.0722 * color.B));
}
}
}

View File

@@ -0,0 +1,12 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>net5.0</TargetFramework>
<ExampleVisible>false</ExampleVisible>
</PropertyGroup>
<ItemGroup>
<ProjectReference Include="..\..\src\Spectre.Console\Spectre.Console.csproj" />
</ItemGroup>
</Project>

View File

@@ -1,7 +1,7 @@
{
"projects": [ "src" ],
"sdk": {
"version": "5.0.100",
"version": "5.0.202",
"rollForward": "latestPatch"
}
}

View File

@@ -15,16 +15,15 @@
<PropertyGroup Label="Package Information">
<Description>A library that makes it easier to create beautiful console applications.</Description>
<Company>Spectre Systems AB</Company>
<Copyright>Spectre Systems AB</Copyright>
<Authors>Patrik Svensson</Authors>
<Copyright>Patrik Svensson, Phil Scott</Copyright>
<Authors>Patrik Svensson, Phil Scott</Authors>
<RepositoryType>git</RepositoryType>
<RepositoryUrl>https://github.com/spectresystems/spectre.console</RepositoryUrl>
<RepositoryUrl>https://github.com/spectreconsole/spectre.console</RepositoryUrl>
<PackageIcon>small-logo.png</PackageIcon>
<PackageRequireLicenseAcceptance>True</PackageRequireLicenseAcceptance>
<PackageProjectUrl>https://github.com/spectresystems/spectre.console</PackageProjectUrl>
<PackageProjectUrl>https://github.com/spectreconsole/spectre.console</PackageProjectUrl>
<PackageLicenseExpression>MIT</PackageLicenseExpression>
<PackageReleaseNotes>https://github.com/spectresystems/spectre.console/releases</PackageReleaseNotes>
<PackageReleaseNotes>https://github.com/spectreconsole/spectre.console/releases</PackageReleaseNotes>
</PropertyGroup>
<PropertyGroup Label="Source Link">
@@ -35,7 +34,7 @@
<ItemGroup Label="Package References">
<PackageReference Include="MinVer" PrivateAssets="All" Version="2.4.0" />
<PackageReference Include="Microsoft.SourceLink.GitHub" PrivateAssets="All" Version="1.0.0" />
<PackageReference Include="Microsoft.CodeAnalysis.NetAnalyzers" Version="5.0.1">
<PackageReference Include="Microsoft.CodeAnalysis.NetAnalyzers" Version="5.0.3">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>

View File

@@ -1,5 +1,4 @@
using System;
using System.Collections.Generic;
using System.IO;
using Spectre.Console.Rendering;
@@ -9,29 +8,32 @@ namespace Spectre.Console.Testing
{
private readonly StringWriter _writer;
private readonly IAnsiConsole _console;
private readonly FakeExclusivityMode _exclusivityLock;
public string Output => _writer.ToString();
public Profile Profile => _console.Profile;
public IAnsiConsoleCursor Cursor => _console.Cursor;
public FakeConsoleInput Input { get; }
public IExclusivityMode ExclusivityMode => _exclusivityLock;
public RenderPipeline Pipeline => _console.Pipeline;
IAnsiConsoleInput IAnsiConsole.Input => Input;
public FakeAnsiConsole(
ColorSystem system,
ColorSystem colors,
AnsiSupport ansi = AnsiSupport.Yes,
int width = 80)
{
_exclusivityLock = new FakeExclusivityMode();
_writer = new StringWriter();
var factory = new AnsiConsoleFactory();
_console = factory.Create(new AnsiConsoleSettings
{
Ansi = ansi,
ColorSystem = (ColorSystemSupport)system,
Out = _writer,
ColorSystem = (ColorSystemSupport)colors,
Out = new AnsiConsoleOutput(_writer),
Enrichment = new ProfileEnrichment
{
UseDefaultEnrichers = false,
@@ -39,6 +41,7 @@ namespace Spectre.Console.Testing
});
_console.Profile.Width = width;
_console.Profile.Capabilities.Unicode = true;
Input = new FakeConsoleInput();
}
@@ -53,17 +56,9 @@ namespace Spectre.Console.Testing
_console.Clear(home);
}
public void Write(IEnumerable<Segment> segments)
public void Write(IRenderable renderable)
{
if (segments is null)
{
return;
}
foreach (var segment in segments)
{
_console.Write(segment);
}
_console.Write(renderable);
}
}
}

View File

@@ -0,0 +1,19 @@
namespace Spectre.Console.Testing
{
public sealed class FakeCapabilities : IReadOnlyCapabilities
{
public ColorSystem ColorSystem { get; set; } = ColorSystem.TrueColor;
public bool Ansi { get; set; }
public bool Links { get; set; }
public bool Legacy { get; set; }
public bool IsTerminal { get; set; }
public bool Interactive { get; set; }
public bool Unicode { get; set; }
}
}

View File

@@ -12,10 +12,11 @@ namespace Spectre.Console.Testing
public Profile Profile { get; }
public IAnsiConsoleCursor Cursor => new FakeAnsiConsoleCursor();
IAnsiConsoleInput IAnsiConsole.Input => Input;
public IExclusivityMode ExclusivityMode { get; }
public RenderPipeline Pipeline { get; }
public FakeConsoleInput Input { get; }
public string Output => Profile.Out.ToString();
public string Output => Profile.Out.Writer.ToString();
public IReadOnlyList<string> Lines => Output.TrimEnd('\n').Split(new char[] { '\n' });
public FakeConsole(
@@ -24,37 +25,34 @@ namespace Spectre.Console.Testing
bool legacyConsole = false, bool interactive = true)
{
Input = new FakeConsoleInput();
ExclusivityMode = new FakeExclusivityMode();
Pipeline = new RenderPipeline();
Profile = new Profile(new StringWriter(), encoding ?? Encoding.UTF8);
Profile = new Profile(new AnsiConsoleOutput(new StringWriter()), encoding ?? Encoding.UTF8);
Profile.Width = width;
Profile.Height = height;
Profile.ColorSystem = colorSystem;
Profile.Capabilities.ColorSystem = colorSystem;
Profile.Capabilities.Ansi = supportsAnsi;
Profile.Capabilities.Legacy = legacyConsole;
Profile.Capabilities.Interactive = interactive;
Profile.Capabilities.Links = true;
Profile.Capabilities.Unicode = true;
}
public void Dispose()
{
Profile.Out.Dispose();
Profile.Out.Writer.Dispose();
}
public void Clear(bool home)
{
}
public void Write(IEnumerable<Segment> segments)
public void Write(IRenderable renderable)
{
if (segments is null)
foreach (var segment in renderable.GetSegments(this))
{
return;
}
foreach (var segment in segments)
{
Profile.Out.Write(segment.Text);
Profile.Out.Writer.Write(segment.Text);
}
}

Some files were not shown because too many files have changed in this diff Show More