mirror of
https://github.com/spectreconsole/spectre.console.git
synced 2025-10-25 15:19:23 +00:00
Compare commits
31 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
d70ad661fc | ||
|
|
0d209d8f18 | ||
|
|
380c6aca45 | ||
|
|
b1da5e7ba8 | ||
|
|
be3350a411 | ||
|
|
a1d11e9d0c | ||
|
|
93d1971f48 | ||
|
|
bca1c889d1 | ||
|
|
9915a0d6a8 | ||
|
|
f34fc43d00 | ||
|
|
e7f497050c | ||
|
|
3e5e22d6c2 | ||
|
|
10daf727e9 | ||
|
|
03334f693d | ||
|
|
c9c0ad733f | ||
|
|
041bd016a2 | ||
|
|
037a215a78 | ||
|
|
9afc1ea721 | ||
|
|
b52056ee49 | ||
|
|
3941fd81ab | ||
|
|
5a1b8a1710 | ||
|
|
1410cba6c5 | ||
|
|
70fc14e9cd | ||
|
|
0b4359a52a | ||
|
|
cb2924a609 | ||
|
|
5c119ee0c3 | ||
|
|
b9d182b6e3 | ||
|
|
bfffef630f | ||
|
|
a2f507e58f | ||
|
|
d1d06d6a6b | ||
|
|
52718c499c |
11
.github/workflows/ci.yaml
vendored
11
.github/workflows/ci.yaml
vendored
@@ -21,7 +21,7 @@ jobs:
|
|||||||
- name: Setup dotnet
|
- name: Setup dotnet
|
||||||
uses: actions/setup-dotnet@v1
|
uses: actions/setup-dotnet@v1
|
||||||
with:
|
with:
|
||||||
dotnet-version: '3.1.301' # SDK Version to use.
|
dotnet-version: 5.0.100
|
||||||
|
|
||||||
- name: Build
|
- name: Build
|
||||||
shell: bash
|
shell: bash
|
||||||
@@ -55,10 +55,15 @@ jobs:
|
|||||||
with:
|
with:
|
||||||
fetch-depth: 0
|
fetch-depth: 0
|
||||||
|
|
||||||
- name: Setup dotnet
|
- name: Setup dotnet 3.1.402
|
||||||
uses: actions/setup-dotnet@v1
|
uses: actions/setup-dotnet@v1
|
||||||
with:
|
with:
|
||||||
dotnet-version: 3.1.301
|
dotnet-version: 3.1.402
|
||||||
|
|
||||||
|
- name: Setup dotnet 5.0.100
|
||||||
|
uses: actions/setup-dotnet@v1
|
||||||
|
with:
|
||||||
|
dotnet-version: 5.0.100
|
||||||
|
|
||||||
- name: Integration Tests
|
- name: Integration Tests
|
||||||
shell: bash
|
shell: bash
|
||||||
|
|||||||
2
.github/workflows/docs.yaml
vendored
2
.github/workflows/docs.yaml
vendored
@@ -24,7 +24,7 @@ jobs:
|
|||||||
- name: Setup dotnet
|
- name: Setup dotnet
|
||||||
uses: actions/setup-dotnet@v1
|
uses: actions/setup-dotnet@v1
|
||||||
with:
|
with:
|
||||||
dotnet-version: '3.1.301' # SDK Version to use.
|
dotnet-version: 5.0.100
|
||||||
|
|
||||||
- name: Publish
|
- name: Publish
|
||||||
shell: bash
|
shell: bash
|
||||||
|
|||||||
20
.github/workflows/publish.yaml
vendored
20
.github/workflows/publish.yaml
vendored
@@ -29,7 +29,7 @@ jobs:
|
|||||||
- name: Setup dotnet
|
- name: Setup dotnet
|
||||||
uses: actions/setup-dotnet@v1
|
uses: actions/setup-dotnet@v1
|
||||||
with:
|
with:
|
||||||
dotnet-version: '3.1.301' # SDK Version to use.
|
dotnet-version: 5.0.100
|
||||||
|
|
||||||
- name: Build
|
- name: Build
|
||||||
shell: bash
|
shell: bash
|
||||||
@@ -64,10 +64,15 @@ jobs:
|
|||||||
with:
|
with:
|
||||||
fetch-depth: 0
|
fetch-depth: 0
|
||||||
|
|
||||||
- name: Setup dotnet
|
- name: Setup dotnet 3.1.402
|
||||||
uses: actions/setup-dotnet@v1
|
uses: actions/setup-dotnet@v1
|
||||||
with:
|
with:
|
||||||
dotnet-version: 3.1.301
|
dotnet-version: 3.1.402
|
||||||
|
|
||||||
|
- name: Setup dotnet 5.0.100
|
||||||
|
uses: actions/setup-dotnet@v1
|
||||||
|
with:
|
||||||
|
dotnet-version: 5.0.100
|
||||||
|
|
||||||
- name: Build
|
- name: Build
|
||||||
shell: bash
|
shell: bash
|
||||||
@@ -90,10 +95,15 @@ jobs:
|
|||||||
with:
|
with:
|
||||||
fetch-depth: 0
|
fetch-depth: 0
|
||||||
|
|
||||||
- name: Setup dotnet
|
- name: Setup dotnet 3.1.402
|
||||||
uses: actions/setup-dotnet@v1
|
uses: actions/setup-dotnet@v1
|
||||||
with:
|
with:
|
||||||
dotnet-version: 3.1.301
|
dotnet-version: 3.1.402
|
||||||
|
|
||||||
|
- name: Setup dotnet 5.0.100
|
||||||
|
uses: actions/setup-dotnet@v1
|
||||||
|
with:
|
||||||
|
dotnet-version: 5.0.100
|
||||||
|
|
||||||
- name: Publish
|
- name: Publish
|
||||||
shell: bash
|
shell: bash
|
||||||
|
|||||||
413
README.jp.md
Normal file
413
README.jp.md
Normal file
@@ -0,0 +1,413 @@
|
|||||||
|
# `Spectre.Console`
|
||||||
|
|
||||||
|
_[](https://www.nuget.org/packages/spectre.console)_
|
||||||
|
|
||||||
|
綺麗なコンソールアプリケーションを簡単に作成するための.NET Standard 2.0ライブラリです。
|
||||||
|
Python用の素晴らしい[Rich ライブラリ](https://github.com/willmcgugan/rich)に強く影響を受けています。
|
||||||
|
|
||||||
|
## 目次
|
||||||
|
|
||||||
|
1. [特徴](#特徴)
|
||||||
|
2. [例](#例)
|
||||||
|
3. [使用方法](#使用方法)
|
||||||
|
3.1. [Static APIの利用](#static-apiの利用)
|
||||||
|
3.2. [コンソールの作成](#コンソールの作成)
|
||||||
|
4. [例の実行](#例の実行)
|
||||||
|
5. [クイックスタート](#クイックスタート)
|
||||||
|
6. [マークアップ](#マークアップ)
|
||||||
|
7. [絵文字](#絵文字)
|
||||||
|
8. [テーブル](#テーブル)
|
||||||
|
9. [例外](#例外)
|
||||||
|
|
||||||
|
## 特徴
|
||||||
|
|
||||||
|
* ユニットテストを意識して書いています。
|
||||||
|
* table、grid、panel、マークアップ言語に影響を受けた [rich](https://github.com/willmcgugan/rich) に対応しています。
|
||||||
|
* 太字、薄字、斜字、下線、斜線、点滅などの一般的なSGR parameters に対応しています。
|
||||||
|
* ターミナルで 3/4/8/24ビットカラーに対応しています。
|
||||||
|
ライブラリは現在のターミナルの性能を検知し、必要なカラーにダウングレードします
|
||||||
|
|
||||||
|
## 例
|
||||||
|
|
||||||
|

|
||||||
|
|
||||||
|
## 使用方法
|
||||||
|
|
||||||
|
`Spectre.Console` APIはステートフルで、スレッドセーフではありません。
|
||||||
|
異なるスレッドからコンソールに書く必要がある場合、通常の`System.Console` APIを使用するときと同様、適切な注意を払ってください。
|
||||||
|
|
||||||
|
現在の端末がANSIエスケープシーケンスに対応していない場合、
|
||||||
|
`Spectre.Console`は、`System.Console` APIの利用に切り替わります。
|
||||||
|
|
||||||
|
_メモ: このライブラリは現在開発中で、APIは1.0のリリースまでの間に変更されたり、
|
||||||
|
削除されたりする可能性があります。_
|
||||||
|
|
||||||
|
### Static APIの利用
|
||||||
|
|
||||||
|
|
||||||
|
`System.Console` APIでするように、テキストを出力したいだけの時にはstatic APIが最適ですが、綺麗です。
|
||||||
|
|
||||||
|
```csharp
|
||||||
|
AnsiConsole.Foreground = Color.CornflowerBlue;
|
||||||
|
AnsiConsole.Decoration = Decoration.Underline | Decoration.Bold;
|
||||||
|
AnsiConsole.WriteLine("Hello World!");
|
||||||
|
|
||||||
|
AnsiConsole.Reset();
|
||||||
|
AnsiConsole.MarkupLine("[bold yellow on red]{0}[/] [underline]world[/]!", "Goodbye");
|
||||||
|
```
|
||||||
|
|
||||||
|
もし、デフォルトの`IAnsiConsole`への参照を取得したい場合、
|
||||||
|
`AnsiConsole.Console`経由でアクセスできます。
|
||||||
|
|
||||||
|
### コンソールの作成
|
||||||
|
|
||||||
|
単体テスト中にコードの実行環境を制御したい場合など、
|
||||||
|
特定の機能をもつコンソールを明示的に作成すると便利なことがあります。
|
||||||
|
|
||||||
|
単体テストの一部としてコードで `AnsiConsole`を使わないことを推奨します。
|
||||||
|
|
||||||
|
```csharp
|
||||||
|
IAnsiConsole console = AnsiConsole.Create(
|
||||||
|
new AnsiConsoleSettings()
|
||||||
|
{
|
||||||
|
Ansi = AnsiSupport.Yes,
|
||||||
|
ColorSystem = ColorSystemSupport.TrueColor,
|
||||||
|
Out = new StringWriter(),
|
||||||
|
});
|
||||||
|
```
|
||||||
|
|
||||||
|
_メモ: 主導でコンソールを作成しているときに特定のカラーシステムを指定できたとしても、
|
||||||
|
ユーザーのターミナルでは使えないかもしれないことを覚えておいてください。
|
||||||
|
テスト用にIAnsiConsoleを作成していない限り、
|
||||||
|
常に`ColorSystemSupport.Detect` と `AnsiSupport.Detect`を使用してください。_
|
||||||
|
|
||||||
|
## 例の実行
|
||||||
|
|
||||||
|
Spectre.Consoleでできることを見るために、
|
||||||
|
[dotnet-example](https://github.com/patriksvensson/dotnet-example)グローバルツールをインストールします。
|
||||||
|
|
||||||
|
|
||||||
|
```
|
||||||
|
> dotnet tool restore
|
||||||
|
```
|
||||||
|
|
||||||
|
このリポジトリで提供している例が一覧表示されます
|
||||||
|
|
||||||
|
```
|
||||||
|
> dotnet example
|
||||||
|
|
||||||
|
╭────────────┬───────────────────────────────────────┬──────────────────────────────────────────────────────╮
|
||||||
|
│ Name │ Path │ Description │
|
||||||
|
├────────────┼───────────────────────────────────────┼──────────────────────────────────────────────────────┤
|
||||||
|
│ Borders │ examples/Borders/Borders.csproj │ Demonstrates the different kind of borders. │
|
||||||
|
│ Calendars │ examples/Calendars/Calendars.csproj │ Demonstrates how to render calendars. │
|
||||||
|
│ Colors │ examples/Colors/Colors.csproj │ Demonstrates how to use colors in the console. │
|
||||||
|
│ Columns │ examples/Columns/Columns.csproj │ Demonstrates how to render data into columns. │
|
||||||
|
│ Emojis │ examples/Emojis/Emojis.csproj │ Demonstrates how to render emojis. │
|
||||||
|
│ Exceptions │ examples/Exceptions/Exceptions.csproj │ Demonstrates how to render formatted exceptions. │
|
||||||
|
│ Grids │ examples/Grids/Grids.csproj │ Demonstrates how to render grids in a console. │
|
||||||
|
│ Info │ examples/Info/Info.csproj │ Displays the capabilities of the current console. │
|
||||||
|
│ Links │ examples/Links/Links.csproj │ Demonstrates how to render links in a console. │
|
||||||
|
│ Panels │ examples/Panels/Panels.csproj │ Demonstrates how to render items in panels. │
|
||||||
|
│ Rules │ examples/Rules/Rules.csproj │ Demonstrates how to render horizontal rules (lines). │
|
||||||
|
│ Tables │ examples/Tables/Tables.csproj │ Demonstrates how to render tables in a console. │
|
||||||
|
╰────────────┴───────────────────────────────────────┴──────────────────────────────────────────────────────╯
|
||||||
|
```
|
||||||
|
|
||||||
|
そして、例を実行します
|
||||||
|
|
||||||
|
```
|
||||||
|
> dotnet example tables
|
||||||
|
┌──────────┬──────────┬────────┐
|
||||||
|
│ Foo │ Bar │ Baz │
|
||||||
|
├──────────┼──────────┼────────┤
|
||||||
|
│ Hello │ World! │ │
|
||||||
|
│ Bonjour │ le │ monde! │
|
||||||
|
│ Hej │ Världen! │ │
|
||||||
|
└──────────┴──────────┴────────┘
|
||||||
|
```
|
||||||
|
|
||||||
|
## クイックスタート
|
||||||
|
pectre.Consoleの利用を開始する最初の方法は、Nugetパッケージをインストールすることです。
|
||||||
|
|
||||||
|
```shell
|
||||||
|
> dotnet add package Spectre.Console
|
||||||
|
```
|
||||||
|
|
||||||
|
その後、`Spectre.Console`名前空間を参照する必要があります。一度参照したら、提供されている全ての機能を使用できます。
|
||||||
|
|
||||||
|
```csharp
|
||||||
|
using Spectre.Console
|
||||||
|
|
||||||
|
public static class Program
|
||||||
|
{
|
||||||
|
public static void Main(string[] args)
|
||||||
|
{
|
||||||
|
AnsiConsole.Markup("[underline red]Hello[/] World!");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
## マークアップ
|
||||||
|
`Markup`クラスは、コンソールにリッチなテキストを出力することができます。
|
||||||
|
|
||||||
|
### 文法
|
||||||
|
|
||||||
|
コンソールマークアップはbbcodeに影響を受けた文法を利用します。角括弧でスタイルを書いたら(スタイルを参照)、例えば、`[bold red]`
|
||||||
|
は、`[/]`で閉じるまでスタイルが適用されます。
|
||||||
|
|
||||||
|
```csharp
|
||||||
|
AnsiConsole.Render(new Markup("[bold yellow]Hello[/] [red]World![/]"));
|
||||||
|
```
|
||||||
|
|
||||||
|
`Markup` クラスは`IRenderable`を実装しており、table、grid、Panelを使用できることを意味します。
|
||||||
|
`IRenderable`のレンダリングに対応している多くのクラスは、リッチテキストの描画を上書きます。
|
||||||
|
|
||||||
|
```csharp
|
||||||
|
var table = new Table();
|
||||||
|
table.AddColumn(new TableColumn(new Markup("[yellow]Foo[/]")));
|
||||||
|
table.AddColumn(new TableColumn("[blue]Bar[/]"));
|
||||||
|
```
|
||||||
|
|
||||||
|
### 便利なメソッド
|
||||||
|
|
||||||
|
`AnsiConsole`には、新しい`Markup`インスタンスをインスタンス化することなく、コンソールにマークアップテキストを書き込める便利なメソッドがあります。
|
||||||
|
|
||||||
|
```csharp
|
||||||
|
AnsiConsole.Markup("[underline green]Hello[/] ");
|
||||||
|
AnsiConsole.MarkupLine("[bold]World[/]");
|
||||||
|
```
|
||||||
|
|
||||||
|
### エスケープ文字列
|
||||||
|
|
||||||
|
`[`を出力するために、 `[[`を利用し、`]`を出力するために`]]`を利用します。
|
||||||
|
|
||||||
|
```csharp
|
||||||
|
AnsiConsole.Markup("[[Hello]] "); // [Hello]
|
||||||
|
AnsiConsole.Markup("[red][[World]][/]"); // [World]
|
||||||
|
```
|
||||||
|
|
||||||
|
`SafeMarkup`拡張メソッドを使用することもできます。
|
||||||
|
|
||||||
|
```csharp
|
||||||
|
AnsiConsole.Markup("[red]{0}[/]", "Hello [World]".SafeMarkup());
|
||||||
|
```
|
||||||
|
|
||||||
|
### カラー
|
||||||
|
|
||||||
|
`new Style(foreground: Color.Maroon)`のようなコード、または、`AnsiConsole.Markup("[maroon on blue]Hello[/]")`のようなマークアップテキストで色を使用できます。
|
||||||
|
|
||||||
|
### 背景色の設定
|
||||||
|
|
||||||
|
カラー指定の際に、`on`を付けることで、マークアップで背景色を設定できます。
|
||||||
|
|
||||||
|
```
|
||||||
|
[bold yellow on blue]Hello[/]
|
||||||
|
[default on blue]World[/]
|
||||||
|
```
|
||||||
|
|
||||||
|
### 絵文字の描画
|
||||||
|
|
||||||
|
マークアップの一部として絵文字を出力するために、emojiショートコードが使用できます。
|
||||||
|
|
||||||
|
```csharp
|
||||||
|
AnsiConsole.MarkupLine("Hello :globe_showing_europe_africa:!");
|
||||||
|
```
|
||||||
|
|
||||||
|
emojiのスタイルについては、付録の[Emoji](./appendix/emojis) を参照してください。
|
||||||
|
|
||||||
|
### カラー
|
||||||
|
|
||||||
|
上の例では、全ての色は名前で参照されています。
|
||||||
|
しかし、16進数やRGB表現をマークダウンで色指定に使用できます。
|
||||||
|
|
||||||
|
```csharp
|
||||||
|
AnsiConsole.Markup("[red]Foo[/] ");
|
||||||
|
AnsiConsole.Markup("[#ff0000]Bar[/] ");
|
||||||
|
AnsiConsole.Markup("[rgb(255,0,0)]Baz[/] ");
|
||||||
|
```
|
||||||
|
|
||||||
|
## 絵文字
|
||||||
|
|
||||||
|
どのような絵文字が使用できるかは、使用しているOSやターミナルに依存し、どのように表示されるかは保証されません。絵文字の幅計算は正確ではないため、表、パネル、グリッドで使用する場合は表示がずれるかもしれません。
|
||||||
|
|
||||||
|
完全な互換性を確保するために、Unicode 13.0 より以前の`Emoji_Presentation`カテゴリにあるものだけを使用することを検討してください。
|
||||||
|
公式の絵文字一覧
|
||||||
|
https://www.unicode.org/Public/UCD/latest/ucd/emoji/emoji-data.txt
|
||||||
|
|
||||||
|
|
||||||
|
```csharp
|
||||||
|
// Markup
|
||||||
|
AnsiConsole.MarkupLine("Hello :globe_showing_europe_africa:!");
|
||||||
|
|
||||||
|
// Constant
|
||||||
|
var hello = "Hello " + Emoji.Known.GlobeShowingEuropeAfrica;
|
||||||
|
```
|
||||||
|
|
||||||
|
テキスト内の絵文字を置き換えることができます。
|
||||||
|
|
||||||
|
```csharp
|
||||||
|
var phrase = "Mmmm :birthday_cake:";
|
||||||
|
var rendered
|
||||||
|
```
|
||||||
|
|
||||||
|
既存の絵文字を別のものにしたり、完全に新しい物を追加したいことがあります。このために、`Emoji.Remap`メソッドを使用できます。
|
||||||
|
この方法は、マークアップ文字と`Emoji.Replace`の両方で動作します。
|
||||||
|
|
||||||
|
```csharp
|
||||||
|
// Remap the emoji
|
||||||
|
Emoji.Remap("globe_showing_europe_africa", "😄");
|
||||||
|
|
||||||
|
// Render markup
|
||||||
|
AnsiConsole.MarkupLine("Hello :globe_showing_europe_africa:!");
|
||||||
|
|
||||||
|
// Replace emojis in string
|
||||||
|
var phrase = "Hello :globe_showing_europe_africa:!";
|
||||||
|
var rendered = Emoji.Replace(phrase);
|
||||||
|
```
|
||||||
|
|
||||||
|
## テーブル
|
||||||
|
|
||||||
|
テーブルはターミナルで表データを表示するのに完璧な方法です。
|
||||||
|
`Spectre.Console` は、テーブルの描画にとても優れていて、全てのカラムは中に合わせて調整してくれます。
|
||||||
|
`IRenderable`を実装しているものは、列ヘッダやセル、別のテーブルとして使用できます。
|
||||||
|
|
||||||
|
### 使い方
|
||||||
|
|
||||||
|
テーブルを描画するために、`Table`インスタンスを作成し、必要な数の列を追加し、行を追加します。
|
||||||
|
テーブルをコンソールの`Render`メソッドに渡して終わりです。
|
||||||
|
|
||||||
|
```csharp
|
||||||
|
// テーブルの作成
|
||||||
|
var table = new Table();
|
||||||
|
|
||||||
|
// 列の追加
|
||||||
|
table.AddColumn("Foo");
|
||||||
|
table.AddColumn(new TableColumn("Bar").Centered());
|
||||||
|
|
||||||
|
// 行の追加
|
||||||
|
table.AddRow("Baz", "[green]Qux[/]");
|
||||||
|
table.AddRow(new Markup("[blue]Corgi[/]"), new Panel("Waldo"));
|
||||||
|
|
||||||
|
// コンソールにテーブルの描画
|
||||||
|
AnsiConsole.Render(table);
|
||||||
|
```
|
||||||
|
|
||||||
|
これは次のように出力を描画します。
|
||||||
|
|
||||||
|

|
||||||
|
|
||||||
|
### 罫線
|
||||||
|
|
||||||
|
|
||||||
|
```csharp
|
||||||
|
// 罫線を設定します
|
||||||
|
table.SetBorder(Border.None);
|
||||||
|
table.SetBorder(Border.Ascii);
|
||||||
|
table.SetBorder(Border.Square);
|
||||||
|
table.SetBorder(Border.Rounded);
|
||||||
|
```
|
||||||
|
|
||||||
|
### 拡大 / 縮小
|
||||||
|
|
||||||
|
```csharp
|
||||||
|
// テーブル幅を最大に設定します
|
||||||
|
table.Expand();
|
||||||
|
|
||||||
|
// テーブル幅を最小に設定します
|
||||||
|
table.Collapse();
|
||||||
|
```
|
||||||
|
|
||||||
|
### ヘッダーを隠す
|
||||||
|
|
||||||
|
```csharp
|
||||||
|
// 全ての列のヘッダーを隠します
|
||||||
|
table.HideHeaders();
|
||||||
|
```
|
||||||
|
|
||||||
|
### テーブル幅の設定
|
||||||
|
|
||||||
|
```csharp
|
||||||
|
// テーブル幅50セルに設定します
|
||||||
|
table.SetWidth(50);
|
||||||
|
```
|
||||||
|
|
||||||
|
### 整列(アライメント)
|
||||||
|
|
||||||
|
```csharp
|
||||||
|
// 整列を明示的に設定する
|
||||||
|
column.SetAlignment(Justify.Right);
|
||||||
|
```
|
||||||
|
|
||||||
|
### パディング
|
||||||
|
|
||||||
|
```csharp
|
||||||
|
// 左と右のパディングを設定する
|
||||||
|
column.SetPadding(left: 3, right: 5);
|
||||||
|
|
||||||
|
// 個別にパディングを設定する
|
||||||
|
column.PadLeft(3);
|
||||||
|
column.PadRight(5);
|
||||||
|
```
|
||||||
|
|
||||||
|
### 列改行の無効化
|
||||||
|
|
||||||
|
```csharp
|
||||||
|
// 列改行の無効化
|
||||||
|
column.NoWrap();
|
||||||
|
```
|
||||||
|
|
||||||
|
### 列幅の設定
|
||||||
|
|
||||||
|
```csharp
|
||||||
|
// 列幅の設定(これはまだ柔軟な拡張メソッドがありません)
|
||||||
|
column.Width = 15;
|
||||||
|
```
|
||||||
|
|
||||||
|
## 例外
|
||||||
|
例外はターミナルで見たときに読みやすいとは限りません。
|
||||||
|
`WriteException`メソッドを使用することで、例外をもう少し読みやすくすることができます。
|
||||||
|
|
||||||
|
```csharp
|
||||||
|
AnsiConsole.WriteException(ex);
|
||||||
|
```
|
||||||
|
|
||||||
|

|
||||||
|
### 例外の省略表示
|
||||||
|
|
||||||
|
例外の特定部分を短くして、さらに読みやすくしたり、パスをクリック可能なハイパーリンクにすることもできます。
|
||||||
|
ハイパーリンクがクリックできるかはターミナル次第です。
|
||||||
|
|
||||||
|
|
||||||
|
```csharp
|
||||||
|
AnsiConsole.WriteException(ex,
|
||||||
|
ExceptionFormats.ShortenPaths | ExceptionFormats.ShortenTypes |
|
||||||
|
ExceptionFormats.ShortenMethods | ExceptionFormats.ShowLinks);
|
||||||
|
```
|
||||||
|
|
||||||
|

|
||||||
|
|
||||||
|
### 例外出力のカスタマイズ
|
||||||
|
|
||||||
|
例外の特定部分を短縮するだけでなく、デフォルトのスタイルを上書きすることもできます。
|
||||||
|
|
||||||
|
```csharp
|
||||||
|
AnsiConsole.WriteException(ex, new ExceptionSettings
|
||||||
|
{
|
||||||
|
Format = ExceptionFormats.ShortenEverything | ExceptionFormats.ShowLinks,
|
||||||
|
Style = new ExceptionStyle
|
||||||
|
{
|
||||||
|
Exception = Style.WithForeground(Color.Grey),
|
||||||
|
Message = Style.WithForeground(Color.White),
|
||||||
|
NonEmphasized = Style.WithForeground(Color.Cornsilk1),
|
||||||
|
Parenthesis = Style.WithForeground(Color.Cornsilk1),
|
||||||
|
Method = Style.WithForeground(Color.Red),
|
||||||
|
ParameterName = Style.WithForeground(Color.Cornsilk1),
|
||||||
|
ParameterType = Style.WithForeground(Color.Red),
|
||||||
|
Path = Style.WithForeground(Color.Red),
|
||||||
|
LineNumber = Style.WithForeground(Color.Cornsilk1),
|
||||||
|
}
|
||||||
|
});
|
||||||
|
```
|
||||||
|
|
||||||
|

|
||||||
47
README.md
47
README.md
@@ -10,10 +10,11 @@ for Python.
|
|||||||
|
|
||||||
1. [Features](#features)
|
1. [Features](#features)
|
||||||
2. [Example](#example)
|
2. [Example](#example)
|
||||||
3. [Usage](#usage)
|
3. [Installing](#installing)
|
||||||
3.1. [Using the static API](#using-the-static-api)
|
4. [Usage](#usage)
|
||||||
3.2. [Creating a console](#creating-a-console)
|
4.1. [Using the static API](#using-the-static-api)
|
||||||
4. [Running examples](#running-examples)
|
4.2. [Creating a console](#creating-a-console)
|
||||||
|
5. [Running examples](#running-examples)
|
||||||
|
|
||||||
## Features
|
## Features
|
||||||
|
|
||||||
@@ -30,6 +31,14 @@ for Python.
|
|||||||
|
|
||||||

|

|
||||||
|
|
||||||
|
## Installing
|
||||||
|
|
||||||
|
The fastest way of getting started using Spectre.Console is to install the NuGet package.
|
||||||
|
|
||||||
|
```csharp
|
||||||
|
dotnet add package Spectre.Console
|
||||||
|
```
|
||||||
|
|
||||||
## Usage
|
## Usage
|
||||||
|
|
||||||
The `Spectre.Console` API is stateful and is not thread-safe.
|
The `Spectre.Console` API is stateful and is not thread-safe.
|
||||||
@@ -40,7 +49,7 @@ regular `System.Console` API.
|
|||||||
If the current terminal does not support ANSI escape sequences,
|
If the current terminal does not support ANSI escape sequences,
|
||||||
`Spectre.Console` will fallback to using the `System.Console` API.
|
`Spectre.Console` will fallback to using the `System.Console` API.
|
||||||
|
|
||||||
_NOTE: This library is currently under development and API's
|
_NOTE: This library is currently under development and APIs
|
||||||
might change or get removed at any point up until a 1.0 release._
|
might change or get removed at any point up until a 1.0 release._
|
||||||
|
|
||||||
### Using the static API
|
### Using the static API
|
||||||
@@ -91,7 +100,7 @@ To see Spectre.Console in action, install the
|
|||||||
global tool.
|
global tool.
|
||||||
|
|
||||||
```
|
```
|
||||||
> dotnet tool install -g dotnet-example
|
> dotnet tool restore
|
||||||
```
|
```
|
||||||
|
|
||||||
Now you can list available examples in this repository:
|
Now you can list available examples in this repository:
|
||||||
@@ -99,20 +108,28 @@ Now you can list available examples in this repository:
|
|||||||
```
|
```
|
||||||
> dotnet example
|
> dotnet example
|
||||||
|
|
||||||
╭────────┬───────────────────────────────┬─────────────────────────────────────────────────╮
|
╭────────────┬───────────────────────────────────────┬──────────────────────────────────────────────────────╮
|
||||||
│ Name │ Path │ Description │
|
│ Name │ Path │ Description │
|
||||||
├────────┼───────────────────────────────┼─────────────────────────────────────────────────┤
|
├────────────┼───────────────────────────────────────┼──────────────────────────────────────────────────────┤
|
||||||
│ Colors │ examples/Colors/Colors.csproj │ Demonstrates how to use colors in the console. │
|
│ Borders │ examples/Borders/Borders.csproj │ Demonstrates the different kind of borders. │
|
||||||
│ Grid │ examples/Grid/Grid.csproj │ Demonstrates how to render grids in a console. │
|
│ Calendars │ examples/Calendars/Calendars.csproj │ Demonstrates how to render calendars. │
|
||||||
│ Panel │ examples/Panel/Panel.csproj │ Demonstrates how to render items in panels. │
|
│ Colors │ examples/Colors/Colors.csproj │ Demonstrates how to use colors in the console. │
|
||||||
│ Table │ examples/Table/Table.csproj │ Demonstrates how to render tables in a console. │
|
│ Columns │ examples/Columns/Columns.csproj │ Demonstrates how to render data into columns. │
|
||||||
╰────────┴───────────────────────────────┴─────────────────────────────────────────────────╯
|
│ Emojis │ examples/Emojis/Emojis.csproj │ Demonstrates how to render emojis. │
|
||||||
|
│ Exceptions │ examples/Exceptions/Exceptions.csproj │ Demonstrates how to render formatted exceptions. │
|
||||||
|
│ Grids │ examples/Grids/Grids.csproj │ Demonstrates how to render grids in a console. │
|
||||||
|
│ Info │ examples/Info/Info.csproj │ Displays the capabilities of the current console. │
|
||||||
|
│ Links │ examples/Links/Links.csproj │ Demonstrates how to render links in a console. │
|
||||||
|
│ Panels │ examples/Panels/Panels.csproj │ Demonstrates how to render items in panels. │
|
||||||
|
│ Rules │ examples/Rules/Rules.csproj │ Demonstrates how to render horizontal rules (lines). │
|
||||||
|
│ Tables │ examples/Tables/Tables.csproj │ Demonstrates how to render tables in a console. │
|
||||||
|
╰────────────┴───────────────────────────────────────┴──────────────────────────────────────────────────────╯
|
||||||
```
|
```
|
||||||
|
|
||||||
And to run an example:
|
And to run an example:
|
||||||
|
|
||||||
```
|
```
|
||||||
> dotnet example table
|
> dotnet example tables
|
||||||
┌──────────┬──────────┬────────┐
|
┌──────────┬──────────┬────────┐
|
||||||
│ Foo │ Bar │ Baz │
|
│ Foo │ Bar │ Baz │
|
||||||
├──────────┼──────────┼────────┤
|
├──────────┼──────────┼────────┤
|
||||||
|
|||||||
@@ -2,7 +2,7 @@
|
|||||||
|
|
||||||
<PropertyGroup>
|
<PropertyGroup>
|
||||||
<OutputType>Exe</OutputType>
|
<OutputType>Exe</OutputType>
|
||||||
<TargetFramework>netcoreapp3.1</TargetFramework>
|
<TargetFramework>net5.0</TargetFramework>
|
||||||
<RunWorkingDirectory>$(MSBuildProjectDirectory)</RunWorkingDirectory>
|
<RunWorkingDirectory>$(MSBuildProjectDirectory)</RunWorkingDirectory>
|
||||||
<DefaultItemExcludes>$(DefaultItemExcludes);output\**;.gitignore</DefaultItemExcludes>
|
<DefaultItemExcludes>$(DefaultItemExcludes);output\**;.gitignore</DefaultItemExcludes>
|
||||||
<MinVerSkip Condition="'$(Configuration)' == 'Debug'">true</MinVerSkip>
|
<MinVerSkip Condition="'$(Configuration)' == 'Debug'">true</MinVerSkip>
|
||||||
@@ -31,8 +31,8 @@
|
|||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<PackageReference Include="Statiq.Web" Version="1.0.0-beta.5" />
|
<PackageReference Include="Statiq.Web" Version="1.0.0-beta.13" />
|
||||||
<PackageReference Include="MinVer" PrivateAssets="All" Version="2.3.0" />
|
<PackageReference Include="MinVer" PrivateAssets="All" Version="2.3.1" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
|
|||||||
@@ -10,7 +10,7 @@ The documentation site uses [Statiq](https://statiq.dev), a static site generato
|
|||||||
> dotnet run preview --virtual-dir "spectre.console"
|
> dotnet run preview --virtual-dir "spectre.console"
|
||||||
```
|
```
|
||||||
|
|
||||||
After the build is complete, you can navigate to [http://localhost:5080/spectre.consle](http://localhost:5080/spectre.console).
|
After the build is complete, you can navigate to [http://localhost:5080/spectre.console](http://localhost:5080/spectre.console).
|
||||||
|
|
||||||
**Note that the site runs under a virtual directory.**
|
**Note that the site runs under a virtual directory.**
|
||||||
|
|
||||||
|
|||||||
@@ -130,7 +130,7 @@
|
|||||||
<div class="sidebar-nav-item @(Document.IdEquals(root) ? "active" : null)">
|
<div class="sidebar-nav-item @(Document.IdEquals(root) ? "active" : null)">
|
||||||
@if(root.ShowLink())
|
@if(root.ShowLink())
|
||||||
{
|
{
|
||||||
@Html.DocumentLink(root)
|
@Html.DocumentLink(root)
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
@@ -140,6 +140,11 @@
|
|||||||
|
|
||||||
@foreach (IDocument document in OutputPages.GetChildrenOf(root).OnlyVisible())
|
@foreach (IDocument document in OutputPages.GetChildrenOf(root).OnlyVisible())
|
||||||
{
|
{
|
||||||
|
if(string.IsNullOrWhiteSpace(document.GetTitle()))
|
||||||
|
{
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
DocumentList<IDocument> documentChildren = OutputPages.GetChildrenOf(document);
|
DocumentList<IDocument> documentChildren = OutputPages.GetChildrenOf(document);
|
||||||
<div class="sidebar-nav-item @(Document.IdEquals(document) ? "active" : null) @(documentChildren.Any() ? "has-children" : null)">
|
<div class="sidebar-nav-item @(Document.IdEquals(document) ? "active" : null) @(documentChildren.Any() ? "has-children" : null)">
|
||||||
@if(document.ShowLink())
|
@if(document.ShowLink())
|
||||||
|
|||||||
BIN
docs/input/assets/images/rule.png
Normal file
BIN
docs/input/assets/images/rule.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 24 KiB |
BIN
docs/input/assets/images/table.gif
Normal file
BIN
docs/input/assets/images/table.gif
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 1.4 MiB |
@@ -19,8 +19,8 @@ the hyperlinks are clickable is up to the terminal.
|
|||||||
|
|
||||||
```csharp
|
```csharp
|
||||||
AnsiConsole.WriteException(ex,
|
AnsiConsole.WriteException(ex,
|
||||||
ExceptionFormat.ShortenPaths | ExceptionFormat.ShortenTypes |
|
ExceptionFormats.ShortenPaths | ExceptionFormats.ShortenTypes |
|
||||||
ExceptionFormat.ShortenMethods | ExceptionFormat.ShowLinks);
|
ExceptionFormats.ShortenMethods | ExceptionFormats.ShowLinks);
|
||||||
```
|
```
|
||||||
|
|
||||||
<img src="assets/images/compact_exception.png" style="max-width: 100%;">
|
<img src="assets/images/compact_exception.png" style="max-width: 100%;">
|
||||||
@@ -36,15 +36,15 @@ AnsiConsole.WriteException(ex, new ExceptionSettings
|
|||||||
Format = ExceptionFormats.ShortenEverything | ExceptionFormats.ShowLinks,
|
Format = ExceptionFormats.ShortenEverything | ExceptionFormats.ShowLinks,
|
||||||
Style = new ExceptionStyle
|
Style = new ExceptionStyle
|
||||||
{
|
{
|
||||||
Exception = Style.WithForeground(Color.Grey),
|
Exception = new Style().Foreground(Color.Grey),
|
||||||
Message = Style.WithForeground(Color.White),
|
Message = new Style().Foreground(Color.White),
|
||||||
NonEmphasized = Style.WithForeground(Color.Cornsilk1),
|
NonEmphasized = new Style().Foreground(Color.Cornsilk1),
|
||||||
Parenthesis = Style.WithForeground(Color.Cornsilk1),
|
Parenthesis = new Style().Foreground(Color.Cornsilk1),
|
||||||
Method = Style.WithForeground(Color.Red),
|
Method = new Style().Foreground(Color.Red),
|
||||||
ParameterName = Style.WithForeground(Color.Cornsilk1),
|
ParameterName = new Style().Foreground(Color.Cornsilk1),
|
||||||
ParameterType = Style.WithForeground(Color.Red),
|
ParameterType = new Style().Foreground(Color.Red),
|
||||||
Path = Style.WithForeground(Color.Red),
|
Path = new Style().Foreground(Color.Red),
|
||||||
LineNumber = Style.WithForeground(Color.Cornsilk1),
|
LineNumber = new Style().Foreground(Color.Cornsilk1),
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
```
|
```
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
Title: Welcome
|
Title: Welcome
|
||||||
Order: 0
|
Order: 0
|
||||||
---
|
---
|
||||||
|
|
||||||
@@ -20,7 +20,7 @@ for Python written by Will McGugan.
|
|||||||
The library will detect the capabilities of the current terminal
|
The library will detect the capabilities of the current terminal
|
||||||
and downgrade colors as needed.
|
and downgrade colors as needed.
|
||||||
|
|
||||||
## Example
|
## Examples
|
||||||
|
|
||||||
<img width="100%"
|
<img src="assets/images/table.gif" style="max-width: 100%; margin-top: 15px; margin-bottom: 25px;" />
|
||||||
src="https://github.com/spectresystems/spectre.console/raw/main/resources/gfx/screenshots/example.png" />
|
<img src="https://github.com/spectresystems/spectre.console/raw/main/resources/gfx/screenshots/example.png" style="max-width: 100%;" />
|
||||||
@@ -6,7 +6,7 @@ The class `Markup` allows you to output rich text to the console.
|
|||||||
|
|
||||||
# Syntax
|
# Syntax
|
||||||
|
|
||||||
Console markup uses a syntax inspired by bbcode. If you write the style (see Styles)
|
Console markup uses a syntax inspired by bbcode. If you write the style (see [Styles](xref:styles))
|
||||||
in square brackets, e.g. `[bold red]`, that style will apply until it is closed with a `[/]`.
|
in square brackets, e.g. `[bold red]`, that style will apply until it is closed with a `[/]`.
|
||||||
|
|
||||||
```csharp
|
```csharp
|
||||||
@@ -21,6 +21,7 @@ rendering of `IRenderable` also have overloads for rendering rich text.
|
|||||||
var table = new Table();
|
var table = new Table();
|
||||||
table.AddColumn(new TableColumn(new Markup("[yellow]Foo[/]")));
|
table.AddColumn(new TableColumn(new Markup("[yellow]Foo[/]")));
|
||||||
table.AddColumn(new TableColumn("[blue]Bar[/]"));
|
table.AddColumn(new TableColumn("[blue]Bar[/]"));
|
||||||
|
AnsiConsole.Render(table);
|
||||||
```
|
```
|
||||||
|
|
||||||
# Convenience methods
|
# Convenience methods
|
||||||
@@ -43,20 +44,24 @@ AnsiConsole.Markup("[[Hello]] "); // [Hello]
|
|||||||
AnsiConsole.Markup("[red][[World]][/]"); // [World]
|
AnsiConsole.Markup("[red][[World]][/]"); // [World]
|
||||||
```
|
```
|
||||||
|
|
||||||
You can also use the `SafeMarkup` extension method.
|
You can also use the `EscapeMarkup` extension method.
|
||||||
|
|
||||||
```csharp
|
```csharp
|
||||||
AnsiConsole.Markup("[red]{0}[/]", "Hello [World]".SafeMarkup());
|
AnsiConsole.Markup("[red]{0}[/]", "Hello [World]".EscapeMarkup());
|
||||||
```
|
```
|
||||||
|
You can also use the `Markup.Escape` method.
|
||||||
|
|
||||||
|
```csharp
|
||||||
|
AnsiConsole.Markup("[red]{0}[/]", Markup.Escape("Hello [World]"));
|
||||||
|
```
|
||||||
# Setting background color
|
# Setting background color
|
||||||
|
|
||||||
You can set the background color in markup by prefixing the color with
|
You can set the background color in markup by prefixing the color with
|
||||||
`on`.
|
`on`.
|
||||||
|
|
||||||
```
|
```csharp
|
||||||
[bold yellow on blue]Hello[/]
|
AnsiConsole.Markup("[bold yellow on blue]Hello[/]");
|
||||||
[default on blue]World[/]
|
AnsiConsole.Markup("[default on blue]World[/]");
|
||||||
```
|
```
|
||||||
|
|
||||||
# Rendering emojis
|
# Rendering emojis
|
||||||
@@ -64,7 +69,7 @@ You can set the background color in markup by prefixing the color with
|
|||||||
To output an emoji as part of markup, you can use emoji shortcodes.
|
To output an emoji as part of markup, you can use emoji shortcodes.
|
||||||
|
|
||||||
```csharp
|
```csharp
|
||||||
AnsiConsole.MarkupLine("Hello :globe_showing_europe_africa:!");
|
AnsiConsole.Markup("Hello :globe_showing_europe_africa:!");
|
||||||
```
|
```
|
||||||
|
|
||||||
For a list of emoji, see the [Emojis](xref:emojis) appendix section.
|
For a list of emoji, see the [Emojis](xref:emojis) appendix section.
|
||||||
|
|||||||
99
docs/input/prompt.md
Normal file
99
docs/input/prompt.md
Normal file
@@ -0,0 +1,99 @@
|
|||||||
|
Title: Prompt
|
||||||
|
Order: 4
|
||||||
|
---
|
||||||
|
|
||||||
|
Sometimes you want to get some input from the user, and for this
|
||||||
|
you can use the `Prompt<TResult>`.
|
||||||
|
|
||||||
|
# Confirmation
|
||||||
|
|
||||||
|
```csharp
|
||||||
|
if (!AnsiConsole.Confirm("Run example?"))
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
```text
|
||||||
|
Run example? [y/n] (y): _
|
||||||
|
```
|
||||||
|
|
||||||
|
# Simple
|
||||||
|
|
||||||
|
```csharp
|
||||||
|
// Ask for the user's name
|
||||||
|
string name = AnsiConsole.Ask<string>("What's your [green]name[/]?");
|
||||||
|
|
||||||
|
// Ask for the user's age
|
||||||
|
int age = AnsiConsole.Ask<int>("What's your [green]age[/]?");
|
||||||
|
```
|
||||||
|
|
||||||
|
```text
|
||||||
|
What's your name? Patrik
|
||||||
|
What's your age? 37
|
||||||
|
```
|
||||||
|
|
||||||
|
# Choices
|
||||||
|
|
||||||
|
```csharp
|
||||||
|
var fruit = AnsiConsole.Prompt(
|
||||||
|
new TextPrompt<string>("What's your [green]favorite fruit[/]?")
|
||||||
|
.InvalidChoiceMessage("[red]That's not a valid fruit[/]")
|
||||||
|
.DefaultValue("Orange")
|
||||||
|
.AddChoice("Apple")
|
||||||
|
.AddChoice("Banana")
|
||||||
|
.AddChoice("Orange"));
|
||||||
|
```
|
||||||
|
|
||||||
|
```text
|
||||||
|
What's your favorite fruit? [Apple/Banana/Orange] (Orange): _
|
||||||
|
```
|
||||||
|
|
||||||
|
# Validation
|
||||||
|
|
||||||
|
```csharp
|
||||||
|
var age = AnsiConsole.Prompt(
|
||||||
|
new TextPrompt<int>("What's the secret number?")
|
||||||
|
.Validate(age =>
|
||||||
|
{
|
||||||
|
return age switch
|
||||||
|
{
|
||||||
|
<= 99 => ValidationResult.Error("[red]Too low[/]"),
|
||||||
|
>= 99 => ValidationResult.Error("[red]Too high[/]"),
|
||||||
|
_ => ValidationResult.Success(),
|
||||||
|
};
|
||||||
|
}));
|
||||||
|
```
|
||||||
|
|
||||||
|
```text
|
||||||
|
What's the secret number? 32
|
||||||
|
Too low
|
||||||
|
What's the secret number? 102
|
||||||
|
Too high
|
||||||
|
What's the secret number? _
|
||||||
|
```
|
||||||
|
|
||||||
|
# Secrets
|
||||||
|
|
||||||
|
```csharp
|
||||||
|
var password = AnsiConsole.Prompt(
|
||||||
|
new TextPrompt<string>("Enter [green]password[/]")
|
||||||
|
.PromptStyle("red")
|
||||||
|
.Secret());
|
||||||
|
```
|
||||||
|
|
||||||
|
```text
|
||||||
|
Enter password: ************_
|
||||||
|
```
|
||||||
|
|
||||||
|
# Optional
|
||||||
|
|
||||||
|
```csharp
|
||||||
|
var color = AnsiConsole.Prompt(
|
||||||
|
new TextPrompt<string>("[grey][[Optional]][/] [green]Favorite color[/]?")
|
||||||
|
.AllowEmpty());
|
||||||
|
```
|
||||||
|
|
||||||
|
```text
|
||||||
|
[Optional] Favorite color? _
|
||||||
|
```
|
||||||
121
docs/input/widgets/calendar.md
Normal file
121
docs/input/widgets/calendar.md
Normal file
@@ -0,0 +1,121 @@
|
|||||||
|
Title: Calendar
|
||||||
|
Order: 4
|
||||||
|
RedirectFrom: calendar
|
||||||
|
---
|
||||||
|
|
||||||
|
The `Calendar` is used to render a calendar to the terminal.
|
||||||
|
|
||||||
|
# Usage
|
||||||
|
|
||||||
|
To render a calendar, create a `Calendar` instance with a target date.
|
||||||
|
|
||||||
|
```csharp
|
||||||
|
var calendar = new Calendar(2020,10);
|
||||||
|
AnsiConsole.Render(calendar);
|
||||||
|
```
|
||||||
|
|
||||||
|
```text
|
||||||
|
2020 October
|
||||||
|
┌─────┬─────┬─────┬─────┬─────┬─────┬─────┐
|
||||||
|
│ Sun │ Mon │ Tue │ Wed │ Thu │ Fri │ Sat │
|
||||||
|
├─────┼─────┼─────┼─────┼─────┼─────┼─────┤
|
||||||
|
│ │ │ │ │ 1 │ 2 │ 3 │
|
||||||
|
│ 4 │ 5 │ 6 │ 7 │ 8 │ 9 │ 10 │
|
||||||
|
│ 11 │ 12 │ 13 │ 14 │ 15 │ 16 │ 17 │
|
||||||
|
│ 18 │ 19 │ 20 │ 21 │ 22 │ 23 │ 24 │
|
||||||
|
│ 25 │ 26 │ 27 │ 28 │ 29 │ 30 │ 31 │
|
||||||
|
│ │ │ │ │ │ │ │
|
||||||
|
└─────┴─────┴─────┴─────┴─────┴─────┴─────┘
|
||||||
|
```
|
||||||
|
|
||||||
|
## Culture
|
||||||
|
|
||||||
|
You can set the calendar's culture to show localized weekdays.
|
||||||
|
|
||||||
|
```csharp
|
||||||
|
var calendar = new Calendar(2020,10);
|
||||||
|
calendar.Culture("ja-JP");
|
||||||
|
AnsiConsole.Render(calendar);
|
||||||
|
```
|
||||||
|
|
||||||
|
```text
|
||||||
|
Oktober 2020
|
||||||
|
┌─────┬─────┬─────┬─────┬─────┬─────┬─────┐
|
||||||
|
│ Mån │ Tis │ Ons │ Tor │ Fre │ Lör │ Sön │
|
||||||
|
├─────┼─────┼─────┼─────┼─────┼─────┼─────┤
|
||||||
|
│ │ │ │ 1 │ 2 │ 3 │ 4 │
|
||||||
|
│ 5 │ 6 │ 7 │ 8 │ 9 │ 10 │ 11* │
|
||||||
|
│ 12 │ 13 │ 14 │ 15 │ 16 │ 17 │ 18 │
|
||||||
|
│ 19 │ 20 │ 21 │ 22 │ 23 │ 24 │ 25 │
|
||||||
|
│ 26 │ 27 │ 28 │ 29 │ 30 │ 31 │ │
|
||||||
|
│ │ │ │ │ │ │ │
|
||||||
|
└─────┴─────┴─────┴─────┴─────┴─────┴─────┘
|
||||||
|
```
|
||||||
|
|
||||||
|
## Header
|
||||||
|
|
||||||
|
You can hide the calendar header.
|
||||||
|
|
||||||
|
```csharp
|
||||||
|
var calendar = new Calendar(2020,10);
|
||||||
|
calendar.ShowHeader();
|
||||||
|
AnsiConsole.Render(calendar);
|
||||||
|
```
|
||||||
|
|
||||||
|
```text
|
||||||
|
┌─────┬─────┬─────┬─────┬─────┬─────┬─────┐
|
||||||
|
│ Sun │ Mon │ Tue │ Wed │ Thu │ Fri │ Sat │
|
||||||
|
├─────┼─────┼─────┼─────┼─────┼─────┼─────┤
|
||||||
|
│ │ │ │ │ 1 │ 2 │ 3 │
|
||||||
|
│ 4 │ 5 │ 6 │ 7 │ 8 │ 9 │ 10 │
|
||||||
|
│ 11 │ 12 │ 13 │ 14 │ 15 │ 16 │ 17 │
|
||||||
|
│ 18 │ 19 │ 20 │ 21 │ 22 │ 23 │ 24 │
|
||||||
|
│ 25 │ 26 │ 27 │ 28 │ 29 │ 30 │ 31 │
|
||||||
|
│ │ │ │ │ │ │ │
|
||||||
|
└─────┴─────┴─────┴─────┴─────┴─────┴─────┘
|
||||||
|
```
|
||||||
|
|
||||||
|
You can set the header style of the calendar.
|
||||||
|
|
||||||
|
```csharp
|
||||||
|
var calendar = new Calendar(2020, 10);
|
||||||
|
calendar.HeaderStyle(Style.Parse("blue bold"));
|
||||||
|
AnsiConsole.Render(calendar);
|
||||||
|
```
|
||||||
|
|
||||||
|
|
||||||
|
## Calendar Events
|
||||||
|
|
||||||
|
You can add an event to the calendar.
|
||||||
|
If a date has an event associated with it, the date gets highlighted in the calendar.
|
||||||
|
|
||||||
|
```csharp
|
||||||
|
var calendar = new Calendar(2020,10);
|
||||||
|
calendar.AddCalendarEvent(2020, 10, 11);
|
||||||
|
AnsiConsole.Render(calendar);
|
||||||
|
```
|
||||||
|
|
||||||
|
```text
|
||||||
|
2020 October
|
||||||
|
┌─────┬─────┬─────┬─────┬─────┬─────┬─────┐
|
||||||
|
│ Sun │ Mon │ Tue │ Wed │ Thu │ Fri │ Sat │
|
||||||
|
├─────┼─────┼─────┼─────┼─────┼─────┼─────┤
|
||||||
|
│ │ │ │ │ 1 │ 2 │ 3 │
|
||||||
|
│ 4 │ 5 │ 6 │ 7 │ 8 │ 9 │ 10 │
|
||||||
|
│ 11* │ 12 │ 13 │ 14 │ 15 │ 16 │ 17 │
|
||||||
|
│ 18 │ 19 │ 20 │ 21 │ 22 │ 23 │ 24 │
|
||||||
|
│ 25 │ 26 │ 27 │ 28 │ 29 │ 30 │ 31 │
|
||||||
|
│ │ │ │ │ │ │ │
|
||||||
|
└─────┴─────┴─────┴─────┴─────┴─────┴─────┘
|
||||||
|
```
|
||||||
|
|
||||||
|
### Highlight style
|
||||||
|
|
||||||
|
You can set the highlight style for a calendar event via `SetHighlightStyle`.
|
||||||
|
|
||||||
|
```csharp
|
||||||
|
var calendar = new Calendar(2020, 10);
|
||||||
|
calendar.AddCalendarEvent(2020, 10, 11);
|
||||||
|
calendar.HighlightStyle(Style.Parse("yellow bold"));
|
||||||
|
AnsiConsole.Render(calendar);
|
||||||
|
```
|
||||||
3
docs/input/widgets/index.md
Normal file
3
docs/input/widgets/index.md
Normal file
@@ -0,0 +1,3 @@
|
|||||||
|
Title: Widgets
|
||||||
|
Order: 9
|
||||||
|
---
|
||||||
72
docs/input/widgets/rule.md
Normal file
72
docs/input/widgets/rule.md
Normal file
@@ -0,0 +1,72 @@
|
|||||||
|
Title: Rule
|
||||||
|
Order: 5
|
||||||
|
RedirectFrom: rule
|
||||||
|
---
|
||||||
|
|
||||||
|
The `Rule` class is used to render a horizontal rule (line) to the terminal.
|
||||||
|
|
||||||
|
<img src="../assets/images/rule.png" style="width: 100%;" />
|
||||||
|
|
||||||
|
# Usage
|
||||||
|
|
||||||
|
To render a rule without a title:
|
||||||
|
|
||||||
|
```csharp
|
||||||
|
var rule = new Rule();
|
||||||
|
AnsiConsole.Render(rule);
|
||||||
|
```
|
||||||
|
|
||||||
|
## Title
|
||||||
|
|
||||||
|
You can set the rule title markup text.
|
||||||
|
|
||||||
|
```csharp
|
||||||
|
var rule = new Rule("[red]Hello[/]");
|
||||||
|
AnsiConsole.Render(rule);
|
||||||
|
```
|
||||||
|
|
||||||
|
```text
|
||||||
|
───────────────────────────────── Hello ─────────────────────────────────
|
||||||
|
```
|
||||||
|
|
||||||
|
### Title alignment
|
||||||
|
|
||||||
|
You can set the rule's title alignment.
|
||||||
|
|
||||||
|
```csharp
|
||||||
|
var rule = new Rule("[red]Hello[/]");
|
||||||
|
rule.Alignment = Justify.Left;
|
||||||
|
AnsiConsole.Render(rule);
|
||||||
|
```
|
||||||
|
|
||||||
|
```text
|
||||||
|
── Hello ────────────────────────────────────────────────────────────────
|
||||||
|
```
|
||||||
|
|
||||||
|
You can also specify it via an extension method:
|
||||||
|
|
||||||
|
```csharp
|
||||||
|
var rule = new Rule("[red]Hello[/]");
|
||||||
|
rule.LeftAligned();
|
||||||
|
AnsiConsole.Render(rule);
|
||||||
|
```
|
||||||
|
|
||||||
|
```text
|
||||||
|
── Hello ────────────────────────────────────────────────────────────────
|
||||||
|
```
|
||||||
|
|
||||||
|
|
||||||
|
## Styling
|
||||||
|
|
||||||
|
```csharp
|
||||||
|
var rule = new Rule("[red]Hello[/]");
|
||||||
|
rule.Style = Style.Parse("red dim");
|
||||||
|
AnsiConsole.Render(rule);
|
||||||
|
```
|
||||||
|
You can also specify it via an extension method
|
||||||
|
|
||||||
|
```csharp
|
||||||
|
var rule = new Rule("[red]Hello[/]");
|
||||||
|
rule.RuleStyle("red dim");
|
||||||
|
AnsiConsole.Render(rule);
|
||||||
|
```
|
||||||
@@ -1,5 +1,6 @@
|
|||||||
Title: Tables
|
Title: Table
|
||||||
Order: 3
|
Order: 3
|
||||||
|
RedirectFrom: tables
|
||||||
---
|
---
|
||||||
|
|
||||||
Tables are a perfect way of displaying tabular data in a terminal.
|
Tables are a perfect way of displaying tabular data in a terminal.
|
||||||
@@ -36,7 +37,7 @@ AnsiConsole.Render(table);
|
|||||||
|
|
||||||
This will render the following output:
|
This will render the following output:
|
||||||
|
|
||||||

|

|
||||||
|
|
||||||
# Table appearance
|
# Table appearance
|
||||||
|
|
||||||
@@ -50,10 +51,10 @@ For a list of borders, see the [Borders](xref:borders) appendix section.
|
|||||||
|
|
||||||
```csharp
|
```csharp
|
||||||
// Sets the border
|
// Sets the border
|
||||||
table.SetBorder(Border.None);
|
table.Border(TableBorder.None);
|
||||||
table.SetBorder(Border.Ascii);
|
table.Border(TableBorder.Ascii);
|
||||||
table.SetBorder(Border.Square);
|
table.Border(TableBorder.Square);
|
||||||
table.SetBorder(Border.Rounded);
|
table.Border(TableBorder.Rounded);
|
||||||
```
|
```
|
||||||
|
|
||||||
## Expand / Collapse
|
## Expand / Collapse
|
||||||
@@ -78,7 +79,16 @@ table.HideHeaders();
|
|||||||
|
|
||||||
```csharp
|
```csharp
|
||||||
// Sets the table width to 50 cells
|
// Sets the table width to 50 cells
|
||||||
table.SetWidth(50);
|
table.Width(50);
|
||||||
|
```
|
||||||
|
|
||||||
|
## Alignment
|
||||||
|
|
||||||
|
```csharp
|
||||||
|
table.Alignment(Justify.Right);
|
||||||
|
table.RightAligned();
|
||||||
|
table.Centered();
|
||||||
|
table.LeftAligned();
|
||||||
```
|
```
|
||||||
|
|
||||||
# Column appearance
|
# Column appearance
|
||||||
@@ -90,31 +100,37 @@ table.SetWidth(50);
|
|||||||
## Alignment
|
## Alignment
|
||||||
|
|
||||||
```csharp
|
```csharp
|
||||||
// Set the alignment explicitly
|
table.Columns[0].Alignment(Justify.Right);
|
||||||
column.SetAlignment(Justify.Right);
|
table.Columns[0].LeftAligned();
|
||||||
|
table.Columns[0].Centered();
|
||||||
|
table.Columns[0].RightAligned();
|
||||||
```
|
```
|
||||||
|
|
||||||
## Padding
|
## Padding
|
||||||
|
|
||||||
```csharp
|
```csharp
|
||||||
// Set left and right padding
|
// Set padding individually
|
||||||
column.SetPadding(left: 3, right: 5);
|
table.Columns[0].PadLeft(3);
|
||||||
|
table.Columns[0].PadRight(5);
|
||||||
|
|
||||||
// Set padding individually.
|
// Or chained together
|
||||||
column.PadLeft(3);
|
table.Columns[0].PadLeft(3).PadRight(5);
|
||||||
column.PadRight(5);
|
|
||||||
|
// Or with the shorthand method if the left and right
|
||||||
|
// padding are identical. Vertical padding is ignored.
|
||||||
|
table.Columns[0].Padding(4, 0);
|
||||||
```
|
```
|
||||||
|
|
||||||
## Disable column wrapping
|
## Disable column wrapping
|
||||||
|
|
||||||
```csharp
|
```csharp
|
||||||
// Disable column wrapping
|
// Disable column wrapping
|
||||||
column.NoWrap();
|
table.Columns[0].NoWrap();
|
||||||
```
|
```
|
||||||
|
|
||||||
## Set column width
|
## Set column width
|
||||||
|
|
||||||
```csharp
|
```csharp
|
||||||
// Set the column width (no fluent extension method for this yet)
|
// Set the column width
|
||||||
column.Width = 15;
|
table.Columns[0].Width(15);
|
||||||
```
|
```
|
||||||
@@ -3,7 +3,7 @@
|
|||||||
"isRoot": true,
|
"isRoot": true,
|
||||||
"tools": {
|
"tools": {
|
||||||
"cake.tool": {
|
"cake.tool": {
|
||||||
"version": "0.38.4",
|
"version": "1.0.0-rc0001",
|
||||||
"commands": [
|
"commands": [
|
||||||
"dotnet-cake"
|
"dotnet-cake"
|
||||||
]
|
]
|
||||||
@@ -15,7 +15,7 @@
|
|||||||
]
|
]
|
||||||
},
|
},
|
||||||
"dotnet-example": {
|
"dotnet-example": {
|
||||||
"version": "0.8.0",
|
"version": "1.1.0",
|
||||||
"commands": [
|
"commands": [
|
||||||
"dotnet-example"
|
"dotnet-example"
|
||||||
]
|
]
|
||||||
|
|||||||
@@ -1,8 +1,8 @@
|
|||||||
<Project Sdk="Microsoft.NET.Sdk">
|
<Project Sdk="Microsoft.NET.Sdk">
|
||||||
|
|
||||||
<PropertyGroup>
|
<PropertyGroup>
|
||||||
<OutputType>Exe</OutputType>
|
<OutputType>Exe</OutputType>
|
||||||
<TargetFramework>netcoreapp3.1</TargetFramework>
|
<TargetFramework>net5.0</TargetFramework>
|
||||||
<IsPackable>false</IsPackable>
|
<IsPackable>false</IsPackable>
|
||||||
<Title>Borders</Title>
|
<Title>Borders</Title>
|
||||||
<Description>Demonstrates the different kind of borders.</Description>
|
<Description>Demonstrates the different kind of borders.</Description>
|
||||||
|
|||||||
@@ -8,26 +8,22 @@ namespace BordersExample
|
|||||||
public static void Main()
|
public static void Main()
|
||||||
{
|
{
|
||||||
// Render panel borders
|
// Render panel borders
|
||||||
AnsiConsole.WriteLine();
|
HorizontalRule("PANEL BORDERS");
|
||||||
AnsiConsole.MarkupLine("[white bold underline]PANEL BORDERS[/]");
|
PanelBorders();
|
||||||
AnsiConsole.WriteLine();
|
|
||||||
RenderPanelBorders();
|
|
||||||
|
|
||||||
// Render table borders
|
// Render table borders
|
||||||
AnsiConsole.WriteLine();
|
HorizontalRule("TABLE BORDERS");
|
||||||
AnsiConsole.MarkupLine("[white bold underline]TABLE BORDERS[/]");
|
TableBorders();
|
||||||
AnsiConsole.WriteLine();
|
|
||||||
RenderTableBorders();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void RenderPanelBorders()
|
private static void PanelBorders()
|
||||||
{
|
{
|
||||||
static IRenderable CreatePanel(string name, BoxBorder border)
|
static IRenderable CreatePanel(string name, BoxBorder border)
|
||||||
{
|
{
|
||||||
return new Panel($"This is a panel with\nthe [yellow]{name}[/] border.")
|
return new Panel($"This is a panel with\nthe [yellow]{name}[/] border.")
|
||||||
.SetHeader($" {name} ", Style.Parse("blue"), Justify.Center)
|
.Header($" [blue]{name}[/] ", Justify.Center)
|
||||||
.SetBorderStyle(Style.Parse("grey"))
|
.Border(border)
|
||||||
.SetBorder(border);
|
.BorderStyle(Style.Parse("grey"));
|
||||||
}
|
}
|
||||||
|
|
||||||
var items = new[]
|
var items = new[]
|
||||||
@@ -46,19 +42,18 @@ namespace BordersExample
|
|||||||
new Padding(2,0,0,0)));
|
new Padding(2,0,0,0)));
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void RenderTableBorders()
|
private static void TableBorders()
|
||||||
{
|
{
|
||||||
static IRenderable CreateTable(string name, TableBorder border)
|
static IRenderable CreateTable(string name, TableBorder border)
|
||||||
{
|
{
|
||||||
var table = new Table().SetBorder(border);
|
var table = new Table().Border(border);
|
||||||
table.AddColumn("[yellow]Header 1[/]");
|
table.AddColumn("[yellow]Header 1[/]", c => c.Footer("[grey]Footer 1[/]"));
|
||||||
table.AddColumn("[yellow]Header 2[/]", col => col.RightAligned());
|
table.AddColumn("[yellow]Header 2[/]", col => col.Footer("[grey]Footer 2[/]").RightAligned());
|
||||||
table.AddRow("Cell", "Cell");
|
table.AddRow("Cell", "Cell");
|
||||||
table.AddRow("Cell", "Cell");
|
table.AddRow("Cell", "Cell");
|
||||||
|
|
||||||
return new Panel(table)
|
return new Panel(table)
|
||||||
.SetHeader($" {name} ", Style.Parse("blue"), Justify.Center)
|
.Header($" [blue]{name}[/] ", Justify.Center)
|
||||||
.SetBorderStyle(Style.Parse("grey"))
|
|
||||||
.NoBorder();
|
.NoBorder();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -85,5 +80,12 @@ namespace BordersExample
|
|||||||
|
|
||||||
AnsiConsole.Render(new Columns(items).Collapse());
|
AnsiConsole.Render(new Columns(items).Collapse());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private static void HorizontalRule(string title)
|
||||||
|
{
|
||||||
|
AnsiConsole.WriteLine();
|
||||||
|
AnsiConsole.Render(new Rule($"[white bold]{title}[/]").RuleStyle("grey").LeftAligned());
|
||||||
|
AnsiConsole.WriteLine();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -2,7 +2,7 @@
|
|||||||
|
|
||||||
<PropertyGroup>
|
<PropertyGroup>
|
||||||
<OutputType>Exe</OutputType>
|
<OutputType>Exe</OutputType>
|
||||||
<TargetFramework>netcoreapp3.1</TargetFramework>
|
<TargetFramework>net5.0</TargetFramework>
|
||||||
<IsPackable>false</IsPackable>
|
<IsPackable>false</IsPackable>
|
||||||
<Title>Calendars</Title>
|
<Title>Calendars</Title>
|
||||||
<Description>Demonstrates how to render calendars.</Description>
|
<Description>Demonstrates how to render calendars.</Description>
|
||||||
|
|||||||
@@ -1,6 +1,4 @@
|
|||||||
using System.Collections.Generic;
|
|
||||||
using Spectre.Console;
|
using Spectre.Console;
|
||||||
using Spectre.Console.Rendering;
|
|
||||||
|
|
||||||
namespace Calendars
|
namespace Calendars
|
||||||
{
|
{
|
||||||
@@ -9,60 +7,13 @@ namespace Calendars
|
|||||||
public static void Main(string[] args)
|
public static void Main(string[] args)
|
||||||
{
|
{
|
||||||
AnsiConsole.WriteLine();
|
AnsiConsole.WriteLine();
|
||||||
AnsiConsole.Render(
|
AnsiConsole.Render(new Calendar(2020, 10)
|
||||||
new Columns(GetCalendars())
|
|
||||||
.Collapse());
|
|
||||||
}
|
|
||||||
|
|
||||||
private static IEnumerable<IRenderable> GetCalendars()
|
|
||||||
{
|
|
||||||
yield return EmbedInPanel(
|
|
||||||
"Invariant calendar",
|
|
||||||
new Calendar(2020, 10)
|
|
||||||
.SimpleHeavyBorder()
|
|
||||||
.SetHighlightStyle(Style.Parse("red"))
|
|
||||||
.AddCalendarEvent("An event", 2020, 9, 22)
|
|
||||||
.AddCalendarEvent("Another event", 2020, 10, 2)
|
|
||||||
.AddCalendarEvent("A third event", 2020, 10, 13));
|
|
||||||
|
|
||||||
yield return EmbedInPanel(
|
|
||||||
"Swedish calendar (sv-SE)",
|
|
||||||
new Calendar(2020, 10)
|
|
||||||
.RoundedBorder()
|
.RoundedBorder()
|
||||||
.SetHighlightStyle(Style.Parse("blue"))
|
.HighlightStyle(Style.Parse("red"))
|
||||||
.SetCulture("sv-SE")
|
.HeaderStyle(Style.Parse("yellow"))
|
||||||
.AddCalendarEvent("An event", 2020, 9, 22)
|
.AddCalendarEvent("An event", 2020, 9, 22)
|
||||||
.AddCalendarEvent("Another event", 2020, 10, 2)
|
.AddCalendarEvent("Another event", 2020, 10, 2)
|
||||||
.AddCalendarEvent("A third event", 2020, 10, 13));
|
.AddCalendarEvent("A third event", 2020, 10, 13));
|
||||||
|
|
||||||
yield return EmbedInPanel(
|
|
||||||
"German calendar (de-DE)",
|
|
||||||
new Calendar(2020, 10)
|
|
||||||
.MarkdownBorder()
|
|
||||||
.SetHighlightStyle(Style.Parse("yellow"))
|
|
||||||
.SetCulture("de-DE")
|
|
||||||
.AddCalendarEvent("An event", 2020, 9, 22)
|
|
||||||
.AddCalendarEvent("Another event", 2020, 10, 2)
|
|
||||||
.AddCalendarEvent("A third event", 2020, 10, 13));
|
|
||||||
|
|
||||||
yield return EmbedInPanel(
|
|
||||||
"Italian calendar (de-DE)",
|
|
||||||
new Calendar(2020, 10)
|
|
||||||
.DoubleBorder()
|
|
||||||
.SetHighlightStyle(Style.Parse("green"))
|
|
||||||
.SetCulture("it-IT")
|
|
||||||
.AddCalendarEvent("An event", 2020, 9, 22)
|
|
||||||
.AddCalendarEvent("Another event", 2020, 10, 2)
|
|
||||||
.AddCalendarEvent("A third event", 2020, 10, 13));
|
|
||||||
}
|
|
||||||
|
|
||||||
private static IRenderable EmbedInPanel(string title, Calendar calendar)
|
|
||||||
{
|
|
||||||
return new Panel(calendar)
|
|
||||||
.Expand()
|
|
||||||
.RoundedBorder()
|
|
||||||
.SetBorderStyle(Style.Parse("grey"))
|
|
||||||
.SetHeader($" {title} ", Style.Parse("yellow"));
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -2,7 +2,7 @@
|
|||||||
|
|
||||||
<PropertyGroup>
|
<PropertyGroup>
|
||||||
<OutputType>Exe</OutputType>
|
<OutputType>Exe</OutputType>
|
||||||
<TargetFramework>netcoreapp3.1</TargetFramework>
|
<TargetFramework>net5.0</TargetFramework>
|
||||||
<IsPackable>false</IsPackable>
|
<IsPackable>false</IsPackable>
|
||||||
<Title>Colors</Title>
|
<Title>Colors</Title>
|
||||||
<Description>Demonstrates how to use [yellow]c[/][red]o[/][green]l[/][blue]o[/][aqua]r[/][lime]s[/] in the console.</Description>
|
<Description>Demonstrates how to use [yellow]c[/][red]o[/][green]l[/][blue]o[/][aqua]r[/][lime]s[/] in the console.</Description>
|
||||||
|
|||||||
@@ -24,7 +24,7 @@ namespace ColorExample
|
|||||||
|
|
||||||
AnsiConsole.ResetColors();
|
AnsiConsole.ResetColors();
|
||||||
AnsiConsole.WriteLine();
|
AnsiConsole.WriteLine();
|
||||||
AnsiConsole.MarkupLine("[bold underline]3-bit Colors[/]");
|
AnsiConsole.Render(new Rule("[yellow bold underline]3-bit Colors[/]").RuleStyle("grey").LeftAligned());
|
||||||
AnsiConsole.WriteLine();
|
AnsiConsole.WriteLine();
|
||||||
|
|
||||||
for (var i = 0; i < 8; i++)
|
for (var i = 0; i < 8; i++)
|
||||||
@@ -47,7 +47,7 @@ namespace ColorExample
|
|||||||
|
|
||||||
AnsiConsole.ResetColors();
|
AnsiConsole.ResetColors();
|
||||||
AnsiConsole.WriteLine();
|
AnsiConsole.WriteLine();
|
||||||
AnsiConsole.MarkupLine("[bold underline]4-bit Colors[/]");
|
AnsiConsole.Render(new Rule("[yellow bold underline]4-bit Colors[/]").RuleStyle("grey").LeftAligned());
|
||||||
AnsiConsole.WriteLine();
|
AnsiConsole.WriteLine();
|
||||||
|
|
||||||
for (var i = 0; i < 16; i++)
|
for (var i = 0; i < 16; i++)
|
||||||
@@ -70,7 +70,7 @@ namespace ColorExample
|
|||||||
|
|
||||||
AnsiConsole.ResetColors();
|
AnsiConsole.ResetColors();
|
||||||
AnsiConsole.WriteLine();
|
AnsiConsole.WriteLine();
|
||||||
AnsiConsole.MarkupLine("[bold underline]8-bit Colors[/]");
|
AnsiConsole.Render(new Rule("[yellow bold underline]8-bit Colors[/]").RuleStyle("grey").LeftAligned());
|
||||||
AnsiConsole.WriteLine();
|
AnsiConsole.WriteLine();
|
||||||
|
|
||||||
for (var i = 0; i < 16; i++)
|
for (var i = 0; i < 16; i++)
|
||||||
@@ -97,7 +97,7 @@ namespace ColorExample
|
|||||||
|
|
||||||
AnsiConsole.ResetColors();
|
AnsiConsole.ResetColors();
|
||||||
AnsiConsole.WriteLine();
|
AnsiConsole.WriteLine();
|
||||||
AnsiConsole.MarkupLine("[bold underline]24-bit Colors[/]");
|
AnsiConsole.Render(new Rule("[yellow bold underline]24-bit Colors[/]").RuleStyle("grey").LeftAligned());
|
||||||
AnsiConsole.WriteLine();
|
AnsiConsole.WriteLine();
|
||||||
|
|
||||||
var index = 0;
|
var index = 0;
|
||||||
|
|||||||
@@ -2,7 +2,7 @@
|
|||||||
|
|
||||||
<PropertyGroup>
|
<PropertyGroup>
|
||||||
<OutputType>Exe</OutputType>
|
<OutputType>Exe</OutputType>
|
||||||
<TargetFramework>netcoreapp3.1</TargetFramework>
|
<TargetFramework>net5.0</TargetFramework>
|
||||||
<IsPackable>false</IsPackable>
|
<IsPackable>false</IsPackable>
|
||||||
<Title>Columns</Title>
|
<Title>Columns</Title>
|
||||||
<Description>Demonstrates how to render data into columns.</Description>
|
<Description>Demonstrates how to render data into columns.</Description>
|
||||||
|
|||||||
@@ -19,8 +19,8 @@ namespace ColumnsExample
|
|||||||
var cards = new List<Panel>();
|
var cards = new List<Panel>();
|
||||||
foreach(var user in users.results)
|
foreach(var user in users.results)
|
||||||
{
|
{
|
||||||
cards.Add(new Panel(GetCard(user))
|
cards.Add(new Panel(GetCardContent(user))
|
||||||
.SetHeader($"{user.location.country}")
|
.Header($"{user.location.country}")
|
||||||
.RoundedBorder().Expand());
|
.RoundedBorder().Expand());
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -28,7 +28,7 @@ namespace ColumnsExample
|
|||||||
AnsiConsole.Render(new Columns(cards));
|
AnsiConsole.Render(new Columns(cards));
|
||||||
}
|
}
|
||||||
|
|
||||||
private static string GetCard(dynamic user)
|
private static string GetCardContent(dynamic user)
|
||||||
{
|
{
|
||||||
var name = $"{user.name.first} {user.name.last}";
|
var name = $"{user.name.first} {user.name.last}";
|
||||||
var country = $"{user.location.city}";
|
var country = $"{user.location.city}";
|
||||||
|
|||||||
15
examples/Cursor/Cursor.csproj
Normal file
15
examples/Cursor/Cursor.csproj
Normal file
@@ -0,0 +1,15 @@
|
|||||||
|
<Project Sdk="Microsoft.NET.Sdk">
|
||||||
|
|
||||||
|
<PropertyGroup>
|
||||||
|
<OutputType>Exe</OutputType>
|
||||||
|
<TargetFramework>net5.0</TargetFramework>
|
||||||
|
<IsPackable>false</IsPackable>
|
||||||
|
<Title>Cursor</Title>
|
||||||
|
<Description>Demonstrates how to move the cursor.</Description>
|
||||||
|
</PropertyGroup>
|
||||||
|
|
||||||
|
<ItemGroup>
|
||||||
|
<ProjectReference Include="..\..\src\Spectre.Console\Spectre.Console.csproj" />
|
||||||
|
</ItemGroup>
|
||||||
|
|
||||||
|
</Project>
|
||||||
20
examples/Cursor/Program.cs
Normal file
20
examples/Cursor/Program.cs
Normal file
@@ -0,0 +1,20 @@
|
|||||||
|
using Spectre.Console;
|
||||||
|
|
||||||
|
namespace Cursor
|
||||||
|
{
|
||||||
|
public static class Program
|
||||||
|
{
|
||||||
|
public static void Main(string[] args)
|
||||||
|
{
|
||||||
|
AnsiConsole.Write("Hello");
|
||||||
|
|
||||||
|
// Move the cursor 3 cells to the right
|
||||||
|
AnsiConsole.Cursor.Move(CursorDirection.Right, 3);
|
||||||
|
AnsiConsole.Write("World");
|
||||||
|
|
||||||
|
// Move the cursor 5 cells to the left.
|
||||||
|
AnsiConsole.Cursor.Move(CursorDirection.Left, 5);
|
||||||
|
AnsiConsole.WriteLine("Universe");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -2,7 +2,7 @@
|
|||||||
|
|
||||||
<PropertyGroup>
|
<PropertyGroup>
|
||||||
<OutputType>Exe</OutputType>
|
<OutputType>Exe</OutputType>
|
||||||
<TargetFramework>netcoreapp3.1</TargetFramework>
|
<TargetFramework>net5.0</TargetFramework>
|
||||||
<IsPackable>false</IsPackable>
|
<IsPackable>false</IsPackable>
|
||||||
<Title>Emojis</Title>
|
<Title>Emojis</Title>
|
||||||
<Description>Demonstrates how to render emojis.</Description>
|
<Description>Demonstrates how to render emojis.</Description>
|
||||||
|
|||||||
@@ -2,7 +2,7 @@
|
|||||||
|
|
||||||
<PropertyGroup>
|
<PropertyGroup>
|
||||||
<OutputType>Exe</OutputType>
|
<OutputType>Exe</OutputType>
|
||||||
<TargetFramework>netcoreapp3.1</TargetFramework>
|
<TargetFramework>net5.0</TargetFramework>
|
||||||
<IsPackable>false</IsPackable>
|
<IsPackable>false</IsPackable>
|
||||||
<Title>Exceptions</Title>
|
<Title>Exceptions</Title>
|
||||||
<Description>Demonstrates how to render formatted exceptions.</Description>
|
<Description>Demonstrates how to render formatted exceptions.</Description>
|
||||||
|
|||||||
@@ -15,32 +15,32 @@ namespace Exceptions
|
|||||||
catch (Exception ex)
|
catch (Exception ex)
|
||||||
{
|
{
|
||||||
AnsiConsole.WriteLine();
|
AnsiConsole.WriteLine();
|
||||||
AnsiConsole.Render(new Panel("[u]Default[/]").Expand());
|
AnsiConsole.Render(new Rule("Default").LeftAligned());
|
||||||
AnsiConsole.WriteLine();
|
AnsiConsole.WriteLine();
|
||||||
AnsiConsole.WriteException(ex);
|
AnsiConsole.WriteException(ex);
|
||||||
|
|
||||||
AnsiConsole.WriteLine();
|
AnsiConsole.WriteLine();
|
||||||
AnsiConsole.Render(new Panel("[u]Compact[/]").Expand());
|
AnsiConsole.Render(new Rule("Compact").LeftAligned());
|
||||||
AnsiConsole.WriteLine();
|
AnsiConsole.WriteLine();
|
||||||
AnsiConsole.WriteException(ex, ExceptionFormats.ShortenEverything | ExceptionFormats.ShowLinks);
|
AnsiConsole.WriteException(ex, ExceptionFormats.ShortenEverything | ExceptionFormats.ShowLinks);
|
||||||
|
|
||||||
AnsiConsole.WriteLine();
|
AnsiConsole.WriteLine();
|
||||||
AnsiConsole.Render(new Panel("[u]Custom colors[/]").Expand());
|
AnsiConsole.Render(new Rule("Compact + Custom colors").LeftAligned());
|
||||||
AnsiConsole.WriteLine();
|
AnsiConsole.WriteLine();
|
||||||
AnsiConsole.WriteException(ex, new ExceptionSettings
|
AnsiConsole.WriteException(ex, new ExceptionSettings
|
||||||
{
|
{
|
||||||
Format = ExceptionFormats.ShortenEverything | ExceptionFormats.ShowLinks,
|
Format = ExceptionFormats.ShortenEverything | ExceptionFormats.ShowLinks,
|
||||||
Style = new ExceptionStyle
|
Style = new ExceptionStyle
|
||||||
{
|
{
|
||||||
Exception = Style.WithForeground(Color.Grey),
|
Exception = new Style().Foreground(Color.Grey),
|
||||||
Message = Style.WithForeground(Color.White),
|
Message = new Style().Foreground(Color.White),
|
||||||
NonEmphasized = Style.WithForeground(Color.Cornsilk1),
|
NonEmphasized = new Style().Foreground(Color.Cornsilk1),
|
||||||
Parenthesis = Style.WithForeground(Color.Cornsilk1),
|
Parenthesis = new Style().Foreground(Color.Cornsilk1),
|
||||||
Method = Style.WithForeground(Color.Red),
|
Method = new Style().Foreground(Color.Red),
|
||||||
ParameterName = Style.WithForeground(Color.Cornsilk1),
|
ParameterName = new Style().Foreground(Color.Cornsilk1),
|
||||||
ParameterType = Style.WithForeground(Color.Red),
|
ParameterType = new Style().Foreground(Color.Red),
|
||||||
Path = Style.WithForeground(Color.Red),
|
Path = new Style().Foreground(Color.Red),
|
||||||
LineNumber = Style.WithForeground(Color.Cornsilk1),
|
LineNumber = new Style().Foreground(Color.Cornsilk1),
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -2,7 +2,7 @@
|
|||||||
|
|
||||||
<PropertyGroup>
|
<PropertyGroup>
|
||||||
<OutputType>Exe</OutputType>
|
<OutputType>Exe</OutputType>
|
||||||
<TargetFramework>netcoreapp3.1</TargetFramework>
|
<TargetFramework>net5.0</TargetFramework>
|
||||||
<IsPackable>false</IsPackable>
|
<IsPackable>false</IsPackable>
|
||||||
<Title>Grids</Title>
|
<Title>Grids</Title>
|
||||||
<Description>Demonstrates how to render grids in a console.</Description>
|
<Description>Demonstrates how to render grids in a console.</Description>
|
||||||
|
|||||||
@@ -11,13 +11,12 @@ namespace GridExample
|
|||||||
AnsiConsole.WriteLine();
|
AnsiConsole.WriteLine();
|
||||||
|
|
||||||
var grid = new Grid();
|
var grid = new Grid();
|
||||||
grid.AddColumn(new GridColumn { NoWrap = true });
|
grid.AddColumn(new GridColumn().NoWrap());
|
||||||
grid.AddColumn(new GridColumn { NoWrap = true, Width = 2 });
|
grid.AddColumn(new GridColumn().PadLeft(2));
|
||||||
grid.AddColumn();
|
grid.AddRow("Options:");
|
||||||
grid.AddRow("Options:", "", "");
|
grid.AddRow(" [blue]-h[/], [blue]--help[/]", "Show command line help.");
|
||||||
grid.AddRow(" [blue]-h[/], [blue]--help[/]", "", "Show command line help.");
|
grid.AddRow(" [blue]-c[/], [blue]--configuration[/] <CONFIGURATION>", "The configuration to run for.");
|
||||||
grid.AddRow(" [blue]-c[/], [blue]--configuration[/] <CONFIGURATION>", "", "The configuration to run for.");
|
grid.AddRow(" [blue]-v[/], [blue]--verbosity[/] <LEVEL>", "Set the [grey]MSBuild[/] verbosity level.");
|
||||||
grid.AddRow(" [blue]-v[/], [blue]--verbosity[/] <LEVEL>", "", "Set the [grey]MSBuild[/] verbosity level.");
|
|
||||||
|
|
||||||
AnsiConsole.Render(grid);
|
AnsiConsole.Render(grid);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -2,7 +2,7 @@
|
|||||||
|
|
||||||
<PropertyGroup>
|
<PropertyGroup>
|
||||||
<OutputType>Exe</OutputType>
|
<OutputType>Exe</OutputType>
|
||||||
<TargetFramework>netcoreapp3.1</TargetFramework>
|
<TargetFramework>net5.0</TargetFramework>
|
||||||
<IsPackable>false</IsPackable>
|
<IsPackable>false</IsPackable>
|
||||||
<Title>Info</Title>
|
<Title>Info</Title>
|
||||||
<Description>Displays the capabilities of the current console.</Description>
|
<Description>Displays the capabilities of the current console.</Description>
|
||||||
|
|||||||
@@ -1,3 +1,4 @@
|
|||||||
|
using System;
|
||||||
using Spectre.Console;
|
using Spectre.Console;
|
||||||
|
|
||||||
namespace InfoExample
|
namespace InfoExample
|
||||||
@@ -12,12 +13,13 @@ namespace InfoExample
|
|||||||
.AddRow("[b]Color system[/]", $"{AnsiConsole.Capabilities.ColorSystem}")
|
.AddRow("[b]Color system[/]", $"{AnsiConsole.Capabilities.ColorSystem}")
|
||||||
.AddRow("[b]Supports ansi?[/]", $"{YesNo(AnsiConsole.Capabilities.SupportsAnsi)}")
|
.AddRow("[b]Supports ansi?[/]", $"{YesNo(AnsiConsole.Capabilities.SupportsAnsi)}")
|
||||||
.AddRow("[b]Legacy console?[/]", $"{YesNo(AnsiConsole.Capabilities.LegacyConsole)}")
|
.AddRow("[b]Legacy console?[/]", $"{YesNo(AnsiConsole.Capabilities.LegacyConsole)}")
|
||||||
|
.AddRow("[b]Interactive?[/]", $"{YesNo(Environment.UserInteractive)}")
|
||||||
.AddRow("[b]Buffer width[/]", $"{AnsiConsole.Console.Width}")
|
.AddRow("[b]Buffer width[/]", $"{AnsiConsole.Console.Width}")
|
||||||
.AddRow("[b]Buffer height[/]", $"{AnsiConsole.Console.Height}");
|
.AddRow("[b]Buffer height[/]", $"{AnsiConsole.Console.Height}");
|
||||||
|
|
||||||
AnsiConsole.Render(
|
AnsiConsole.Render(
|
||||||
new Panel(grid)
|
new Panel(grid)
|
||||||
.SetHeader("Information"));
|
.Header("Information"));
|
||||||
}
|
}
|
||||||
|
|
||||||
private static string YesNo(bool value)
|
private static string YesNo(bool value)
|
||||||
|
|||||||
@@ -2,7 +2,7 @@
|
|||||||
|
|
||||||
<PropertyGroup>
|
<PropertyGroup>
|
||||||
<OutputType>Exe</OutputType>
|
<OutputType>Exe</OutputType>
|
||||||
<TargetFramework>netcoreapp3.1</TargetFramework>
|
<TargetFramework>net5.0</TargetFramework>
|
||||||
<IsPackable>false</IsPackable>
|
<IsPackable>false</IsPackable>
|
||||||
<Title>Links</Title>
|
<Title>Links</Title>
|
||||||
<Description>Demonstrates how to render links in a console.</Description>
|
<Description>Demonstrates how to render links in a console.</Description>
|
||||||
|
|||||||
@@ -2,7 +2,7 @@
|
|||||||
|
|
||||||
<PropertyGroup>
|
<PropertyGroup>
|
||||||
<OutputType>Exe</OutputType>
|
<OutputType>Exe</OutputType>
|
||||||
<TargetFramework>netcoreapp3.1</TargetFramework>
|
<TargetFramework>net5.0</TargetFramework>
|
||||||
<IsPackable>false</IsPackable>
|
<IsPackable>false</IsPackable>
|
||||||
<Title>Panels</Title>
|
<Title>Panels</Title>
|
||||||
<Description>Demonstrates how to render items in panels.</Description>
|
<Description>Demonstrates how to render items in panels.</Description>
|
||||||
|
|||||||
@@ -13,28 +13,30 @@ namespace PanelExample
|
|||||||
AnsiConsole.Render(
|
AnsiConsole.Render(
|
||||||
new Panel(
|
new Panel(
|
||||||
new Panel(content)
|
new Panel(content)
|
||||||
.SetBorder(BoxBorder.Rounded)));
|
.Border(BoxBorder.Rounded)));
|
||||||
|
|
||||||
// Left adjusted panel with text
|
// Left adjusted panel with text
|
||||||
AnsiConsole.Render(
|
AnsiConsole.Render(
|
||||||
new Panel(new Text("Left adjusted\nLeft").LeftAligned())
|
new Panel(new Text("Left adjusted\nLeft").LeftAligned())
|
||||||
.Expand()
|
.Expand()
|
||||||
.SquareBorder()
|
.SquareBorder()
|
||||||
.SetHeader("Left", Style.WithForeground(Color.Red)));
|
.Header("[red]Left[/]"));
|
||||||
|
|
||||||
// Centered ASCII panel with text
|
// Centered ASCII panel with text
|
||||||
AnsiConsole.Render(
|
AnsiConsole.Render(
|
||||||
new Panel(new Text("Centered\nCenter").Centered())
|
new Panel(new Text("Centered\nCenter").Centered())
|
||||||
.Expand()
|
.Expand()
|
||||||
.AsciiBorder()
|
.AsciiBorder()
|
||||||
.SetHeader("Center", Style.WithForeground(Color.Green), Justify.Center));
|
.Header("[green]Center[/]")
|
||||||
|
.HeaderAlignment(Justify.Center));
|
||||||
|
|
||||||
// Right adjusted, rounded panel with text
|
// Right adjusted, rounded panel with text
|
||||||
AnsiConsole.Render(
|
AnsiConsole.Render(
|
||||||
new Panel(new Text("Right adjusted\nRight").RightAligned())
|
new Panel(new Text("Right adjusted\nRight").RightAligned())
|
||||||
.Expand()
|
.Expand()
|
||||||
.RoundedBorder()
|
.RoundedBorder()
|
||||||
.SetHeader("Right", Style.WithForeground(Color.Blue), Justify.Right));
|
.Header("[blue]Right[/]")
|
||||||
|
.HeaderAlignment(Justify.Right));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
77
examples/Prompt/Program.cs
Normal file
77
examples/Prompt/Program.cs
Normal file
@@ -0,0 +1,77 @@
|
|||||||
|
using Spectre.Console;
|
||||||
|
|
||||||
|
namespace Cursor
|
||||||
|
{
|
||||||
|
public static class Program
|
||||||
|
{
|
||||||
|
public static void Main(string[] args)
|
||||||
|
{
|
||||||
|
// Confirmation
|
||||||
|
if (!AnsiConsole.Confirm("Run prompt example?"))
|
||||||
|
{
|
||||||
|
AnsiConsole.MarkupLine("Ok... :(");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
// String
|
||||||
|
AnsiConsole.WriteLine();
|
||||||
|
AnsiConsole.Render(new Rule("[yellow]Strings[/]").RuleStyle("grey").LeftAligned());
|
||||||
|
var name = AnsiConsole.Ask<string>("What's your [green]name[/]?");
|
||||||
|
|
||||||
|
// String with choices
|
||||||
|
AnsiConsole.WriteLine();
|
||||||
|
AnsiConsole.Render(new Rule("[yellow]Choices[/]").RuleStyle("grey").LeftAligned());
|
||||||
|
var fruit = AnsiConsole.Prompt(
|
||||||
|
new TextPrompt<string>("What's your [green]favorite fruit[/]?")
|
||||||
|
.InvalidChoiceMessage("[red]That's not a valid fruit[/]")
|
||||||
|
.DefaultValue("Orange")
|
||||||
|
.AddChoice("Apple")
|
||||||
|
.AddChoice("Banana")
|
||||||
|
.AddChoice("Orange"));
|
||||||
|
|
||||||
|
// Integer
|
||||||
|
AnsiConsole.WriteLine();
|
||||||
|
AnsiConsole.Render(new Rule("[yellow]Integers[/]").RuleStyle("grey").LeftAligned());
|
||||||
|
var age = AnsiConsole.Prompt(
|
||||||
|
new TextPrompt<int>("How [green]old[/] are you?")
|
||||||
|
.PromptStyle("green")
|
||||||
|
.ValidationErrorMessage("[red]That's not a valid age[/]")
|
||||||
|
.Validate(age =>
|
||||||
|
{
|
||||||
|
return age switch
|
||||||
|
{
|
||||||
|
<= 0 => ValidationResult.Error("[red]You must at least be 1 years old[/]"),
|
||||||
|
>= 123 => ValidationResult.Error("[red]You must be younger than the oldest person alive[/]"),
|
||||||
|
_ => ValidationResult.Success(),
|
||||||
|
};
|
||||||
|
}));
|
||||||
|
|
||||||
|
// Secret
|
||||||
|
AnsiConsole.WriteLine();
|
||||||
|
AnsiConsole.Render(new Rule("[yellow]Secrets[/]").RuleStyle("grey").LeftAligned());
|
||||||
|
var password = AnsiConsole.Prompt(
|
||||||
|
new TextPrompt<string>("Enter [green]password[/]?")
|
||||||
|
.PromptStyle("red")
|
||||||
|
.Secret());
|
||||||
|
|
||||||
|
// Optional
|
||||||
|
AnsiConsole.WriteLine();
|
||||||
|
AnsiConsole.Render(new Rule("[yellow]Optional[/]").RuleStyle("grey").LeftAligned());
|
||||||
|
var color = AnsiConsole.Prompt(
|
||||||
|
new TextPrompt<string>("[grey][[Optional]][/] What is your [green]favorite color[/]?")
|
||||||
|
.AllowEmpty());
|
||||||
|
|
||||||
|
// Summary
|
||||||
|
AnsiConsole.WriteLine();
|
||||||
|
AnsiConsole.Render(new Rule("[yellow]Results[/]").RuleStyle("grey").LeftAligned());
|
||||||
|
AnsiConsole.Render(new Table().AddColumns("[grey]Question[/]", "[grey]Answer[/]")
|
||||||
|
.RoundedBorder()
|
||||||
|
.BorderColor(Color.Grey)
|
||||||
|
.AddRow("[grey]Name[/]", name)
|
||||||
|
.AddRow("[grey]Favorite fruit[/]", fruit)
|
||||||
|
.AddRow("[grey]Age[/]", age.ToString())
|
||||||
|
.AddRow("[grey]Password[/]", password)
|
||||||
|
.AddRow("[grey]Favorite color[/]", string.IsNullOrEmpty(color) ? "Unknown" : color));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
16
examples/Prompt/Prompt.csproj
Normal file
16
examples/Prompt/Prompt.csproj
Normal file
@@ -0,0 +1,16 @@
|
|||||||
|
<Project Sdk="Microsoft.NET.Sdk">
|
||||||
|
|
||||||
|
<PropertyGroup>
|
||||||
|
<OutputType>Exe</OutputType>
|
||||||
|
<TargetFramework>netcoreapp3.1</TargetFramework>
|
||||||
|
<LangVersion>9</LangVersion>
|
||||||
|
<IsPackable>false</IsPackable>
|
||||||
|
<Title>Prompt</Title>
|
||||||
|
<Description>Demonstrates how to get input from a user.</Description>
|
||||||
|
</PropertyGroup>
|
||||||
|
|
||||||
|
<ItemGroup>
|
||||||
|
<ProjectReference Include="..\..\src\Spectre.Console\Spectre.Console.csproj" />
|
||||||
|
</ItemGroup>
|
||||||
|
|
||||||
|
</Project>
|
||||||
43
examples/Rules/Program.cs
Normal file
43
examples/Rules/Program.cs
Normal file
@@ -0,0 +1,43 @@
|
|||||||
|
using Spectre.Console;
|
||||||
|
|
||||||
|
namespace EmojiExample
|
||||||
|
{
|
||||||
|
public static class Program
|
||||||
|
{
|
||||||
|
public static void Main(string[] args)
|
||||||
|
{
|
||||||
|
// No title
|
||||||
|
WrapInPanel(
|
||||||
|
new Rule()
|
||||||
|
.RuleStyle(Style.Parse("yellow"))
|
||||||
|
.AsciiBorder()
|
||||||
|
.LeftAligned());
|
||||||
|
|
||||||
|
// Left aligned title
|
||||||
|
WrapInPanel(
|
||||||
|
new Rule("[blue]Left aligned[/]")
|
||||||
|
.RuleStyle(Style.Parse("red"))
|
||||||
|
.DoubleBorder()
|
||||||
|
.LeftAligned());
|
||||||
|
|
||||||
|
// Centered title
|
||||||
|
WrapInPanel(
|
||||||
|
new Rule("[green]Centered[/]")
|
||||||
|
.RuleStyle(Style.Parse("green"))
|
||||||
|
.HeavyBorder()
|
||||||
|
.Centered());
|
||||||
|
|
||||||
|
// Right aligned title
|
||||||
|
WrapInPanel(
|
||||||
|
new Rule("[red]Right aligned[/]")
|
||||||
|
.RuleStyle(Style.Parse("blue"))
|
||||||
|
.RightAligned());
|
||||||
|
}
|
||||||
|
|
||||||
|
private static void WrapInPanel(Rule rule)
|
||||||
|
{
|
||||||
|
AnsiConsole.Render(rule);
|
||||||
|
AnsiConsole.WriteLine();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
15
examples/Rules/Rules.csproj
Normal file
15
examples/Rules/Rules.csproj
Normal file
@@ -0,0 +1,15 @@
|
|||||||
|
<Project Sdk="Microsoft.NET.Sdk">
|
||||||
|
|
||||||
|
<PropertyGroup>
|
||||||
|
<OutputType>Exe</OutputType>
|
||||||
|
<TargetFramework>net5.0</TargetFramework>
|
||||||
|
<IsPackable>false</IsPackable>
|
||||||
|
<Title>Rules</Title>
|
||||||
|
<Description>Demonstrates how to render horizontal rules (lines).</Description>
|
||||||
|
</PropertyGroup>
|
||||||
|
|
||||||
|
<ItemGroup>
|
||||||
|
<ProjectReference Include="..\..\src\Spectre.Console\Spectre.Console.csproj" />
|
||||||
|
</ItemGroup>
|
||||||
|
|
||||||
|
</Project>
|
||||||
@@ -1,4 +1,3 @@
|
|||||||
using System.Diagnostics;
|
|
||||||
using Spectre.Console;
|
using Spectre.Console;
|
||||||
|
|
||||||
namespace TableExample
|
namespace TableExample
|
||||||
@@ -6,86 +5,47 @@ namespace TableExample
|
|||||||
public static class Program
|
public static class Program
|
||||||
{
|
{
|
||||||
public static void Main()
|
public static void Main()
|
||||||
{
|
|
||||||
// A simple table
|
|
||||||
RenderSimpleTable();
|
|
||||||
|
|
||||||
// A big table
|
|
||||||
RenderBigTable();
|
|
||||||
|
|
||||||
// A nested table
|
|
||||||
RenderNestedTable();
|
|
||||||
}
|
|
||||||
|
|
||||||
private static void RenderSimpleTable()
|
|
||||||
{
|
{
|
||||||
// Create the table.
|
// Create the table.
|
||||||
var table = new Table();
|
var table = CreateTable();
|
||||||
table.AddColumn(new TableColumn("[u]Foo[/]"));
|
|
||||||
table.AddColumn(new TableColumn("[u]Bar[/]"));
|
|
||||||
table.AddColumn(new TableColumn("[u]Baz[/]"));
|
|
||||||
|
|
||||||
// Add some rows
|
|
||||||
table.AddRow("Hello", "[red]World![/]", "");
|
|
||||||
table.AddRow("[blue]Bonjour[/]", "[white]le[/]", "[red]monde![/]");
|
|
||||||
table.AddRow("[blue]Hej[/]", "[yellow]Världen![/]", "");
|
|
||||||
|
|
||||||
|
// Render the table.
|
||||||
AnsiConsole.Render(table);
|
AnsiConsole.Render(table);
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void RenderBigTable()
|
private static Table CreateTable()
|
||||||
{
|
{
|
||||||
// Create the table.
|
var simple = new Table()
|
||||||
var table = new Table().SetBorder(TableBorder.Rounded);
|
.Border(TableBorder.Square)
|
||||||
table.AddColumn("[red underline]Foo[/]");
|
.BorderColor(Color.Red)
|
||||||
table.AddColumn(new TableColumn("[blue]Bar[/]") { Alignment = Justify.Right, NoWrap = true });
|
.AddColumn(new TableColumn("[u]CDE[/]").Footer("EDC").Centered())
|
||||||
|
.AddColumn(new TableColumn("[u]FED[/]").Footer("DEF"))
|
||||||
|
.AddColumn(new TableColumn("[u]IHG[/]").Footer("GHI"))
|
||||||
|
.AddRow("Hello", "[red]World![/]", "")
|
||||||
|
.AddRow("[blue]Bonjour[/]", "[white]le[/]", "[red]monde![/]")
|
||||||
|
.AddRow("[blue]Hej[/]", "[yellow]Världen![/]", "");
|
||||||
|
|
||||||
// Add some rows
|
var second = new Table()
|
||||||
table.AddRow("[blue][underline]Hell[/]o[/]", "World");
|
.Border(TableBorder.Rounded)
|
||||||
table.AddRow("[yellow]Patrik [green]\"Hello World\"[/] Svensson[/]", "Was [underline]here[/]!");
|
.BorderColor(Color.Green)
|
||||||
table.AddEmptyRow();
|
.AddColumn(new TableColumn("[u]Foo[/]"))
|
||||||
table.AddRow(
|
.AddColumn(new TableColumn("[u]Bar[/]"))
|
||||||
"Lorem ipsum dolor sit amet, consectetur adipiscing elit,sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. " +
|
.AddColumn(new TableColumn("[u]Baz[/]"))
|
||||||
"Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure " +
|
.AddRow("Hello", "[red]World![/]", "")
|
||||||
"dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat " +
|
.AddRow(simple, new Text("Whaaat"), new Text("Lolz"))
|
||||||
"non proident, sunt in culpa qui officia deserunt mollit anim id est laborum", "<- Strange language");
|
.AddRow("[blue]Hej[/]", "[yellow]Världen![/]", "");
|
||||||
table.AddEmptyRow();
|
|
||||||
table.AddRow("Hej", "[green]Världen[/]");
|
|
||||||
|
|
||||||
AnsiConsole.Render(table);
|
return new Table()
|
||||||
}
|
.Centered()
|
||||||
|
.Border(TableBorder.DoubleEdge)
|
||||||
private static void RenderNestedTable()
|
.Title("TABLE [yellow]TITLE[/]")
|
||||||
{
|
.Caption("TABLE [yellow]CAPTION[/]")
|
||||||
// Create simple table.
|
.AddColumn(new TableColumn(new Panel("[u]ABC[/]").BorderColor(Color.Red)).Footer("[u]FOOTER 1[/]"))
|
||||||
var simple = new Table().SetBorder(TableBorder.Rounded).SetBorderColor(Color.Red);
|
.AddColumn(new TableColumn(new Panel("[u]DEF[/]").BorderColor(Color.Green)).Footer("[u]FOOTER 2[/]"))
|
||||||
simple.AddColumn(new TableColumn("[u]Foo[/]").Centered());
|
.AddColumn(new TableColumn(new Panel("[u]GHI[/]").BorderColor(Color.Blue)).Footer("[u]FOOTER 3[/]"))
|
||||||
simple.AddColumn(new TableColumn("[u]Bar[/]"));
|
.AddRow(new Text("Hello").Centered(), new Markup("[red]World![/]"), Text.Empty)
|
||||||
simple.AddColumn(new TableColumn("[u]Baz[/]"));
|
.AddRow(second, new Text("Whaaat"), new Text("Lol"))
|
||||||
simple.AddRow("Hello", "[red]World![/]", "");
|
.AddRow(new Markup("[blue]Hej[/]").Centered(), new Markup("[yellow]Världen![/]"), Text.Empty);
|
||||||
simple.AddRow("[blue]Bonjour[/]", "[white]le[/]", "[red]monde![/]");
|
|
||||||
simple.AddRow("[blue]Hej[/]", "[yellow]Världen![/]", "");
|
|
||||||
|
|
||||||
// Create other table.
|
|
||||||
var second = new Table().SetBorder(TableBorder.Square).SetBorderColor(Color.Green);
|
|
||||||
second.AddColumn(new TableColumn("[u]Foo[/]"));
|
|
||||||
second.AddColumn(new TableColumn("[u]Bar[/]"));
|
|
||||||
second.AddColumn(new TableColumn("[u]Baz[/]"));
|
|
||||||
second.AddRow("Hello", "[red]World![/]", "");
|
|
||||||
second.AddRow(simple, new Text("Whaaat"), new Text("Lolz"));
|
|
||||||
second.AddRow("[blue]Hej[/]", "[yellow]Världen![/]", "");
|
|
||||||
|
|
||||||
var table = new Table().SetBorder(TableBorder.Rounded);
|
|
||||||
table.AddColumn(new TableColumn(new Panel("[u]Foo[/]").SetBorderColor(Color.Red)));
|
|
||||||
table.AddColumn(new TableColumn(new Panel("[u]Bar[/]").SetBorderColor(Color.Green)));
|
|
||||||
table.AddColumn(new TableColumn(new Panel("[u]Baz[/]").SetBorderColor(Color.Blue)));
|
|
||||||
|
|
||||||
// Add some rows
|
|
||||||
table.AddRow(new Text("Hello").Centered(), new Markup("[red]World![/]"), Text.Empty);
|
|
||||||
table.AddRow(second, new Text("Whaaat"), new Text("Lol"));
|
|
||||||
table.AddRow(new Markup("[blue]Hej[/]").Centered(), new Markup("[yellow]Världen![/]"), Text.Empty);
|
|
||||||
|
|
||||||
AnsiConsole.Render(table);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -2,7 +2,7 @@
|
|||||||
|
|
||||||
<PropertyGroup>
|
<PropertyGroup>
|
||||||
<OutputType>Exe</OutputType>
|
<OutputType>Exe</OutputType>
|
||||||
<TargetFramework>netcoreapp3.1</TargetFramework>
|
<TargetFramework>net5.0</TargetFramework>
|
||||||
<IsPackable>false</IsPackable>
|
<IsPackable>false</IsPackable>
|
||||||
<Title>Tables</Title>
|
<Title>Tables</Title>
|
||||||
<Description>Demonstrates how to render tables in a console.</Description>
|
<Description>Demonstrates how to render tables in a console.</Description>
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
{
|
{
|
||||||
"projects": [ "src" ],
|
"projects": [ "src" ],
|
||||||
"sdk": {
|
"sdk": {
|
||||||
"version": "3.1.301",
|
"version": "5.0.100",
|
||||||
"rollForward": "latestPatch"
|
"rollForward": "latestPatch"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -1,7 +1,7 @@
|
|||||||
<Project>
|
<Project>
|
||||||
<PropertyGroup Label="Settings">
|
<PropertyGroup Label="Settings">
|
||||||
<Deterministic>true</Deterministic>
|
<Deterministic>true</Deterministic>
|
||||||
<LangVersion>8.0</LangVersion>
|
<LangVersion>9.0</LangVersion>
|
||||||
<DebugSymbols>true</DebugSymbols>
|
<DebugSymbols>true</DebugSymbols>
|
||||||
<DebugType>embedded</DebugType>
|
<DebugType>embedded</DebugType>
|
||||||
<MinVerSkip Condition="'$(Configuration)' == 'Debug'">true</MinVerSkip>
|
<MinVerSkip Condition="'$(Configuration)' == 'Debug'">true</MinVerSkip>
|
||||||
|
|||||||
@@ -6,10 +6,10 @@ namespace Spectre.Console.Tests
|
|||||||
{
|
{
|
||||||
if (foreground)
|
if (foreground)
|
||||||
{
|
{
|
||||||
return style.WithForeground(color);
|
return style.Foreground(color);
|
||||||
}
|
}
|
||||||
|
|
||||||
return style.WithBackground(color);
|
return style.Background(color);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
<Project Sdk="Microsoft.NET.Sdk">
|
<Project Sdk="Microsoft.NET.Sdk">
|
||||||
|
|
||||||
<PropertyGroup>
|
<PropertyGroup>
|
||||||
<TargetFramework>netcoreapp3.1</TargetFramework>
|
<TargetFrameworks>net5.0;netcoreapp3.1</TargetFrameworks>
|
||||||
<IsPackable>false</IsPackable>
|
<IsPackable>false</IsPackable>
|
||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
|
|
||||||
|
|||||||
@@ -1,44 +0,0 @@
|
|||||||
using System;
|
|
||||||
using System.IO;
|
|
||||||
using System.Text;
|
|
||||||
using Spectre.Console.Rendering;
|
|
||||||
|
|
||||||
namespace Spectre.Console.Tests.Tools
|
|
||||||
{
|
|
||||||
public sealed class MarkupConsoleFixture : IDisposable, IAnsiConsole
|
|
||||||
{
|
|
||||||
private readonly StringWriter _writer;
|
|
||||||
private readonly IAnsiConsole _console;
|
|
||||||
|
|
||||||
public string Output => _writer.ToString().TrimEnd('\n');
|
|
||||||
|
|
||||||
public Capabilities Capabilities => _console.Capabilities;
|
|
||||||
public Encoding Encoding => _console.Encoding;
|
|
||||||
public int Width { get; }
|
|
||||||
public int Height => _console.Height;
|
|
||||||
|
|
||||||
public MarkupConsoleFixture(ColorSystem system, AnsiSupport ansi = AnsiSupport.Yes, int width = 80)
|
|
||||||
{
|
|
||||||
_writer = new StringWriter();
|
|
||||||
_console = AnsiConsole.Create(new AnsiConsoleSettings
|
|
||||||
{
|
|
||||||
Ansi = ansi,
|
|
||||||
ColorSystem = (ColorSystemSupport)system,
|
|
||||||
Out = _writer,
|
|
||||||
LinkIdentityGenerator = new TestLinkIdentityGenerator(),
|
|
||||||
});
|
|
||||||
|
|
||||||
Width = width;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void Dispose()
|
|
||||||
{
|
|
||||||
_writer?.Dispose();
|
|
||||||
}
|
|
||||||
|
|
||||||
public void Write(Segment segment)
|
|
||||||
{
|
|
||||||
_console.Write(segment);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -11,10 +11,14 @@ namespace Spectre.Console.Tests
|
|||||||
{
|
{
|
||||||
public Capabilities Capabilities { get; }
|
public Capabilities Capabilities { get; }
|
||||||
public Encoding Encoding { get; }
|
public Encoding Encoding { get; }
|
||||||
|
public IAnsiConsoleCursor Cursor => throw new NotSupportedException();
|
||||||
|
public TestableConsoleInput Input { get; }
|
||||||
|
|
||||||
public int Width { get; }
|
public int Width { get; }
|
||||||
public int Height { get; }
|
public int Height { get; }
|
||||||
|
|
||||||
|
IAnsiConsoleInput IAnsiConsole.Input => Input;
|
||||||
|
|
||||||
public Decoration Decoration { get; set; }
|
public Decoration Decoration { get; set; }
|
||||||
public Color Foreground { get; set; }
|
public Color Foreground { get; set; }
|
||||||
public Color Background { get; set; }
|
public Color Background { get; set; }
|
||||||
@@ -35,6 +39,7 @@ namespace Spectre.Console.Tests
|
|||||||
Width = width;
|
Width = width;
|
||||||
Height = height;
|
Height = height;
|
||||||
Writer = new StringWriter();
|
Writer = new StringWriter();
|
||||||
|
Input = new TestableConsoleInput();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void Dispose()
|
public void Dispose()
|
||||||
@@ -42,6 +47,10 @@ namespace Spectre.Console.Tests
|
|||||||
Writer.Dispose();
|
Writer.Dispose();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void Clear(bool home)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
public void Write(Segment segment)
|
public void Write(Segment segment)
|
||||||
{
|
{
|
||||||
if (segment is null)
|
if (segment is null)
|
||||||
|
|||||||
@@ -17,6 +17,10 @@ namespace Spectre.Console.Tests
|
|||||||
public Encoding Encoding => _console.Encoding;
|
public Encoding Encoding => _console.Encoding;
|
||||||
public int Width { get; }
|
public int Width { get; }
|
||||||
public int Height => _console.Height;
|
public int Height => _console.Height;
|
||||||
|
public IAnsiConsoleCursor Cursor => _console.Cursor;
|
||||||
|
public TestableConsoleInput Input { get; }
|
||||||
|
|
||||||
|
IAnsiConsoleInput IAnsiConsole.Input => Input;
|
||||||
|
|
||||||
public TestableAnsiConsole(ColorSystem system, AnsiSupport ansi = AnsiSupport.Yes, int width = 80)
|
public TestableAnsiConsole(ColorSystem system, AnsiSupport ansi = AnsiSupport.Yes, int width = 80)
|
||||||
{
|
{
|
||||||
@@ -30,6 +34,7 @@ namespace Spectre.Console.Tests
|
|||||||
});
|
});
|
||||||
|
|
||||||
Width = width;
|
Width = width;
|
||||||
|
Input = new TestableConsoleInput();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void Dispose()
|
public void Dispose()
|
||||||
@@ -37,6 +42,11 @@ namespace Spectre.Console.Tests
|
|||||||
_writer?.Dispose();
|
_writer?.Dispose();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void Clear(bool home)
|
||||||
|
{
|
||||||
|
_console.Clear(home);
|
||||||
|
}
|
||||||
|
|
||||||
public void Write(Segment segment)
|
public void Write(Segment segment)
|
||||||
{
|
{
|
||||||
_console.Write(segment);
|
_console.Write(segment);
|
||||||
51
src/Spectre.Console.Tests/Tools/TestableConsoleInput.cs
Normal file
51
src/Spectre.Console.Tests/Tools/TestableConsoleInput.cs
Normal file
@@ -0,0 +1,51 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
|
||||||
|
namespace Spectre.Console.Tests
|
||||||
|
{
|
||||||
|
public sealed class TestableConsoleInput : IAnsiConsoleInput
|
||||||
|
{
|
||||||
|
private readonly Queue<ConsoleKeyInfo> _input;
|
||||||
|
|
||||||
|
public TestableConsoleInput()
|
||||||
|
{
|
||||||
|
_input = new Queue<ConsoleKeyInfo>();
|
||||||
|
}
|
||||||
|
|
||||||
|
public void PushText(string input)
|
||||||
|
{
|
||||||
|
if (input is null)
|
||||||
|
{
|
||||||
|
throw new ArgumentNullException(nameof(input));
|
||||||
|
}
|
||||||
|
|
||||||
|
foreach (var character in input)
|
||||||
|
{
|
||||||
|
PushCharacter(character);
|
||||||
|
}
|
||||||
|
|
||||||
|
PushKey(ConsoleKey.Enter);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void PushCharacter(char character)
|
||||||
|
{
|
||||||
|
var control = char.IsUpper(character);
|
||||||
|
_input.Enqueue(new ConsoleKeyInfo(character, (ConsoleKey)character, false, false, control));
|
||||||
|
}
|
||||||
|
|
||||||
|
public void PushKey(ConsoleKey key)
|
||||||
|
{
|
||||||
|
_input.Enqueue(new ConsoleKeyInfo((char)key, key, false, false, false));
|
||||||
|
}
|
||||||
|
|
||||||
|
public ConsoleKeyInfo ReadKey(bool intercept)
|
||||||
|
{
|
||||||
|
if (_input.Count == 0)
|
||||||
|
{
|
||||||
|
throw new InvalidOperationException("No input available.");
|
||||||
|
}
|
||||||
|
|
||||||
|
return _input.Dequeue();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -21,7 +21,7 @@ namespace Spectre.Console.Tests.Unit
|
|||||||
var console = new TestableAnsiConsole(ColorSystem.TrueColor);
|
var console = new TestableAnsiConsole(ColorSystem.TrueColor);
|
||||||
|
|
||||||
// When
|
// When
|
||||||
console.Write("Hello World", Style.WithDecoration(decoration));
|
console.Write("Hello World", new Style().Decoration(decoration));
|
||||||
|
|
||||||
// Then
|
// Then
|
||||||
console.Output.ShouldBe(expected);
|
console.Output.ShouldBe(expected);
|
||||||
@@ -36,7 +36,7 @@ namespace Spectre.Console.Tests.Unit
|
|||||||
var console = new TestableAnsiConsole(ColorSystem.TrueColor);
|
var console = new TestableAnsiConsole(ColorSystem.TrueColor);
|
||||||
|
|
||||||
// When
|
// When
|
||||||
console.Write("Hello World", Style.WithDecoration(decoration));
|
console.Write("Hello World", new Style().Decoration(decoration));
|
||||||
|
|
||||||
// Then
|
// Then
|
||||||
console.Output.ShouldBe(expected);
|
console.Output.ShouldBe(expected);
|
||||||
|
|||||||
@@ -15,9 +15,10 @@ namespace Spectre.Console.Tests.Unit
|
|||||||
// When
|
// When
|
||||||
console.Write(
|
console.Write(
|
||||||
"Hello",
|
"Hello",
|
||||||
Style.WithForeground(Color.RoyalBlue1)
|
new Style()
|
||||||
.WithBackground(Color.NavajoWhite1)
|
.Foreground(Color.RoyalBlue1)
|
||||||
.WithDecoration(Decoration.Italic));
|
.Background(Color.NavajoWhite1)
|
||||||
|
.Decoration(Decoration.Italic));
|
||||||
|
|
||||||
// Then
|
// Then
|
||||||
console.Output.ShouldBe("\u001b[3;90;47mHello\u001b[0m");
|
console.Output.ShouldBe("\u001b[3;90;47mHello\u001b[0m");
|
||||||
@@ -32,9 +33,10 @@ namespace Spectre.Console.Tests.Unit
|
|||||||
// When
|
// When
|
||||||
console.Write(
|
console.Write(
|
||||||
"Hello",
|
"Hello",
|
||||||
Style.WithForeground(Color.Default)
|
new Style()
|
||||||
.WithBackground(Color.NavajoWhite1)
|
.Foreground(Color.Default)
|
||||||
.WithDecoration(Decoration.Italic));
|
.Background(Color.NavajoWhite1)
|
||||||
|
.Decoration(Decoration.Italic));
|
||||||
|
|
||||||
// Then
|
// Then
|
||||||
console.Output.ShouldBe("\u001b[3;47mHello\u001b[0m");
|
console.Output.ShouldBe("\u001b[3;47mHello\u001b[0m");
|
||||||
@@ -49,9 +51,10 @@ namespace Spectre.Console.Tests.Unit
|
|||||||
// When
|
// When
|
||||||
console.Write(
|
console.Write(
|
||||||
"Hello",
|
"Hello",
|
||||||
Style.WithForeground(Color.RoyalBlue1)
|
new Style()
|
||||||
.WithBackground(Color.Default)
|
.Foreground(Color.RoyalBlue1)
|
||||||
.WithDecoration(Decoration.Italic));
|
.Background(Color.Default)
|
||||||
|
.Decoration(Decoration.Italic));
|
||||||
|
|
||||||
// Then
|
// Then
|
||||||
console.Output.ShouldBe("\u001b[3;90mHello\u001b[0m");
|
console.Output.ShouldBe("\u001b[3;90mHello\u001b[0m");
|
||||||
@@ -66,9 +69,10 @@ namespace Spectre.Console.Tests.Unit
|
|||||||
// When
|
// When
|
||||||
console.Write(
|
console.Write(
|
||||||
"Hello",
|
"Hello",
|
||||||
Style.WithForeground(Color.RoyalBlue1)
|
new Style()
|
||||||
.WithBackground(Color.NavajoWhite1)
|
.Foreground(Color.RoyalBlue1)
|
||||||
.WithDecoration(Decoration.None));
|
.Background(Color.NavajoWhite1)
|
||||||
|
.Decoration(Decoration.None));
|
||||||
|
|
||||||
// Then
|
// Then
|
||||||
console.Output.ShouldBe("\u001b[90;47mHello\u001b[0m");
|
console.Output.ShouldBe("\u001b[90;47mHello\u001b[0m");
|
||||||
@@ -83,8 +87,8 @@ namespace Spectre.Console.Tests.Unit
|
|||||||
var console = new TestableAnsiConsole(ColorSystem.Standard, AnsiSupport.Yes);
|
var console = new TestableAnsiConsole(ColorSystem.Standard, AnsiSupport.Yes);
|
||||||
|
|
||||||
// When
|
// When
|
||||||
console.WriteLine("Hello", Style.WithBackground(ConsoleColor.Red));
|
console.WriteLine("Hello", new Style().Background(ConsoleColor.Red));
|
||||||
console.WriteLine("World", Style.WithBackground(ConsoleColor.Green));
|
console.WriteLine("World", new Style().Background(ConsoleColor.Green));
|
||||||
|
|
||||||
// Then
|
// Then
|
||||||
console.Output.NormalizeLineEndings()
|
console.Output.NormalizeLineEndings()
|
||||||
@@ -98,7 +102,7 @@ namespace Spectre.Console.Tests.Unit
|
|||||||
var console = new TestableAnsiConsole(ColorSystem.Standard, AnsiSupport.Yes);
|
var console = new TestableAnsiConsole(ColorSystem.Standard, AnsiSupport.Yes);
|
||||||
|
|
||||||
// When
|
// When
|
||||||
console.WriteLine("Hello\nWorld", Style.WithBackground(ConsoleColor.Red));
|
console.WriteLine("Hello\nWorld", new Style().Background(ConsoleColor.Red));
|
||||||
|
|
||||||
// Then
|
// Then
|
||||||
console.Output.NormalizeLineEndings()
|
console.Output.NormalizeLineEndings()
|
||||||
|
|||||||
@@ -14,7 +14,7 @@ namespace Spectre.Console.Tests.Unit
|
|||||||
public void Should_Return_Safe_Border()
|
public void Should_Return_Safe_Border()
|
||||||
{
|
{
|
||||||
// Given, When
|
// Given, When
|
||||||
var border = BoxBorder.None.GetSafeBorder(safe: true);
|
var border = BoxExtensions.GetSafeBorder(BoxBorder.None, safe: true);
|
||||||
|
|
||||||
// Then
|
// Then
|
||||||
border.ShouldBeSameAs(BoxBorder.None);
|
border.ShouldBeSameAs(BoxBorder.None);
|
||||||
@@ -47,7 +47,7 @@ namespace Spectre.Console.Tests.Unit
|
|||||||
public void Should_Return_Safe_Border()
|
public void Should_Return_Safe_Border()
|
||||||
{
|
{
|
||||||
// Given, When
|
// Given, When
|
||||||
var border = BoxBorder.Ascii.GetSafeBorder(safe: true);
|
var border = BoxExtensions.GetSafeBorder(BoxBorder.Ascii, safe: true);
|
||||||
|
|
||||||
// Then
|
// Then
|
||||||
border.ShouldBeSameAs(BoxBorder.Ascii);
|
border.ShouldBeSameAs(BoxBorder.Ascii);
|
||||||
@@ -80,7 +80,7 @@ namespace Spectre.Console.Tests.Unit
|
|||||||
public void Should_Return_Safe_Border()
|
public void Should_Return_Safe_Border()
|
||||||
{
|
{
|
||||||
// Given, When
|
// Given, When
|
||||||
var border = BoxBorder.Double.GetSafeBorder(safe: true);
|
var border = BoxExtensions.GetSafeBorder(BoxBorder.Double, safe: true);
|
||||||
|
|
||||||
// Then
|
// Then
|
||||||
border.ShouldBeSameAs(BoxBorder.Double);
|
border.ShouldBeSameAs(BoxBorder.Double);
|
||||||
@@ -113,7 +113,7 @@ namespace Spectre.Console.Tests.Unit
|
|||||||
public void Should_Return_Safe_Border()
|
public void Should_Return_Safe_Border()
|
||||||
{
|
{
|
||||||
// Given, When
|
// Given, When
|
||||||
var border = BoxBorder.Heavy.GetSafeBorder(safe: true);
|
var border = BoxExtensions.GetSafeBorder(BoxBorder.Heavy, safe: true);
|
||||||
|
|
||||||
// Then
|
// Then
|
||||||
border.ShouldBeSameAs(BoxBorder.Square);
|
border.ShouldBeSameAs(BoxBorder.Square);
|
||||||
@@ -144,7 +144,7 @@ namespace Spectre.Console.Tests.Unit
|
|||||||
public void Should_Return_Safe_Border()
|
public void Should_Return_Safe_Border()
|
||||||
{
|
{
|
||||||
// Given, When
|
// Given, When
|
||||||
var border = BoxBorder.Rounded.GetSafeBorder(safe: true);
|
var border = BoxExtensions.GetSafeBorder(BoxBorder.Rounded, safe: true);
|
||||||
|
|
||||||
// Then
|
// Then
|
||||||
border.ShouldBeSameAs(BoxBorder.Square);
|
border.ShouldBeSameAs(BoxBorder.Square);
|
||||||
@@ -174,7 +174,7 @@ namespace Spectre.Console.Tests.Unit
|
|||||||
public void Should_Return_Safe_Border()
|
public void Should_Return_Safe_Border()
|
||||||
{
|
{
|
||||||
// Given, When
|
// Given, When
|
||||||
var border = BoxBorder.Square.GetSafeBorder(safe: true);
|
var border = BoxExtensions.GetSafeBorder(BoxBorder.Square, safe: true);
|
||||||
|
|
||||||
// Then
|
// Then
|
||||||
border.ShouldBeSameAs(BoxBorder.Square);
|
border.ShouldBeSameAs(BoxBorder.Square);
|
||||||
@@ -203,7 +203,7 @@ namespace Spectre.Console.Tests.Unit
|
|||||||
public static Panel GetPanel()
|
public static Panel GetPanel()
|
||||||
{
|
{
|
||||||
return new Panel("Hello World")
|
return new Panel("Hello World")
|
||||||
.SetHeader("Greeting");
|
.Header("Greeting");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -20,17 +20,105 @@ namespace Spectre.Console.Tests.Unit
|
|||||||
console.Render(calendar);
|
console.Render(calendar);
|
||||||
|
|
||||||
// Then
|
// Then
|
||||||
console.Lines.Count.ShouldBe(10);
|
console.Lines.Count.ShouldBe(11);
|
||||||
console.Lines[0].ShouldBe("┌─────┬─────┬─────┬─────┬─────┬─────┬─────┐");
|
console.Lines[00].ShouldBe(" 2020 October ");
|
||||||
console.Lines[1].ShouldBe("│ Sun │ Mon │ Tue │ Wed │ Thu │ Fri │ Sat │");
|
console.Lines[01].ShouldBe("┌─────┬─────┬─────┬─────┬─────┬─────┬─────┐");
|
||||||
console.Lines[2].ShouldBe("├─────┼─────┼─────┼─────┼─────┼─────┼─────┤");
|
console.Lines[02].ShouldBe("│ Sun │ Mon │ Tue │ Wed │ Thu │ Fri │ Sat │");
|
||||||
console.Lines[3].ShouldBe("│ │ │ │ │ 1 │ 2 │ 3* │");
|
console.Lines[03].ShouldBe("├─────┼─────┼─────┼─────┼─────┼─────┼─────┤");
|
||||||
console.Lines[4].ShouldBe("│ 4 │ 5 │ 6 │ 7 │ 8 │ 9 │ 10 │");
|
console.Lines[04].ShouldBe("│ │ │ │ │ 1 │ 2 │ 3* │");
|
||||||
console.Lines[5].ShouldBe("│ 11 │ 12* │ 13 │ 14 │ 15 │ 16 │ 17 │");
|
console.Lines[05].ShouldBe("│ 4 │ 5 │ 6 │ 7 │ 8 │ 9 │ 10 │");
|
||||||
console.Lines[6].ShouldBe("│ 18 │ 19 │ 20 │ 21 │ 22 │ 23 │ 24 │");
|
console.Lines[06].ShouldBe("│ 11 │ 12* │ 13 │ 14 │ 15 │ 16 │ 17 │");
|
||||||
console.Lines[7].ShouldBe("│ 25 │ 26 │ 27 │ 28 │ 29 │ 30 │ 31 │");
|
console.Lines[07].ShouldBe("│ 18 │ 19 │ 20 │ 21 │ 22 │ 23 │ 24 │");
|
||||||
console.Lines[8].ShouldBe("│ │ │ │ │ │ │ │");
|
console.Lines[08].ShouldBe("│ 25 │ 26 │ 27 │ 28 │ 29 │ 30 │ 31 │");
|
||||||
console.Lines[9].ShouldBe("└─────┴─────┴─────┴─────┴─────┴─────┴─────┘");
|
console.Lines[09].ShouldBe("│ │ │ │ │ │ │ │");
|
||||||
|
console.Lines[10].ShouldBe("└─────┴─────┴─────┴─────┴─────┴─────┴─────┘");
|
||||||
|
}
|
||||||
|
|
||||||
|
[Fact]
|
||||||
|
public void Should_Center_Calendar_Correctly()
|
||||||
|
{
|
||||||
|
// Given
|
||||||
|
var console = new PlainConsole(width: 80);
|
||||||
|
var calendar = new Calendar(2020, 10)
|
||||||
|
.Centered()
|
||||||
|
.AddCalendarEvent(new DateTime(2020, 9, 1))
|
||||||
|
.AddCalendarEvent(new DateTime(2020, 10, 3))
|
||||||
|
.AddCalendarEvent(new DateTime(2020, 10, 12));
|
||||||
|
|
||||||
|
// When
|
||||||
|
console.Render(calendar);
|
||||||
|
|
||||||
|
// Then
|
||||||
|
console.Lines.Count.ShouldBe(11);
|
||||||
|
console.Lines[00].ShouldBe(" 2020 October ");
|
||||||
|
console.Lines[01].ShouldBe(" ┌─────┬─────┬─────┬─────┬─────┬─────┬─────┐ ");
|
||||||
|
console.Lines[02].ShouldBe(" │ Sun │ Mon │ Tue │ Wed │ Thu │ Fri │ Sat │ ");
|
||||||
|
console.Lines[03].ShouldBe(" ├─────┼─────┼─────┼─────┼─────┼─────┼─────┤ ");
|
||||||
|
console.Lines[04].ShouldBe(" │ │ │ │ │ 1 │ 2 │ 3* │ ");
|
||||||
|
console.Lines[05].ShouldBe(" │ 4 │ 5 │ 6 │ 7 │ 8 │ 9 │ 10 │ ");
|
||||||
|
console.Lines[06].ShouldBe(" │ 11 │ 12* │ 13 │ 14 │ 15 │ 16 │ 17 │ ");
|
||||||
|
console.Lines[07].ShouldBe(" │ 18 │ 19 │ 20 │ 21 │ 22 │ 23 │ 24 │ ");
|
||||||
|
console.Lines[08].ShouldBe(" │ 25 │ 26 │ 27 │ 28 │ 29 │ 30 │ 31 │ ");
|
||||||
|
console.Lines[09].ShouldBe(" │ │ │ │ │ │ │ │ ");
|
||||||
|
console.Lines[10].ShouldBe(" └─────┴─────┴─────┴─────┴─────┴─────┴─────┘ ");
|
||||||
|
}
|
||||||
|
|
||||||
|
[Fact]
|
||||||
|
public void Should_Left_Align_Calendar_Correctly()
|
||||||
|
{
|
||||||
|
// Given
|
||||||
|
var console = new PlainConsole(width: 80);
|
||||||
|
var calendar = new Calendar(2020, 10)
|
||||||
|
.LeftAligned()
|
||||||
|
.AddCalendarEvent(new DateTime(2020, 9, 1))
|
||||||
|
.AddCalendarEvent(new DateTime(2020, 10, 3))
|
||||||
|
.AddCalendarEvent(new DateTime(2020, 10, 12));
|
||||||
|
|
||||||
|
// When
|
||||||
|
console.Render(calendar);
|
||||||
|
|
||||||
|
// Then
|
||||||
|
console.Lines.Count.ShouldBe(11);
|
||||||
|
console.Lines[00].ShouldBe(" 2020 October ");
|
||||||
|
console.Lines[01].ShouldBe("┌─────┬─────┬─────┬─────┬─────┬─────┬─────┐");
|
||||||
|
console.Lines[02].ShouldBe("│ Sun │ Mon │ Tue │ Wed │ Thu │ Fri │ Sat │");
|
||||||
|
console.Lines[03].ShouldBe("├─────┼─────┼─────┼─────┼─────┼─────┼─────┤");
|
||||||
|
console.Lines[04].ShouldBe("│ │ │ │ │ 1 │ 2 │ 3* │");
|
||||||
|
console.Lines[05].ShouldBe("│ 4 │ 5 │ 6 │ 7 │ 8 │ 9 │ 10 │");
|
||||||
|
console.Lines[06].ShouldBe("│ 11 │ 12* │ 13 │ 14 │ 15 │ 16 │ 17 │");
|
||||||
|
console.Lines[07].ShouldBe("│ 18 │ 19 │ 20 │ 21 │ 22 │ 23 │ 24 │");
|
||||||
|
console.Lines[08].ShouldBe("│ 25 │ 26 │ 27 │ 28 │ 29 │ 30 │ 31 │");
|
||||||
|
console.Lines[09].ShouldBe("│ │ │ │ │ │ │ │");
|
||||||
|
console.Lines[10].ShouldBe("└─────┴─────┴─────┴─────┴─────┴─────┴─────┘");
|
||||||
|
}
|
||||||
|
|
||||||
|
[Fact]
|
||||||
|
public void Should_Right_Align_Calendar_Correctly()
|
||||||
|
{
|
||||||
|
// Given
|
||||||
|
var console = new PlainConsole(width: 80);
|
||||||
|
var calendar = new Calendar(2020, 10)
|
||||||
|
.RightAligned()
|
||||||
|
.AddCalendarEvent(new DateTime(2020, 9, 1))
|
||||||
|
.AddCalendarEvent(new DateTime(2020, 10, 3))
|
||||||
|
.AddCalendarEvent(new DateTime(2020, 10, 12));
|
||||||
|
|
||||||
|
// When
|
||||||
|
console.Render(calendar);
|
||||||
|
|
||||||
|
// Then
|
||||||
|
console.Lines.Count.ShouldBe(11);
|
||||||
|
console.Lines[00].ShouldBe(" 2020 October ");
|
||||||
|
console.Lines[01].ShouldBe(" ┌─────┬─────┬─────┬─────┬─────┬─────┬─────┐");
|
||||||
|
console.Lines[02].ShouldBe(" │ Sun │ Mon │ Tue │ Wed │ Thu │ Fri │ Sat │");
|
||||||
|
console.Lines[03].ShouldBe(" ├─────┼─────┼─────┼─────┼─────┼─────┼─────┤");
|
||||||
|
console.Lines[04].ShouldBe(" │ │ │ │ │ 1 │ 2 │ 3* │");
|
||||||
|
console.Lines[05].ShouldBe(" │ 4 │ 5 │ 6 │ 7 │ 8 │ 9 │ 10 │");
|
||||||
|
console.Lines[06].ShouldBe(" │ 11 │ 12* │ 13 │ 14 │ 15 │ 16 │ 17 │");
|
||||||
|
console.Lines[07].ShouldBe(" │ 18 │ 19 │ 20 │ 21 │ 22 │ 23 │ 24 │");
|
||||||
|
console.Lines[08].ShouldBe(" │ 25 │ 26 │ 27 │ 28 │ 29 │ 30 │ 31 │");
|
||||||
|
console.Lines[09].ShouldBe(" │ │ │ │ │ │ │ │");
|
||||||
|
console.Lines[10].ShouldBe(" └─────┴─────┴─────┴─────┴─────┴─────┴─────┘");
|
||||||
}
|
}
|
||||||
|
|
||||||
[Fact]
|
[Fact]
|
||||||
@@ -39,7 +127,7 @@ namespace Spectre.Console.Tests.Unit
|
|||||||
// Given
|
// Given
|
||||||
var console = new PlainConsole(width: 80);
|
var console = new PlainConsole(width: 80);
|
||||||
var calendar = new Calendar(2020, 10, 15)
|
var calendar = new Calendar(2020, 10, 15)
|
||||||
.SetCulture("de-DE")
|
.Culture("de-DE")
|
||||||
.AddCalendarEvent(new DateTime(2020, 9, 1))
|
.AddCalendarEvent(new DateTime(2020, 9, 1))
|
||||||
.AddCalendarEvent(new DateTime(2020, 10, 3))
|
.AddCalendarEvent(new DateTime(2020, 10, 3))
|
||||||
.AddCalendarEvent(new DateTime(2020, 10, 12));
|
.AddCalendarEvent(new DateTime(2020, 10, 12));
|
||||||
@@ -48,45 +136,18 @@ namespace Spectre.Console.Tests.Unit
|
|||||||
console.Render(calendar);
|
console.Render(calendar);
|
||||||
|
|
||||||
// Then
|
// Then
|
||||||
console.Lines.Count.ShouldBe(10);
|
console.Lines.Count.ShouldBe(11);
|
||||||
console.Lines[0].ShouldBe("┌─────┬────┬────┬────┬────┬────┬────┐");
|
console.Lines[00].ShouldBe(" Oktober 2020 ");
|
||||||
console.Lines[1].ShouldBe("│ Mo │ Di │ Mi │ Do │ Fr │ Sa │ So │");
|
console.Lines[01].ShouldBe("┌─────┬────┬────┬────┬────┬────┬────┐");
|
||||||
console.Lines[2].ShouldBe("├─────┼────┼────┼────┼────┼────┼────┤");
|
console.Lines[02].ShouldBe("│ Mo │ Di │ Mi │ Do │ Fr │ Sa │ So │");
|
||||||
console.Lines[3].ShouldBe("│ │ │ │ 1 │ 2 │ 3* │ 4 │");
|
console.Lines[03].ShouldBe("├─────┼────┼────┼────┼────┼────┼────┤");
|
||||||
console.Lines[4].ShouldBe("│ 5 │ 6 │ 7 │ 8 │ 9 │ 10 │ 11 │");
|
console.Lines[04].ShouldBe("│ │ │ │ 1 │ 2 │ 3* │ 4 │");
|
||||||
console.Lines[5].ShouldBe("│ 12* │ 13 │ 14 │ 15 │ 16 │ 17 │ 18 │");
|
console.Lines[05].ShouldBe("│ 5 │ 6 │ 7 │ 8 │ 9 │ 10 │ 11 │");
|
||||||
console.Lines[6].ShouldBe("│ 19 │ 20 │ 21 │ 22 │ 23 │ 24 │ 25 │");
|
console.Lines[06].ShouldBe("│ 12* │ 13 │ 14 │ 15 │ 16 │ 17 │ 18 │");
|
||||||
console.Lines[7].ShouldBe("│ 26 │ 27 │ 28 │ 29 │ 30 │ 31 │ │");
|
console.Lines[07].ShouldBe("│ 19 │ 20 │ 21 │ 22 │ 23 │ 24 │ 25 │");
|
||||||
console.Lines[8].ShouldBe("│ │ │ │ │ │ │ │");
|
console.Lines[08].ShouldBe("│ 26 │ 27 │ 28 │ 29 │ 30 │ 31 │ │");
|
||||||
console.Lines[9].ShouldBe("└─────┴────┴────┴────┴────┴────┴────┘");
|
console.Lines[09].ShouldBe("│ │ │ │ │ │ │ │");
|
||||||
}
|
console.Lines[10].ShouldBe("└─────┴────┴────┴────┴────┴────┴────┘");
|
||||||
|
|
||||||
[Fact]
|
|
||||||
public void Should_Render_List_Of_Events_If_Enabled()
|
|
||||||
{
|
|
||||||
// Given
|
|
||||||
var console = new PlainConsole(width: 80);
|
|
||||||
var calendar = new Calendar(2020, 10, 15)
|
|
||||||
.SetCulture("de-DE")
|
|
||||||
.AddCalendarEvent(new DateTime(2020, 9, 1))
|
|
||||||
.AddCalendarEvent(new DateTime(2020, 10, 3))
|
|
||||||
.AddCalendarEvent(new DateTime(2020, 10, 12));
|
|
||||||
|
|
||||||
// When
|
|
||||||
console.Render(calendar);
|
|
||||||
|
|
||||||
// Then
|
|
||||||
console.Lines.Count.ShouldBe(10);
|
|
||||||
console.Lines[0].ShouldBe("┌─────┬────┬────┬────┬────┬────┬────┐");
|
|
||||||
console.Lines[1].ShouldBe("│ Mo │ Di │ Mi │ Do │ Fr │ Sa │ So │");
|
|
||||||
console.Lines[2].ShouldBe("├─────┼────┼────┼────┼────┼────┼────┤");
|
|
||||||
console.Lines[3].ShouldBe("│ │ │ │ 1 │ 2 │ 3* │ 4 │");
|
|
||||||
console.Lines[4].ShouldBe("│ 5 │ 6 │ 7 │ 8 │ 9 │ 10 │ 11 │");
|
|
||||||
console.Lines[5].ShouldBe("│ 12* │ 13 │ 14 │ 15 │ 16 │ 17 │ 18 │");
|
|
||||||
console.Lines[6].ShouldBe("│ 19 │ 20 │ 21 │ 22 │ 23 │ 24 │ 25 │");
|
|
||||||
console.Lines[7].ShouldBe("│ 26 │ 27 │ 28 │ 29 │ 30 │ 31 │ │");
|
|
||||||
console.Lines[8].ShouldBe("│ │ │ │ │ │ │ │");
|
|
||||||
console.Lines[9].ShouldBe("└─────┴────┴────┴────┴────┴────┴────┘");
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -53,7 +53,7 @@ namespace Spectre.Console.Tests.Unit
|
|||||||
grid.AddRow("Foo");
|
grid.AddRow("Foo");
|
||||||
|
|
||||||
// Then
|
// Then
|
||||||
grid.RowCount.ShouldBe(1);
|
grid.Rows.Count.ShouldBe(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
[Fact]
|
[Fact]
|
||||||
|
|||||||
@@ -6,6 +6,24 @@ namespace Spectre.Console.Tests.Unit
|
|||||||
{
|
{
|
||||||
public sealed class MarkupTests
|
public sealed class MarkupTests
|
||||||
{
|
{
|
||||||
|
public sealed class TheEscapeMethod
|
||||||
|
{
|
||||||
|
[Theory]
|
||||||
|
[InlineData("Hello World", "Hello World")]
|
||||||
|
[InlineData("Hello World [", "Hello World [[")]
|
||||||
|
[InlineData("Hello World ]", "Hello World ]]")]
|
||||||
|
[InlineData("Hello [World]", "Hello [[World]]")]
|
||||||
|
[InlineData("Hello [[World]]", "Hello [[[[World]]]]")]
|
||||||
|
public void Should_Escape_Markup_As_Expected(string input, string expected)
|
||||||
|
{
|
||||||
|
// Given, When
|
||||||
|
var result = Markup.Escape(input);
|
||||||
|
|
||||||
|
// Then
|
||||||
|
result.ShouldBe(expected);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
[Theory]
|
[Theory]
|
||||||
[InlineData("Hello [[ World ]")]
|
[InlineData("Hello [[ World ]")]
|
||||||
[InlineData("Hello [[ World ] !")]
|
[InlineData("Hello [[ World ] !")]
|
||||||
|
|||||||
@@ -17,7 +17,7 @@ namespace Spectre.Console.Tests.Unit
|
|||||||
table.AddRow("Corgi", "Waldo");
|
table.AddRow("Corgi", "Waldo");
|
||||||
|
|
||||||
// When
|
// When
|
||||||
console.Render(new Padder(table).SetPadding(1, 2, 3, 4));
|
console.Render(new Padder(table).Padding(1, 2, 3, 4));
|
||||||
|
|
||||||
// Then
|
// Then
|
||||||
console.Lines.Count.ShouldBe(12);
|
console.Lines.Count.ShouldBe(12);
|
||||||
@@ -48,7 +48,7 @@ namespace Spectre.Console.Tests.Unit
|
|||||||
|
|
||||||
// When
|
// When
|
||||||
console.Render(new Padder(table)
|
console.Render(new Padder(table)
|
||||||
.SetPadding(1, 2, 3, 4)
|
.Padding(1, 2, 3, 4)
|
||||||
.Expand());
|
.Expand());
|
||||||
|
|
||||||
// Then
|
// Then
|
||||||
@@ -77,11 +77,11 @@ namespace Spectre.Console.Tests.Unit
|
|||||||
table.AddColumn("Bar", c => c.PadLeft(0).PadRight(0));
|
table.AddColumn("Bar", c => c.PadLeft(0).PadRight(0));
|
||||||
table.AddRow("Baz", "Qux");
|
table.AddRow("Baz", "Qux");
|
||||||
table.AddRow(new Text("Corgi"), new Padder(new Panel("Waldo"))
|
table.AddRow(new Text("Corgi"), new Padder(new Panel("Waldo"))
|
||||||
.SetPadding(2, 1, 2, 1));
|
.Padding(2, 1));
|
||||||
|
|
||||||
// When
|
// When
|
||||||
console.Render(new Padder(table)
|
console.Render(new Padder(table)
|
||||||
.SetPadding(1, 2, 3, 4)
|
.Padding(1, 2, 3, 4)
|
||||||
.Expand());
|
.Expand());
|
||||||
|
|
||||||
// Then
|
// Then
|
||||||
|
|||||||
@@ -244,7 +244,7 @@ namespace Spectre.Console.Tests.Unit
|
|||||||
}
|
}
|
||||||
|
|
||||||
[Fact]
|
[Fact]
|
||||||
public void Should_Justify_Child_To_Right()
|
public void Should_Justify_Child_To_Right_Correctly()
|
||||||
{
|
{
|
||||||
// Given
|
// Given
|
||||||
var console = new PlainConsole(width: 25);
|
var console = new PlainConsole(width: 25);
|
||||||
@@ -264,7 +264,7 @@ namespace Spectre.Console.Tests.Unit
|
|||||||
}
|
}
|
||||||
|
|
||||||
[Fact]
|
[Fact]
|
||||||
public void Should_Justify_Child_To_Center()
|
public void Should_Center_Child_Correctly()
|
||||||
{
|
{
|
||||||
// Given
|
// Given
|
||||||
var console = new PlainConsole(width: 25);
|
var console = new PlainConsole(width: 25);
|
||||||
@@ -315,15 +315,15 @@ namespace Spectre.Console.Tests.Unit
|
|||||||
|
|
||||||
var panel = new Panel(grid)
|
var panel = new Panel(grid)
|
||||||
.Expand().RoundedBorder()
|
.Expand().RoundedBorder()
|
||||||
.SetBorderStyle(Style.WithForeground(Color.Grey))
|
.BorderStyle(new Style().Foreground(Color.Grey))
|
||||||
.SetHeader("Short paths ", Style.WithForeground(Color.Grey));
|
.Header("[grey]Short paths[/]");
|
||||||
|
|
||||||
// When
|
// When
|
||||||
console.Render(panel);
|
console.Render(panel);
|
||||||
|
|
||||||
// Then
|
// Then
|
||||||
console.Lines.Count.ShouldBe(4);
|
console.Lines.Count.ShouldBe(4);
|
||||||
console.Lines[0].ShouldBe("╭─Short paths ─────────────────────────────────────────────────────────────────────╮");
|
console.Lines[0].ShouldBe("╭─Short paths──────────────────────────────────────────────────────────────────────╮");
|
||||||
console.Lines[1].ShouldBe("│ at System.Runtime.CompilerServices.TaskAwaiter. │");
|
console.Lines[1].ShouldBe("│ at System.Runtime.CompilerServices.TaskAwaiter. │");
|
||||||
console.Lines[2].ShouldBe("│ HandleNonSuccessAndDebuggerNotification(Task task) │");
|
console.Lines[2].ShouldBe("│ HandleNonSuccessAndDebuggerNotification(Task task) │");
|
||||||
console.Lines[3].ShouldBe("╰──────────────────────────────────────────────────────────────────────────────────╯");
|
console.Lines[3].ShouldBe("╰──────────────────────────────────────────────────────────────────────────────────╯");
|
||||||
|
|||||||
126
src/Spectre.Console.Tests/Unit/PromptTests.cs
Normal file
126
src/Spectre.Console.Tests/Unit/PromptTests.cs
Normal file
@@ -0,0 +1,126 @@
|
|||||||
|
using System;
|
||||||
|
using Shouldly;
|
||||||
|
using Xunit;
|
||||||
|
|
||||||
|
namespace Spectre.Console.Tests.Unit
|
||||||
|
{
|
||||||
|
public sealed class PromptTests
|
||||||
|
{
|
||||||
|
[Fact]
|
||||||
|
public void Should_Return_Validation_Error_If_Value_Cannot_Be_Converted()
|
||||||
|
{
|
||||||
|
// Given
|
||||||
|
var console = new PlainConsole();
|
||||||
|
console.Input.PushText("ninety-nine");
|
||||||
|
console.Input.PushText("99");
|
||||||
|
|
||||||
|
// When
|
||||||
|
console.Prompt(new TextPrompt<int>("Age?"));
|
||||||
|
|
||||||
|
// Then
|
||||||
|
console.Lines.Count.ShouldBe(3);
|
||||||
|
console.Lines[0].ShouldBe("Age? ninety-nine");
|
||||||
|
console.Lines[1].ShouldBe("Invalid input");
|
||||||
|
console.Lines[2].ShouldBe("Age? 99");
|
||||||
|
}
|
||||||
|
|
||||||
|
[Fact]
|
||||||
|
public void Should_Chose_Default_Value_If_Nothing_Is_Entered()
|
||||||
|
{
|
||||||
|
// Given
|
||||||
|
var console = new PlainConsole();
|
||||||
|
console.Input.PushKey(ConsoleKey.Enter);
|
||||||
|
|
||||||
|
// When
|
||||||
|
console.Prompt(
|
||||||
|
new TextPrompt<string>("Favorite fruit?")
|
||||||
|
.AddChoice("Banana")
|
||||||
|
.AddChoice("Orange")
|
||||||
|
.DefaultValue("Banana"));
|
||||||
|
|
||||||
|
// Then
|
||||||
|
console.Lines.Count.ShouldBe(1);
|
||||||
|
console.Lines[0].ShouldBe("Favorite fruit? [Banana/Orange] (Banana): Banana");
|
||||||
|
}
|
||||||
|
|
||||||
|
[Fact]
|
||||||
|
public void Should_Return_Error_If_An_Invalid_Choice_Is_Made()
|
||||||
|
{
|
||||||
|
// Given
|
||||||
|
var console = new PlainConsole();
|
||||||
|
console.Input.PushText("Apple");
|
||||||
|
console.Input.PushText("Banana");
|
||||||
|
|
||||||
|
// When
|
||||||
|
console.Prompt(
|
||||||
|
new TextPrompt<string>("Favorite fruit?")
|
||||||
|
.AddChoice("Banana")
|
||||||
|
.AddChoice("Orange")
|
||||||
|
.DefaultValue("Banana"));
|
||||||
|
|
||||||
|
// Then
|
||||||
|
console.Lines.Count.ShouldBe(3);
|
||||||
|
console.Lines[0].ShouldBe("Favorite fruit? [Banana/Orange] (Banana): Apple");
|
||||||
|
console.Lines[1].ShouldBe("Please select one of the available options");
|
||||||
|
console.Lines[2].ShouldBe("Favorite fruit? [Banana/Orange] (Banana): Banana");
|
||||||
|
}
|
||||||
|
|
||||||
|
[Fact]
|
||||||
|
public void Should_Accept_Choice_In_List()
|
||||||
|
{
|
||||||
|
// Given
|
||||||
|
var console = new PlainConsole();
|
||||||
|
console.Input.PushText("Orange");
|
||||||
|
|
||||||
|
// When
|
||||||
|
console.Prompt(
|
||||||
|
new TextPrompt<string>("Favorite fruit?")
|
||||||
|
.AddChoice("Banana")
|
||||||
|
.AddChoice("Orange")
|
||||||
|
.DefaultValue("Banana"));
|
||||||
|
|
||||||
|
// Then
|
||||||
|
console.Lines.Count.ShouldBe(1);
|
||||||
|
console.Lines[0].ShouldBe("Favorite fruit? [Banana/Orange] (Banana): Orange");
|
||||||
|
}
|
||||||
|
|
||||||
|
[Fact]
|
||||||
|
public void Should_Return_Error_If_Custom_Validation_Fails()
|
||||||
|
{
|
||||||
|
// Given
|
||||||
|
var console = new PlainConsole();
|
||||||
|
console.Input.PushText("22");
|
||||||
|
console.Input.PushText("102");
|
||||||
|
console.Input.PushText("ABC");
|
||||||
|
console.Input.PushText("99");
|
||||||
|
|
||||||
|
// When
|
||||||
|
console.Prompt(
|
||||||
|
new TextPrompt<int>("Guess number:")
|
||||||
|
.ValidationErrorMessage("Invalid input")
|
||||||
|
.Validate(age =>
|
||||||
|
{
|
||||||
|
if (age < 99)
|
||||||
|
{
|
||||||
|
return ValidationResult.Error("Too low");
|
||||||
|
}
|
||||||
|
else if (age > 99)
|
||||||
|
{
|
||||||
|
return ValidationResult.Error("Too high");
|
||||||
|
}
|
||||||
|
|
||||||
|
return ValidationResult.Success();
|
||||||
|
}));
|
||||||
|
|
||||||
|
// Then
|
||||||
|
console.Lines.Count.ShouldBe(7);
|
||||||
|
console.Lines[0].ShouldBe("Guess number: 22");
|
||||||
|
console.Lines[1].ShouldBe("Too low");
|
||||||
|
console.Lines[2].ShouldBe("Guess number: 102");
|
||||||
|
console.Lines[3].ShouldBe("Too high");
|
||||||
|
console.Lines[4].ShouldBe("Guess number: ABC");
|
||||||
|
console.Lines[5].ShouldBe("Invalid input");
|
||||||
|
console.Lines[6].ShouldBe("Guess number: 99");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -43,7 +43,7 @@ namespace Spectre.Console.Tests.Unit
|
|||||||
.AddColumns("[red on black]Foo[/]", "[green bold]Bar[/]", "[blue italic]Qux[/]")
|
.AddColumns("[red on black]Foo[/]", "[green bold]Bar[/]", "[blue italic]Qux[/]")
|
||||||
.AddRow("[invert underline]Corgi[/]", "[bold strikethrough]Waldo[/]", "[dim]Zap[/]")
|
.AddRow("[invert underline]Corgi[/]", "[bold strikethrough]Waldo[/]", "[dim]Zap[/]")
|
||||||
.AddRow(new Panel("[blue]Hello World[/]")
|
.AddRow(new Panel("[blue]Hello World[/]")
|
||||||
.SetBorderColor(Color.Red).RoundedBorder()));
|
.BorderColor(Color.Red).RoundedBorder()));
|
||||||
|
|
||||||
// When
|
// When
|
||||||
var html = recorder.ExportHtml();
|
var html = recorder.ExportHtml();
|
||||||
|
|||||||
153
src/Spectre.Console.Tests/Unit/RuleTests.cs
Normal file
153
src/Spectre.Console.Tests/Unit/RuleTests.cs
Normal file
@@ -0,0 +1,153 @@
|
|||||||
|
using Shouldly;
|
||||||
|
using Xunit;
|
||||||
|
|
||||||
|
namespace Spectre.Console.Tests.Unit
|
||||||
|
{
|
||||||
|
public sealed class RuleTests
|
||||||
|
{
|
||||||
|
[Fact]
|
||||||
|
public void Should_Render_Default_Rule_Without_Title()
|
||||||
|
{
|
||||||
|
// Given
|
||||||
|
var console = new PlainConsole(width: 40);
|
||||||
|
|
||||||
|
// When
|
||||||
|
console.Render(new Rule());
|
||||||
|
|
||||||
|
// Then
|
||||||
|
console.Lines.Count.ShouldBe(1);
|
||||||
|
console.Lines[0].ShouldBe("────────────────────────────────────────");
|
||||||
|
}
|
||||||
|
|
||||||
|
[Fact]
|
||||||
|
public void Should_Render_Default_Rule_With_Specified_Box()
|
||||||
|
{
|
||||||
|
// Given
|
||||||
|
var console = new PlainConsole(width: 40);
|
||||||
|
|
||||||
|
// When
|
||||||
|
console.Render(new Rule().DoubleBorder());
|
||||||
|
|
||||||
|
// Then
|
||||||
|
console.Lines.Count.ShouldBe(1);
|
||||||
|
console.Lines[0].ShouldBe("════════════════════════════════════════");
|
||||||
|
}
|
||||||
|
|
||||||
|
[Fact]
|
||||||
|
public void Should_Render_With_Specified_Box()
|
||||||
|
{
|
||||||
|
// Given
|
||||||
|
var console = new PlainConsole(width: 40);
|
||||||
|
|
||||||
|
// When
|
||||||
|
console.Render(new Rule("Hello World").DoubleBorder());
|
||||||
|
|
||||||
|
// Then
|
||||||
|
console.Lines.Count.ShouldBe(1);
|
||||||
|
console.Lines[0].ShouldBe("═════════════ Hello World ══════════════");
|
||||||
|
}
|
||||||
|
|
||||||
|
[Fact]
|
||||||
|
public void Should_Render_Default_Rule_With_Title_Centered_By_Default()
|
||||||
|
{
|
||||||
|
// Given
|
||||||
|
var console = new PlainConsole(width: 40);
|
||||||
|
|
||||||
|
// When
|
||||||
|
console.Render(new Rule("Hello World"));
|
||||||
|
|
||||||
|
// Then
|
||||||
|
console.Lines.Count.ShouldBe(1);
|
||||||
|
console.Lines[0].ShouldBe("───────────── Hello World ──────────────");
|
||||||
|
}
|
||||||
|
|
||||||
|
[Fact]
|
||||||
|
public void Should_Render_Default_Rule_With_Title_Left_Aligned()
|
||||||
|
{
|
||||||
|
// Given
|
||||||
|
var console = new PlainConsole(width: 40);
|
||||||
|
|
||||||
|
// When
|
||||||
|
console.Render(new Rule("Hello World")
|
||||||
|
{
|
||||||
|
Alignment = Justify.Left,
|
||||||
|
});
|
||||||
|
|
||||||
|
// Then
|
||||||
|
console.Lines.Count.ShouldBe(1);
|
||||||
|
console.Lines[0].ShouldBe("── Hello World ─────────────────────────");
|
||||||
|
}
|
||||||
|
|
||||||
|
[Fact]
|
||||||
|
public void Should_Render_Default_Rule_With_Title_Right_Aligned()
|
||||||
|
{
|
||||||
|
// Given
|
||||||
|
var console = new PlainConsole(width: 40);
|
||||||
|
|
||||||
|
// When
|
||||||
|
console.Render(new Rule("Hello World")
|
||||||
|
{
|
||||||
|
Alignment = Justify.Right,
|
||||||
|
});
|
||||||
|
|
||||||
|
// Then
|
||||||
|
console.Lines.Count.ShouldBe(1);
|
||||||
|
console.Lines[0].ShouldBe("───────────────────────── Hello World ──");
|
||||||
|
}
|
||||||
|
|
||||||
|
[Fact]
|
||||||
|
public void Should_Convert_Line_Breaks_In_Title_To_Spaces()
|
||||||
|
{
|
||||||
|
// Given
|
||||||
|
var console = new PlainConsole(width: 40);
|
||||||
|
|
||||||
|
// When
|
||||||
|
console.Render(new Rule("Hello\nWorld\r\n!"));
|
||||||
|
|
||||||
|
// Then
|
||||||
|
console.Lines.Count.ShouldBe(1);
|
||||||
|
console.Lines[0].ShouldBe("──────────── Hello World ! ─────────────");
|
||||||
|
}
|
||||||
|
|
||||||
|
[Fact]
|
||||||
|
public void Should_Truncate_Title()
|
||||||
|
{
|
||||||
|
// Given
|
||||||
|
var console = new PlainConsole(width: 40);
|
||||||
|
|
||||||
|
// When
|
||||||
|
console.Render(new Rule(" Hello World "));
|
||||||
|
|
||||||
|
// Then
|
||||||
|
console.Lines.Count.ShouldBe(1);
|
||||||
|
console.Lines[0].ShouldBe("───────────── Hello World ──────────────");
|
||||||
|
}
|
||||||
|
|
||||||
|
[Theory]
|
||||||
|
[InlineData(0, "Hello World Hello World Hello World Hello World Hello World", "")]
|
||||||
|
[InlineData(1, "Hello World Hello World Hello World Hello World Hello World", "─")]
|
||||||
|
[InlineData(2, "Hello World Hello World Hello World Hello World Hello World", "──")]
|
||||||
|
[InlineData(3, "Hello World Hello World Hello World Hello World Hello World", "───")]
|
||||||
|
[InlineData(4, "Hello World Hello World Hello World Hello World Hello World", "────")]
|
||||||
|
[InlineData(5, "Hello World Hello World Hello World Hello World Hello World", "─────")]
|
||||||
|
[InlineData(6, "Hello World Hello World Hello World Hello World Hello World", "──────")]
|
||||||
|
[InlineData(7, "Hello World Hello World Hello World Hello World Hello World", "───────")]
|
||||||
|
[InlineData(8, "Hello World Hello World Hello World Hello World Hello World", "── H… ──")]
|
||||||
|
[InlineData(8, "A", "── A ───")]
|
||||||
|
[InlineData(8, "AB", "── AB ──")]
|
||||||
|
[InlineData(8, "ABC", "── A… ──")]
|
||||||
|
[InlineData(40, "Hello World Hello World Hello World Hello World Hello World", "──── Hello World Hello World Hello… ────")]
|
||||||
|
public void Should_Truncate_Too_Long_Title(int width, string input, string expected)
|
||||||
|
{
|
||||||
|
// Given
|
||||||
|
var console = new PlainConsole(width);
|
||||||
|
|
||||||
|
// When
|
||||||
|
console.Render(new Rule(input));
|
||||||
|
|
||||||
|
// Then
|
||||||
|
console.Lines.Count.ShouldBe(1);
|
||||||
|
console.Lines[0].ShouldBe(expected);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,3 +1,4 @@
|
|||||||
|
using System.Text;
|
||||||
using Shouldly;
|
using Shouldly;
|
||||||
using Spectre.Console.Rendering;
|
using Spectre.Console.Rendering;
|
||||||
using Xunit;
|
using Xunit;
|
||||||
@@ -6,6 +7,16 @@ namespace Spectre.Console.Tests.Unit
|
|||||||
{
|
{
|
||||||
public sealed class SegmentTests
|
public sealed class SegmentTests
|
||||||
{
|
{
|
||||||
|
[Fact]
|
||||||
|
public void Lol()
|
||||||
|
{
|
||||||
|
var context = new RenderContext(Encoding.UTF8, false);
|
||||||
|
|
||||||
|
var result = new Segment(" ").CellCount(context);
|
||||||
|
|
||||||
|
result.ShouldBe(4);
|
||||||
|
}
|
||||||
|
|
||||||
public sealed class TheSplitMethod
|
public sealed class TheSplitMethod
|
||||||
{
|
{
|
||||||
[Fact]
|
[Fact]
|
||||||
@@ -31,7 +42,10 @@ namespace Spectre.Console.Tests.Unit
|
|||||||
[Fact]
|
[Fact]
|
||||||
public void Should_Split_Segment()
|
public void Should_Split_Segment()
|
||||||
{
|
{
|
||||||
|
var context = new RenderContext(Encoding.UTF8, false);
|
||||||
|
|
||||||
var lines = Segment.SplitLines(
|
var lines = Segment.SplitLines(
|
||||||
|
context,
|
||||||
new[]
|
new[]
|
||||||
{
|
{
|
||||||
new Segment("Foo"),
|
new Segment("Foo"),
|
||||||
@@ -61,7 +75,9 @@ namespace Spectre.Console.Tests.Unit
|
|||||||
[Fact]
|
[Fact]
|
||||||
public void Should_Split_Segments_With_Linebreak_In_Text()
|
public void Should_Split_Segments_With_Linebreak_In_Text()
|
||||||
{
|
{
|
||||||
|
var context = new RenderContext(Encoding.UTF8, false);
|
||||||
var lines = Segment.SplitLines(
|
var lines = Segment.SplitLines(
|
||||||
|
context,
|
||||||
new[]
|
new[]
|
||||||
{
|
{
|
||||||
new Segment("Foo\n"),
|
new Segment("Foo\n"),
|
||||||
|
|||||||
@@ -42,10 +42,11 @@ namespace Spectre.Console.Tests.Unit
|
|||||||
console.Render(table);
|
console.Render(table);
|
||||||
|
|
||||||
// Then
|
// Then
|
||||||
console.Lines.Count.ShouldBe(3);
|
console.Lines.Count.ShouldBe(4);
|
||||||
console.Lines[0].ShouldBe("Header 1 Header 2");
|
console.Lines[0].ShouldBe("Header 1 Header 2");
|
||||||
console.Lines[1].ShouldBe("Cell Cell ");
|
console.Lines[1].ShouldBe("Cell Cell ");
|
||||||
console.Lines[2].ShouldBe("Cell Cell ");
|
console.Lines[2].ShouldBe("Cell Cell ");
|
||||||
|
console.Lines[3].ShouldBe("Footer 1 Footer 2");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -85,13 +86,15 @@ namespace Spectre.Console.Tests.Unit
|
|||||||
console.Render(table);
|
console.Render(table);
|
||||||
|
|
||||||
// Then
|
// Then
|
||||||
console.Lines.Count.ShouldBe(6);
|
console.Lines.Count.ShouldBe(8);
|
||||||
console.Lines[0].ShouldBe("+---------------------+");
|
console.Lines[0].ShouldBe("+---------------------+");
|
||||||
console.Lines[1].ShouldBe("| Header 1 | Header 2 |");
|
console.Lines[1].ShouldBe("| Header 1 | Header 2 |");
|
||||||
console.Lines[2].ShouldBe("|----------+----------|");
|
console.Lines[2].ShouldBe("|----------+----------|");
|
||||||
console.Lines[3].ShouldBe("| Cell | Cell |");
|
console.Lines[3].ShouldBe("| Cell | Cell |");
|
||||||
console.Lines[4].ShouldBe("| Cell | Cell |");
|
console.Lines[4].ShouldBe("| Cell | Cell |");
|
||||||
console.Lines[5].ShouldBe("+---------------------+");
|
console.Lines[5].ShouldBe("|----------+----------|");
|
||||||
|
console.Lines[6].ShouldBe("| Footer 1 | Footer 2 |");
|
||||||
|
console.Lines[7].ShouldBe("+---------------------+");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -131,13 +134,15 @@ namespace Spectre.Console.Tests.Unit
|
|||||||
console.Render(table);
|
console.Render(table);
|
||||||
|
|
||||||
// Then
|
// Then
|
||||||
console.Lines.Count.ShouldBe(6);
|
console.Lines.Count.ShouldBe(8);
|
||||||
console.Lines[0].ShouldBe("+----------+----------+");
|
console.Lines[0].ShouldBe("+----------+----------+");
|
||||||
console.Lines[1].ShouldBe("| Header 1 | Header 2 |");
|
console.Lines[1].ShouldBe("| Header 1 | Header 2 |");
|
||||||
console.Lines[2].ShouldBe("|----------+----------|");
|
console.Lines[2].ShouldBe("|----------+----------|");
|
||||||
console.Lines[3].ShouldBe("| Cell | Cell |");
|
console.Lines[3].ShouldBe("| Cell | Cell |");
|
||||||
console.Lines[4].ShouldBe("| Cell | Cell |");
|
console.Lines[4].ShouldBe("| Cell | Cell |");
|
||||||
console.Lines[5].ShouldBe("+----------+----------+");
|
console.Lines[5].ShouldBe("|----------+----------|");
|
||||||
|
console.Lines[6].ShouldBe("| Footer 1 | Footer 2 |");
|
||||||
|
console.Lines[7].ShouldBe("+----------+----------+");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -177,13 +182,15 @@ namespace Spectre.Console.Tests.Unit
|
|||||||
console.Render(table);
|
console.Render(table);
|
||||||
|
|
||||||
// Then
|
// Then
|
||||||
console.Lines.Count.ShouldBe(6);
|
console.Lines.Count.ShouldBe(8);
|
||||||
console.Lines[0].ShouldBe("+----------+----------+");
|
console.Lines[0].ShouldBe("+----------+----------+");
|
||||||
console.Lines[1].ShouldBe("| Header 1 | Header 2 |");
|
console.Lines[1].ShouldBe("| Header 1 | Header 2 |");
|
||||||
console.Lines[2].ShouldBe("|==========+==========|");
|
console.Lines[2].ShouldBe("|==========+==========|");
|
||||||
console.Lines[3].ShouldBe("| Cell | Cell |");
|
console.Lines[3].ShouldBe("| Cell | Cell |");
|
||||||
console.Lines[4].ShouldBe("| Cell | Cell |");
|
console.Lines[4].ShouldBe("| Cell | Cell |");
|
||||||
console.Lines[5].ShouldBe("+----------+----------+");
|
console.Lines[5].ShouldBe("+----------+----------+");
|
||||||
|
console.Lines[6].ShouldBe("| Footer 1 | Footer 2 |");
|
||||||
|
console.Lines[7].ShouldBe("+----------+----------+");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -223,13 +230,15 @@ namespace Spectre.Console.Tests.Unit
|
|||||||
console.Render(table);
|
console.Render(table);
|
||||||
|
|
||||||
// Then
|
// Then
|
||||||
console.Lines.Count.ShouldBe(6);
|
console.Lines.Count.ShouldBe(8);
|
||||||
console.Lines[0].ShouldBe("┌──────────┬──────────┐");
|
console.Lines[0].ShouldBe("┌──────────┬──────────┐");
|
||||||
console.Lines[1].ShouldBe("│ Header 1 │ Header 2 │");
|
console.Lines[1].ShouldBe("│ Header 1 │ Header 2 │");
|
||||||
console.Lines[2].ShouldBe("├──────────┼──────────┤");
|
console.Lines[2].ShouldBe("├──────────┼──────────┤");
|
||||||
console.Lines[3].ShouldBe("│ Cell │ Cell │");
|
console.Lines[3].ShouldBe("│ Cell │ Cell │");
|
||||||
console.Lines[4].ShouldBe("│ Cell │ Cell │");
|
console.Lines[4].ShouldBe("│ Cell │ Cell │");
|
||||||
console.Lines[5].ShouldBe("└──────────┴──────────┘");
|
console.Lines[5].ShouldBe("├──────────┼──────────┤");
|
||||||
|
console.Lines[6].ShouldBe("│ Footer 1 │ Footer 2 │");
|
||||||
|
console.Lines[7].ShouldBe("└──────────┴──────────┘");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -269,13 +278,15 @@ namespace Spectre.Console.Tests.Unit
|
|||||||
console.Render(table);
|
console.Render(table);
|
||||||
|
|
||||||
// Then
|
// Then
|
||||||
console.Lines.Count.ShouldBe(6);
|
console.Lines.Count.ShouldBe(8);
|
||||||
console.Lines[0].ShouldBe("╭──────────┬──────────╮");
|
console.Lines[0].ShouldBe("╭──────────┬──────────╮");
|
||||||
console.Lines[1].ShouldBe("│ Header 1 │ Header 2 │");
|
console.Lines[1].ShouldBe("│ Header 1 │ Header 2 │");
|
||||||
console.Lines[2].ShouldBe("├──────────┼──────────┤");
|
console.Lines[2].ShouldBe("├──────────┼──────────┤");
|
||||||
console.Lines[3].ShouldBe("│ Cell │ Cell │");
|
console.Lines[3].ShouldBe("│ Cell │ Cell │");
|
||||||
console.Lines[4].ShouldBe("│ Cell │ Cell │");
|
console.Lines[4].ShouldBe("│ Cell │ Cell │");
|
||||||
console.Lines[5].ShouldBe("╰──────────┴──────────╯");
|
console.Lines[5].ShouldBe("├──────────┼──────────┤");
|
||||||
|
console.Lines[6].ShouldBe("│ Footer 1 │ Footer 2 │");
|
||||||
|
console.Lines[7].ShouldBe("╰──────────┴──────────╯");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -315,13 +326,15 @@ namespace Spectre.Console.Tests.Unit
|
|||||||
console.Render(table);
|
console.Render(table);
|
||||||
|
|
||||||
// Then
|
// Then
|
||||||
console.Lines.Count.ShouldBe(6);
|
console.Lines.Count.ShouldBe(8);
|
||||||
console.Lines[0].ShouldBe(" ");
|
console.Lines[0].ShouldBe(" ");
|
||||||
console.Lines[1].ShouldBe(" Header 1 │ Header 2 ");
|
console.Lines[1].ShouldBe(" Header 1 │ Header 2 ");
|
||||||
console.Lines[2].ShouldBe(" ──────────┼────────── ");
|
console.Lines[2].ShouldBe(" ──────────┼────────── ");
|
||||||
console.Lines[3].ShouldBe(" Cell │ Cell ");
|
console.Lines[3].ShouldBe(" Cell │ Cell ");
|
||||||
console.Lines[4].ShouldBe(" Cell │ Cell ");
|
console.Lines[4].ShouldBe(" Cell │ Cell ");
|
||||||
console.Lines[5].ShouldBe(" ");
|
console.Lines[5].ShouldBe(" ──────────┼────────── ");
|
||||||
|
console.Lines[6].ShouldBe(" Footer 1 │ Footer 2 ");
|
||||||
|
console.Lines[7].ShouldBe(" ");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -361,13 +374,15 @@ namespace Spectre.Console.Tests.Unit
|
|||||||
console.Render(table);
|
console.Render(table);
|
||||||
|
|
||||||
// Then
|
// Then
|
||||||
console.Lines.Count.ShouldBe(6);
|
console.Lines.Count.ShouldBe(8);
|
||||||
console.Lines[0].ShouldBe(" ");
|
console.Lines[0].ShouldBe(" ");
|
||||||
console.Lines[1].ShouldBe(" Header 1 │ Header 2 ");
|
console.Lines[1].ShouldBe(" Header 1 │ Header 2 ");
|
||||||
console.Lines[2].ShouldBe(" ━━━━━━━━━━┿━━━━━━━━━━ ");
|
console.Lines[2].ShouldBe(" ━━━━━━━━━━┿━━━━━━━━━━ ");
|
||||||
console.Lines[3].ShouldBe(" Cell │ Cell ");
|
console.Lines[3].ShouldBe(" Cell │ Cell ");
|
||||||
console.Lines[4].ShouldBe(" Cell │ Cell ");
|
console.Lines[4].ShouldBe(" Cell │ Cell ");
|
||||||
console.Lines[5].ShouldBe(" ");
|
console.Lines[5].ShouldBe(" ━━━━━━━━━━┿━━━━━━━━━━ ");
|
||||||
|
console.Lines[6].ShouldBe(" Footer 1 │ Footer 2 ");
|
||||||
|
console.Lines[7].ShouldBe(" ");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -407,13 +422,15 @@ namespace Spectre.Console.Tests.Unit
|
|||||||
console.Render(table);
|
console.Render(table);
|
||||||
|
|
||||||
// Then
|
// Then
|
||||||
console.Lines.Count.ShouldBe(6);
|
console.Lines.Count.ShouldBe(8);
|
||||||
console.Lines[0].ShouldBe(" ");
|
console.Lines[0].ShouldBe(" ");
|
||||||
console.Lines[1].ShouldBe(" Header 1 │ Header 2 ");
|
console.Lines[1].ShouldBe(" Header 1 │ Header 2 ");
|
||||||
console.Lines[2].ShouldBe(" ══════════╪══════════ ");
|
console.Lines[2].ShouldBe(" ══════════╪══════════ ");
|
||||||
console.Lines[3].ShouldBe(" Cell │ Cell ");
|
console.Lines[3].ShouldBe(" Cell │ Cell ");
|
||||||
console.Lines[4].ShouldBe(" Cell │ Cell ");
|
console.Lines[4].ShouldBe(" Cell │ Cell ");
|
||||||
console.Lines[5].ShouldBe(" ");
|
console.Lines[5].ShouldBe(" ══════════╪══════════ ");
|
||||||
|
console.Lines[6].ShouldBe(" Footer 1 │ Footer 2 ");
|
||||||
|
console.Lines[7].ShouldBe(" ");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -453,13 +470,15 @@ namespace Spectre.Console.Tests.Unit
|
|||||||
console.Render(table);
|
console.Render(table);
|
||||||
|
|
||||||
// Then
|
// Then
|
||||||
console.Lines.Count.ShouldBe(6);
|
console.Lines.Count.ShouldBe(8);
|
||||||
console.Lines[0].ShouldBe(" ");
|
console.Lines[0].ShouldBe(" ");
|
||||||
console.Lines[1].ShouldBe(" Header 1 Header 2 ");
|
console.Lines[1].ShouldBe(" Header 1 Header 2 ");
|
||||||
console.Lines[2].ShouldBe("───────────────────────");
|
console.Lines[2].ShouldBe("───────────────────────");
|
||||||
console.Lines[3].ShouldBe(" Cell Cell ");
|
console.Lines[3].ShouldBe(" Cell Cell ");
|
||||||
console.Lines[4].ShouldBe(" Cell Cell ");
|
console.Lines[4].ShouldBe(" Cell Cell ");
|
||||||
console.Lines[5].ShouldBe(" ");
|
console.Lines[5].ShouldBe("───────────────────────");
|
||||||
|
console.Lines[6].ShouldBe(" Footer 1 Footer 2 ");
|
||||||
|
console.Lines[7].ShouldBe(" ");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -499,13 +518,15 @@ namespace Spectre.Console.Tests.Unit
|
|||||||
console.Render(table);
|
console.Render(table);
|
||||||
|
|
||||||
// Then
|
// Then
|
||||||
console.Lines.Count.ShouldBe(6);
|
console.Lines.Count.ShouldBe(8);
|
||||||
console.Lines[0].ShouldBe("───────────────────────");
|
console.Lines[0].ShouldBe("───────────────────────");
|
||||||
console.Lines[1].ShouldBe(" Header 1 Header 2 ");
|
console.Lines[1].ShouldBe(" Header 1 Header 2 ");
|
||||||
console.Lines[2].ShouldBe("───────────────────────");
|
console.Lines[2].ShouldBe("───────────────────────");
|
||||||
console.Lines[3].ShouldBe(" Cell Cell ");
|
console.Lines[3].ShouldBe(" Cell Cell ");
|
||||||
console.Lines[4].ShouldBe(" Cell Cell ");
|
console.Lines[4].ShouldBe(" Cell Cell ");
|
||||||
console.Lines[5].ShouldBe("───────────────────────");
|
console.Lines[5].ShouldBe("───────────────────────");
|
||||||
|
console.Lines[6].ShouldBe(" Footer 1 Footer 2 ");
|
||||||
|
console.Lines[7].ShouldBe("───────────────────────");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -545,13 +566,15 @@ namespace Spectre.Console.Tests.Unit
|
|||||||
console.Render(table);
|
console.Render(table);
|
||||||
|
|
||||||
// Then
|
// Then
|
||||||
console.Lines.Count.ShouldBe(6);
|
console.Lines.Count.ShouldBe(8);
|
||||||
console.Lines[0].ShouldBe(" ");
|
console.Lines[0].ShouldBe(" ");
|
||||||
console.Lines[1].ShouldBe(" Header 1 Header 2 ");
|
console.Lines[1].ShouldBe(" Header 1 Header 2 ");
|
||||||
console.Lines[2].ShouldBe("━━━━━━━━━━━━━━━━━━━━━━━");
|
console.Lines[2].ShouldBe("━━━━━━━━━━━━━━━━━━━━━━━");
|
||||||
console.Lines[3].ShouldBe(" Cell Cell ");
|
console.Lines[3].ShouldBe(" Cell Cell ");
|
||||||
console.Lines[4].ShouldBe(" Cell Cell ");
|
console.Lines[4].ShouldBe(" Cell Cell ");
|
||||||
console.Lines[5].ShouldBe(" ");
|
console.Lines[5].ShouldBe("━━━━━━━━━━━━━━━━━━━━━━━");
|
||||||
|
console.Lines[6].ShouldBe(" Footer 1 Footer 2 ");
|
||||||
|
console.Lines[7].ShouldBe(" ");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -591,13 +614,15 @@ namespace Spectre.Console.Tests.Unit
|
|||||||
console.Render(table);
|
console.Render(table);
|
||||||
|
|
||||||
// Then
|
// Then
|
||||||
console.Lines.Count.ShouldBe(6);
|
console.Lines.Count.ShouldBe(8);
|
||||||
console.Lines[0].ShouldBe("┏━━━━━━━━━━┳━━━━━━━━━━┓");
|
console.Lines[0].ShouldBe("┏━━━━━━━━━━┳━━━━━━━━━━┓");
|
||||||
console.Lines[1].ShouldBe("┃ Header 1 ┃ Header 2 ┃");
|
console.Lines[1].ShouldBe("┃ Header 1 ┃ Header 2 ┃");
|
||||||
console.Lines[2].ShouldBe("┣━━━━━━━━━━╋━━━━━━━━━━┫");
|
console.Lines[2].ShouldBe("┣━━━━━━━━━━╋━━━━━━━━━━┫");
|
||||||
console.Lines[3].ShouldBe("┃ Cell ┃ Cell ┃");
|
console.Lines[3].ShouldBe("┃ Cell ┃ Cell ┃");
|
||||||
console.Lines[4].ShouldBe("┃ Cell ┃ Cell ┃");
|
console.Lines[4].ShouldBe("┃ Cell ┃ Cell ┃");
|
||||||
console.Lines[5].ShouldBe("┗━━━━━━━━━━┻━━━━━━━━━━┛");
|
console.Lines[5].ShouldBe("┣━━━━━━━━━━╋━━━━━━━━━━┫");
|
||||||
|
console.Lines[6].ShouldBe("┃ Footer 1 ┃ Footer 2 ┃");
|
||||||
|
console.Lines[7].ShouldBe("┗━━━━━━━━━━┻━━━━━━━━━━┛");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -637,13 +662,15 @@ namespace Spectre.Console.Tests.Unit
|
|||||||
console.Render(table);
|
console.Render(table);
|
||||||
|
|
||||||
// Then
|
// Then
|
||||||
console.Lines.Count.ShouldBe(6);
|
console.Lines.Count.ShouldBe(8);
|
||||||
console.Lines[0].ShouldBe("┏━━━━━━━━━━┯━━━━━━━━━━┓");
|
console.Lines[0].ShouldBe("┏━━━━━━━━━━┯━━━━━━━━━━┓");
|
||||||
console.Lines[1].ShouldBe("┃ Header 1 │ Header 2 ┃");
|
console.Lines[1].ShouldBe("┃ Header 1 │ Header 2 ┃");
|
||||||
console.Lines[2].ShouldBe("┠──────────┼──────────┨");
|
console.Lines[2].ShouldBe("┠──────────┼──────────┨");
|
||||||
console.Lines[3].ShouldBe("┃ Cell │ Cell ┃");
|
console.Lines[3].ShouldBe("┃ Cell │ Cell ┃");
|
||||||
console.Lines[4].ShouldBe("┃ Cell │ Cell ┃");
|
console.Lines[4].ShouldBe("┃ Cell │ Cell ┃");
|
||||||
console.Lines[5].ShouldBe("┗━━━━━━━━━━┷━━━━━━━━━━┛");
|
console.Lines[5].ShouldBe("┠──────────┼──────────┨");
|
||||||
|
console.Lines[6].ShouldBe("┃ Footer 1 │ Footer 2 ┃");
|
||||||
|
console.Lines[7].ShouldBe("┗━━━━━━━━━━┷━━━━━━━━━━┛");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -683,13 +710,15 @@ namespace Spectre.Console.Tests.Unit
|
|||||||
console.Render(table);
|
console.Render(table);
|
||||||
|
|
||||||
// Then
|
// Then
|
||||||
console.Lines.Count.ShouldBe(6);
|
console.Lines.Count.ShouldBe(8);
|
||||||
console.Lines[0].ShouldBe("┏━━━━━━━━━━┳━━━━━━━━━━┓");
|
console.Lines[0].ShouldBe("┏━━━━━━━━━━┳━━━━━━━━━━┓");
|
||||||
console.Lines[1].ShouldBe("┃ Header 1 ┃ Header 2 ┃");
|
console.Lines[1].ShouldBe("┃ Header 1 ┃ Header 2 ┃");
|
||||||
console.Lines[2].ShouldBe("┡━━━━━━━━━━╇━━━━━━━━━━┩");
|
console.Lines[2].ShouldBe("┡━━━━━━━━━━╇━━━━━━━━━━┩");
|
||||||
console.Lines[3].ShouldBe("│ Cell │ Cell │");
|
console.Lines[3].ShouldBe("│ Cell │ Cell │");
|
||||||
console.Lines[4].ShouldBe("│ Cell │ Cell │");
|
console.Lines[4].ShouldBe("│ Cell │ Cell │");
|
||||||
console.Lines[5].ShouldBe("└──────────┴──────────┘");
|
console.Lines[5].ShouldBe("├──────────┼──────────┤");
|
||||||
|
console.Lines[6].ShouldBe("│ Footer 1 │ Footer 2 │");
|
||||||
|
console.Lines[7].ShouldBe("└──────────┴──────────┘");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -729,13 +758,15 @@ namespace Spectre.Console.Tests.Unit
|
|||||||
console.Render(table);
|
console.Render(table);
|
||||||
|
|
||||||
// Then
|
// Then
|
||||||
console.Lines.Count.ShouldBe(6);
|
console.Lines.Count.ShouldBe(8);
|
||||||
console.Lines[0].ShouldBe("╔══════════╦══════════╗");
|
console.Lines[0].ShouldBe("╔══════════╦══════════╗");
|
||||||
console.Lines[1].ShouldBe("║ Header 1 ║ Header 2 ║");
|
console.Lines[1].ShouldBe("║ Header 1 ║ Header 2 ║");
|
||||||
console.Lines[2].ShouldBe("╠══════════╬══════════╣");
|
console.Lines[2].ShouldBe("╠══════════╬══════════╣");
|
||||||
console.Lines[3].ShouldBe("║ Cell ║ Cell ║");
|
console.Lines[3].ShouldBe("║ Cell ║ Cell ║");
|
||||||
console.Lines[4].ShouldBe("║ Cell ║ Cell ║");
|
console.Lines[4].ShouldBe("║ Cell ║ Cell ║");
|
||||||
console.Lines[5].ShouldBe("╚══════════╩══════════╝");
|
console.Lines[5].ShouldBe("╠══════════╬══════════╣");
|
||||||
|
console.Lines[6].ShouldBe("║ Footer 1 ║ Footer 2 ║");
|
||||||
|
console.Lines[7].ShouldBe("╚══════════╩══════════╝");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -775,13 +806,15 @@ namespace Spectre.Console.Tests.Unit
|
|||||||
console.Render(table);
|
console.Render(table);
|
||||||
|
|
||||||
// Then
|
// Then
|
||||||
console.Lines.Count.ShouldBe(6);
|
console.Lines.Count.ShouldBe(8);
|
||||||
console.Lines[0].ShouldBe("╔══════════╤══════════╗");
|
console.Lines[0].ShouldBe("╔══════════╤══════════╗");
|
||||||
console.Lines[1].ShouldBe("║ Header 1 │ Header 2 ║");
|
console.Lines[1].ShouldBe("║ Header 1 │ Header 2 ║");
|
||||||
console.Lines[2].ShouldBe("╟──────────┼──────────╢");
|
console.Lines[2].ShouldBe("╟──────────┼──────────╢");
|
||||||
console.Lines[3].ShouldBe("║ Cell │ Cell ║");
|
console.Lines[3].ShouldBe("║ Cell │ Cell ║");
|
||||||
console.Lines[4].ShouldBe("║ Cell │ Cell ║");
|
console.Lines[4].ShouldBe("║ Cell │ Cell ║");
|
||||||
console.Lines[5].ShouldBe("╚══════════╧══════════╝");
|
console.Lines[5].ShouldBe("╟──────────┼──────────╢");
|
||||||
|
console.Lines[6].ShouldBe("║ Footer 1 │ Footer 2 ║");
|
||||||
|
console.Lines[7].ShouldBe("╚══════════╧══════════╝");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -821,13 +854,14 @@ namespace Spectre.Console.Tests.Unit
|
|||||||
console.Render(table);
|
console.Render(table);
|
||||||
|
|
||||||
// Then
|
// Then
|
||||||
console.Lines.Count.ShouldBe(6);
|
console.Lines.Count.ShouldBe(7);
|
||||||
console.Lines[0].ShouldBe(" ");
|
console.Lines[0].ShouldBe(" ");
|
||||||
console.Lines[1].ShouldBe("| Header 1 | Header 2 |");
|
console.Lines[1].ShouldBe("| Header 1 | Header 2 |");
|
||||||
console.Lines[2].ShouldBe("| -------- | -------- |");
|
console.Lines[2].ShouldBe("| -------- | -------- |");
|
||||||
console.Lines[3].ShouldBe("| Cell | Cell |");
|
console.Lines[3].ShouldBe("| Cell | Cell |");
|
||||||
console.Lines[4].ShouldBe("| Cell | Cell |");
|
console.Lines[4].ShouldBe("| Cell | Cell |");
|
||||||
console.Lines[5].ShouldBe(" ");
|
console.Lines[5].ShouldBe("| Footer 1 | Footer 2 |");
|
||||||
|
console.Lines[6].ShouldBe(" ");
|
||||||
}
|
}
|
||||||
|
|
||||||
[Fact]
|
[Fact]
|
||||||
@@ -841,13 +875,14 @@ namespace Spectre.Console.Tests.Unit
|
|||||||
console.Render(table);
|
console.Render(table);
|
||||||
|
|
||||||
// Then
|
// Then
|
||||||
console.Lines.Count.ShouldBe(6);
|
console.Lines.Count.ShouldBe(7);
|
||||||
console.Lines[0].ShouldBe(" ");
|
console.Lines[0].ShouldBe(" ");
|
||||||
console.Lines[1].ShouldBe("| Header 1 | Header 2 |");
|
console.Lines[1].ShouldBe("| Header 1 | Header 2 |");
|
||||||
console.Lines[2].ShouldBe("| -------- | :------- |");
|
console.Lines[2].ShouldBe("| -------- | :------- |");
|
||||||
console.Lines[3].ShouldBe("| Cell | Cell |");
|
console.Lines[3].ShouldBe("| Cell | Cell |");
|
||||||
console.Lines[4].ShouldBe("| Cell | Cell |");
|
console.Lines[4].ShouldBe("| Cell | Cell |");
|
||||||
console.Lines[5].ShouldBe(" ");
|
console.Lines[5].ShouldBe("| Footer 1 | Footer 2 |");
|
||||||
|
console.Lines[6].ShouldBe(" ");
|
||||||
}
|
}
|
||||||
|
|
||||||
[Fact]
|
[Fact]
|
||||||
@@ -861,13 +896,14 @@ namespace Spectre.Console.Tests.Unit
|
|||||||
console.Render(table);
|
console.Render(table);
|
||||||
|
|
||||||
// Then
|
// Then
|
||||||
console.Lines.Count.ShouldBe(6);
|
console.Lines.Count.ShouldBe(7);
|
||||||
console.Lines[0].ShouldBe(" ");
|
console.Lines[0].ShouldBe(" ");
|
||||||
console.Lines[1].ShouldBe("| Header 1 | Header 2 |");
|
console.Lines[1].ShouldBe("| Header 1 | Header 2 |");
|
||||||
console.Lines[2].ShouldBe("| -------- | :------: |");
|
console.Lines[2].ShouldBe("| -------- | :------: |");
|
||||||
console.Lines[3].ShouldBe("| Cell | Cell |");
|
console.Lines[3].ShouldBe("| Cell | Cell |");
|
||||||
console.Lines[4].ShouldBe("| Cell | Cell |");
|
console.Lines[4].ShouldBe("| Cell | Cell |");
|
||||||
console.Lines[5].ShouldBe(" ");
|
console.Lines[5].ShouldBe("| Footer 1 | Footer 2 |");
|
||||||
|
console.Lines[6].ShouldBe(" ");
|
||||||
}
|
}
|
||||||
|
|
||||||
[Fact]
|
[Fact]
|
||||||
@@ -881,13 +917,14 @@ namespace Spectre.Console.Tests.Unit
|
|||||||
console.Render(table);
|
console.Render(table);
|
||||||
|
|
||||||
// Then
|
// Then
|
||||||
console.Lines.Count.ShouldBe(6);
|
console.Lines.Count.ShouldBe(7);
|
||||||
console.Lines[0].ShouldBe(" ");
|
console.Lines[0].ShouldBe(" ");
|
||||||
console.Lines[1].ShouldBe("| Header 1 | Header 2 |");
|
console.Lines[1].ShouldBe("| Header 1 | Header 2 |");
|
||||||
console.Lines[2].ShouldBe("| -------- | -------: |");
|
console.Lines[2].ShouldBe("| -------- | -------: |");
|
||||||
console.Lines[3].ShouldBe("| Cell | Cell |");
|
console.Lines[3].ShouldBe("| Cell | Cell |");
|
||||||
console.Lines[4].ShouldBe("| Cell | Cell |");
|
console.Lines[4].ShouldBe("| Cell | Cell |");
|
||||||
console.Lines[5].ShouldBe(" ");
|
console.Lines[5].ShouldBe("| Footer 1 | Footer 2 |");
|
||||||
|
console.Lines[6].ShouldBe(" ");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -896,8 +933,8 @@ namespace Spectre.Console.Tests.Unit
|
|||||||
public static Table GetTable(Justify? header1 = null, Justify? header2 = null)
|
public static Table GetTable(Justify? header1 = null, Justify? header2 = null)
|
||||||
{
|
{
|
||||||
var table = new Table();
|
var table = new Table();
|
||||||
table.AddColumn("Header 1", c => c.Alignment = header1);
|
table.AddColumn("Header 1", c => c.Alignment(header1).Footer("Footer 1"));
|
||||||
table.AddColumn("Header 2", c => c.Alignment = header2);
|
table.AddColumn("Header 2", c => c.Alignment(header2).Footer("Footer 2"));
|
||||||
table.AddRow("Cell", "Cell");
|
table.AddRow("Cell", "Cell");
|
||||||
table.AddRow("Cell", "Cell");
|
table.AddRow("Cell", "Cell");
|
||||||
return table;
|
return table;
|
||||||
|
|||||||
@@ -98,7 +98,7 @@ namespace Spectre.Console.Tests.Unit
|
|||||||
table.AddRow("Foo");
|
table.AddRow("Foo");
|
||||||
|
|
||||||
// Then
|
// Then
|
||||||
table.RowCount.ShouldBe(1);
|
table.Rows.Count.ShouldBe(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
[Fact]
|
[Fact]
|
||||||
@@ -168,6 +168,105 @@ namespace Spectre.Console.Tests.Unit
|
|||||||
console.Lines[5].ShouldBe("└────────┴────────┴───────┘");
|
console.Lines[5].ShouldBe("└────────┴────────┴───────┘");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
[Fact]
|
||||||
|
public void Should_Render_Table_With_Footers_Correctly()
|
||||||
|
{
|
||||||
|
// Given
|
||||||
|
var console = new PlainConsole(width: 80);
|
||||||
|
var table = new Table();
|
||||||
|
table.AddColumn(new TableColumn("Foo").Footer("Oof").RightAligned());
|
||||||
|
table.AddColumn("Bar");
|
||||||
|
table.AddColumns(new TableColumn("Baz").Footer("Zab"));
|
||||||
|
table.AddRow("Qux", "Corgi", "Waldo");
|
||||||
|
table.AddRow("Grault", "Garply", "Fred");
|
||||||
|
|
||||||
|
// When
|
||||||
|
console.Render(table);
|
||||||
|
|
||||||
|
// Then
|
||||||
|
console.Lines.Count.ShouldBe(8);
|
||||||
|
console.Lines[0].ShouldBe("┌────────┬────────┬───────┐");
|
||||||
|
console.Lines[1].ShouldBe("│ Foo │ Bar │ Baz │");
|
||||||
|
console.Lines[2].ShouldBe("├────────┼────────┼───────┤");
|
||||||
|
console.Lines[3].ShouldBe("│ Qux │ Corgi │ Waldo │");
|
||||||
|
console.Lines[4].ShouldBe("│ Grault │ Garply │ Fred │");
|
||||||
|
console.Lines[5].ShouldBe("├────────┼────────┼───────┤");
|
||||||
|
console.Lines[6].ShouldBe("│ Oof │ │ Zab │");
|
||||||
|
console.Lines[7].ShouldBe("└────────┴────────┴───────┘");
|
||||||
|
}
|
||||||
|
|
||||||
|
[Fact]
|
||||||
|
public void Should_Left_Align_Table_Correctly()
|
||||||
|
{
|
||||||
|
// Given
|
||||||
|
var console = new PlainConsole(width: 80);
|
||||||
|
var table = new Table();
|
||||||
|
table.Alignment = Justify.Left;
|
||||||
|
table.AddColumns("Foo", "Bar", "Baz");
|
||||||
|
table.AddRow("Qux", "Corgi", "Waldo");
|
||||||
|
table.AddRow("Grault", "Garply", "Fred");
|
||||||
|
|
||||||
|
// When
|
||||||
|
console.Render(table);
|
||||||
|
|
||||||
|
// Then
|
||||||
|
console.Lines.Count.ShouldBe(6);
|
||||||
|
console.Lines[0].ShouldBe("┌────────┬────────┬───────┐");
|
||||||
|
console.Lines[1].ShouldBe("│ Foo │ Bar │ Baz │");
|
||||||
|
console.Lines[2].ShouldBe("├────────┼────────┼───────┤");
|
||||||
|
console.Lines[3].ShouldBe("│ Qux │ Corgi │ Waldo │");
|
||||||
|
console.Lines[4].ShouldBe("│ Grault │ Garply │ Fred │");
|
||||||
|
console.Lines[5].ShouldBe("└────────┴────────┴───────┘");
|
||||||
|
}
|
||||||
|
|
||||||
|
[Fact]
|
||||||
|
public void Should_Center_Table_Correctly()
|
||||||
|
{
|
||||||
|
// Given
|
||||||
|
var console = new PlainConsole(width: 80);
|
||||||
|
var table = new Table();
|
||||||
|
table.Alignment = Justify.Center;
|
||||||
|
table.AddColumns("Foo", "Bar", "Baz");
|
||||||
|
table.AddRow("Qux", "Corgi", "Waldo");
|
||||||
|
table.AddRow("Grault", "Garply", "Fred");
|
||||||
|
|
||||||
|
// When
|
||||||
|
console.Render(table);
|
||||||
|
|
||||||
|
// Then
|
||||||
|
console.Lines.Count.ShouldBe(6);
|
||||||
|
console.Lines[0].ShouldBe(" ┌────────┬────────┬───────┐ ");
|
||||||
|
console.Lines[1].ShouldBe(" │ Foo │ Bar │ Baz │ ");
|
||||||
|
console.Lines[2].ShouldBe(" ├────────┼────────┼───────┤ ");
|
||||||
|
console.Lines[3].ShouldBe(" │ Qux │ Corgi │ Waldo │ ");
|
||||||
|
console.Lines[4].ShouldBe(" │ Grault │ Garply │ Fred │ ");
|
||||||
|
console.Lines[5].ShouldBe(" └────────┴────────┴───────┘ ");
|
||||||
|
}
|
||||||
|
|
||||||
|
[Fact]
|
||||||
|
public void Should_Right_Align_Table_Correctly()
|
||||||
|
{
|
||||||
|
// Given
|
||||||
|
var console = new PlainConsole(width: 80);
|
||||||
|
var table = new Table();
|
||||||
|
table.Alignment = Justify.Right;
|
||||||
|
table.AddColumns("Foo", "Bar", "Baz");
|
||||||
|
table.AddRow("Qux", "Corgi", "Waldo");
|
||||||
|
table.AddRow("Grault", "Garply", "Fred");
|
||||||
|
|
||||||
|
// When
|
||||||
|
console.Render(table);
|
||||||
|
|
||||||
|
// Then
|
||||||
|
console.Lines.Count.ShouldBe(6);
|
||||||
|
console.Lines[0].ShouldBe(" ┌────────┬────────┬───────┐");
|
||||||
|
console.Lines[1].ShouldBe(" │ Foo │ Bar │ Baz │");
|
||||||
|
console.Lines[2].ShouldBe(" ├────────┼────────┼───────┤");
|
||||||
|
console.Lines[3].ShouldBe(" │ Qux │ Corgi │ Waldo │");
|
||||||
|
console.Lines[4].ShouldBe(" │ Grault │ Garply │ Fred │");
|
||||||
|
console.Lines[5].ShouldBe(" └────────┴────────┴───────┘");
|
||||||
|
}
|
||||||
|
|
||||||
[Fact]
|
[Fact]
|
||||||
public void Should_Render_Table_Nested_In_Panels_Correctly()
|
public void Should_Render_Table_Nested_In_Panels_Correctly()
|
||||||
{
|
{
|
||||||
@@ -250,52 +349,6 @@ namespace Spectre.Console.Tests.Unit
|
|||||||
console.Lines[5].ShouldBe("└───────────────────────────┴───────────────────────────┴──────────────────────┘");
|
console.Lines[5].ShouldBe("└───────────────────────────┴───────────────────────────┴──────────────────────┘");
|
||||||
}
|
}
|
||||||
|
|
||||||
[Fact]
|
|
||||||
public void Should_Render_Table_With_Ascii_Border_Correctly()
|
|
||||||
{
|
|
||||||
// Given
|
|
||||||
var console = new PlainConsole(width: 80);
|
|
||||||
var table = new Table { Border = TableBorder.Ascii };
|
|
||||||
table.AddColumns("Foo", "Bar", "Baz");
|
|
||||||
table.AddRow("Qux", "Corgi", "Waldo");
|
|
||||||
table.AddRow("Grault", "Garply", "Fred");
|
|
||||||
|
|
||||||
// When
|
|
||||||
console.Render(table);
|
|
||||||
|
|
||||||
// Then
|
|
||||||
console.Lines.Count.ShouldBe(6);
|
|
||||||
console.Lines[0].ShouldBe("+-------------------------+");
|
|
||||||
console.Lines[1].ShouldBe("| Foo | Bar | Baz |");
|
|
||||||
console.Lines[2].ShouldBe("|--------+--------+-------|");
|
|
||||||
console.Lines[3].ShouldBe("| Qux | Corgi | Waldo |");
|
|
||||||
console.Lines[4].ShouldBe("| Grault | Garply | Fred |");
|
|
||||||
console.Lines[5].ShouldBe("+-------------------------+");
|
|
||||||
}
|
|
||||||
|
|
||||||
[Fact]
|
|
||||||
public void Should_Render_Table_With_Rounded_Border_Correctly()
|
|
||||||
{
|
|
||||||
// Given
|
|
||||||
var console = new PlainConsole(width: 80);
|
|
||||||
var table = new Table { Border = TableBorder.Rounded };
|
|
||||||
table.AddColumns("Foo", "Bar", "Baz");
|
|
||||||
table.AddRow("Qux", "Corgi", "Waldo");
|
|
||||||
table.AddRow("Grault", "Garply", "Fred");
|
|
||||||
|
|
||||||
// When
|
|
||||||
console.Render(table);
|
|
||||||
|
|
||||||
// Then
|
|
||||||
console.Lines.Count.ShouldBe(6);
|
|
||||||
console.Lines[0].ShouldBe("╭────────┬────────┬───────╮");
|
|
||||||
console.Lines[1].ShouldBe("│ Foo │ Bar │ Baz │");
|
|
||||||
console.Lines[2].ShouldBe("├────────┼────────┼───────┤");
|
|
||||||
console.Lines[3].ShouldBe("│ Qux │ Corgi │ Waldo │");
|
|
||||||
console.Lines[4].ShouldBe("│ Grault │ Garply │ Fred │");
|
|
||||||
console.Lines[5].ShouldBe("╰────────┴────────┴───────╯");
|
|
||||||
}
|
|
||||||
|
|
||||||
[Fact]
|
[Fact]
|
||||||
public void Should_Render_Table_With_No_Border_Correctly()
|
public void Should_Render_Table_With_No_Border_Correctly()
|
||||||
{
|
{
|
||||||
@@ -383,5 +436,165 @@ namespace Spectre.Console.Tests.Unit
|
|||||||
console.Lines[1].ShouldBe("│ Foo │ Bar │ Baz │");
|
console.Lines[1].ShouldBe("│ Foo │ Bar │ Baz │");
|
||||||
console.Lines[2].ShouldBe("└─────┴─────┴────────┘");
|
console.Lines[2].ShouldBe("└─────┴─────┴────────┘");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
[Fact]
|
||||||
|
public void Should_Not_Draw_Tables_That_Are_Impossible_To_Draw()
|
||||||
|
{
|
||||||
|
// Given
|
||||||
|
var console = new PlainConsole(width: 25);
|
||||||
|
|
||||||
|
var first = new Table().Border(TableBorder.Rounded).BorderColor(Color.Red);
|
||||||
|
first.AddColumn(new TableColumn("[u]PS1[/]").Centered());
|
||||||
|
first.AddColumn(new TableColumn("[u]PS2[/]"));
|
||||||
|
first.AddColumn(new TableColumn("[u]PS3[/]"));
|
||||||
|
first.AddRow("Hello", "[red]World[/]", string.Empty);
|
||||||
|
first.AddRow("[blue]Bonjour[/]", "[white]le[/]", "[red]monde![/]");
|
||||||
|
first.AddRow("[blue]Hej[/]", "[yellow]Världen[/]", string.Empty);
|
||||||
|
|
||||||
|
var second = new Table().Border(TableBorder.Square).BorderColor(Color.Green);
|
||||||
|
second.AddColumn(new TableColumn("[u]Foo[/]"));
|
||||||
|
second.AddColumn(new TableColumn("[u]Bar[/]"));
|
||||||
|
second.AddColumn(new TableColumn("[u]Baz[/]"));
|
||||||
|
second.AddRow("Hello", "[red]World[/]", string.Empty);
|
||||||
|
second.AddRow(first, new Text("Whaaat"), new Text("Lolz"));
|
||||||
|
second.AddRow("[blue]Hej[/]", "[yellow]Världen[/]", string.Empty);
|
||||||
|
|
||||||
|
var table = new Table().Border(TableBorder.Rounded);
|
||||||
|
table.AddColumn(new TableColumn(new Panel("[u]ABC[/]").BorderColor(Color.Red)));
|
||||||
|
table.AddColumn(new TableColumn(new Panel("[u]DEF[/]").BorderColor(Color.Green)));
|
||||||
|
table.AddColumn(new TableColumn(new Panel("[u]GHI[/]").BorderColor(Color.Blue)));
|
||||||
|
table.AddRow(new Text("Hello").Centered(), new Markup("[red]World[/]"), Text.Empty);
|
||||||
|
table.AddRow(second, new Text("Whaat"), new Text("Lol").RightAligned());
|
||||||
|
table.AddRow(new Markup("[blue]Hej[/]"), new Markup("[yellow]Världen[/]"), Text.Empty);
|
||||||
|
|
||||||
|
// When
|
||||||
|
console.Render(table);
|
||||||
|
|
||||||
|
// Then
|
||||||
|
console.Lines.Count.ShouldBe(12);
|
||||||
|
console.Lines[00].ShouldBe("╭───────┬───────┬───────╮");
|
||||||
|
console.Lines[01].ShouldBe("│ ┌───┐ │ ┌───┐ │ ┌───┐ │");
|
||||||
|
console.Lines[02].ShouldBe("│ │ A │ │ │ D │ │ │ G │ │");
|
||||||
|
console.Lines[03].ShouldBe("│ │ B │ │ │ E │ │ │ H │ │");
|
||||||
|
console.Lines[04].ShouldBe("│ │ C │ │ │ F │ │ │ I │ │");
|
||||||
|
console.Lines[05].ShouldBe("│ └───┘ │ └───┘ │ └───┘ │");
|
||||||
|
console.Lines[06].ShouldBe("├───────┼───────┼───────┤");
|
||||||
|
console.Lines[07].ShouldBe("│ Hello │ World │ │");
|
||||||
|
console.Lines[08].ShouldBe("│ … │ Whaat │ Lol │");
|
||||||
|
console.Lines[09].ShouldBe("│ Hej │ Värld │ │");
|
||||||
|
console.Lines[10].ShouldBe("│ │ en │ │");
|
||||||
|
console.Lines[11].ShouldBe("╰───────┴───────┴───────╯");
|
||||||
|
}
|
||||||
|
|
||||||
|
[Fact]
|
||||||
|
public void Should_Render_Table_With_Title_And_Caption_Correctly()
|
||||||
|
{
|
||||||
|
// Given
|
||||||
|
var console = new PlainConsole(width: 80);
|
||||||
|
var table = new Table { Border = TableBorder.Rounded };
|
||||||
|
table.Title = new TableTitle("Hello World");
|
||||||
|
table.Caption = new TableTitle("Goodbye World");
|
||||||
|
table.AddColumns("Foo", "Bar", "Baz");
|
||||||
|
table.AddRow("Qux", "Corgi", "Waldo");
|
||||||
|
table.AddRow("Grault", "Garply", "Fred");
|
||||||
|
|
||||||
|
// When
|
||||||
|
console.Render(table);
|
||||||
|
|
||||||
|
// Then
|
||||||
|
console.Lines.Count.ShouldBe(8);
|
||||||
|
console.Lines[0].ShouldBe(" Hello World ");
|
||||||
|
console.Lines[1].ShouldBe("╭────────┬────────┬───────╮");
|
||||||
|
console.Lines[2].ShouldBe("│ Foo │ Bar │ Baz │");
|
||||||
|
console.Lines[3].ShouldBe("├────────┼────────┼───────┤");
|
||||||
|
console.Lines[4].ShouldBe("│ Qux │ Corgi │ Waldo │");
|
||||||
|
console.Lines[5].ShouldBe("│ Grault │ Garply │ Fred │");
|
||||||
|
console.Lines[6].ShouldBe("╰────────┴────────┴───────╯");
|
||||||
|
console.Lines[7].ShouldBe(" Goodbye World ");
|
||||||
|
}
|
||||||
|
|
||||||
|
[Fact]
|
||||||
|
public void Should_Left_Align_Table_With_Title_And_Caption_Correctly()
|
||||||
|
{
|
||||||
|
// Given
|
||||||
|
var console = new PlainConsole(width: 80);
|
||||||
|
var table = new Table { Border = TableBorder.Rounded };
|
||||||
|
table.LeftAligned();
|
||||||
|
table.Title = new TableTitle("Hello World");
|
||||||
|
table.Caption = new TableTitle("Goodbye World");
|
||||||
|
table.AddColumns("Foo", "Bar", "Baz");
|
||||||
|
table.AddRow("Qux", "Corgi", "Waldo");
|
||||||
|
table.AddRow("Grault", "Garply", "Fred");
|
||||||
|
|
||||||
|
// When
|
||||||
|
console.Render(table);
|
||||||
|
|
||||||
|
// Then
|
||||||
|
console.Lines.Count.ShouldBe(8);
|
||||||
|
console.Lines[0].ShouldBe(" Hello World ");
|
||||||
|
console.Lines[1].ShouldBe("╭────────┬────────┬───────╮");
|
||||||
|
console.Lines[2].ShouldBe("│ Foo │ Bar │ Baz │");
|
||||||
|
console.Lines[3].ShouldBe("├────────┼────────┼───────┤");
|
||||||
|
console.Lines[4].ShouldBe("│ Qux │ Corgi │ Waldo │");
|
||||||
|
console.Lines[5].ShouldBe("│ Grault │ Garply │ Fred │");
|
||||||
|
console.Lines[6].ShouldBe("╰────────┴────────┴───────╯");
|
||||||
|
console.Lines[7].ShouldBe(" Goodbye World ");
|
||||||
|
}
|
||||||
|
|
||||||
|
[Fact]
|
||||||
|
public void Should_Center_Table_With_Title_And_Caption_Correctly()
|
||||||
|
{
|
||||||
|
// Given
|
||||||
|
var console = new PlainConsole(width: 80);
|
||||||
|
var table = new Table { Border = TableBorder.Rounded };
|
||||||
|
table.Centered();
|
||||||
|
table.Title = new TableTitle("Hello World");
|
||||||
|
table.Caption = new TableTitle("Goodbye World");
|
||||||
|
table.AddColumns("Foo", "Bar", "Baz");
|
||||||
|
table.AddRow("Qux", "Corgi", "Waldo");
|
||||||
|
table.AddRow("Grault", "Garply", "Fred");
|
||||||
|
|
||||||
|
// When
|
||||||
|
console.Render(table);
|
||||||
|
|
||||||
|
// Then
|
||||||
|
console.Lines.Count.ShouldBe(8);
|
||||||
|
console.Lines[0].ShouldBe(" Hello World ");
|
||||||
|
console.Lines[1].ShouldBe(" ╭────────┬────────┬───────╮ ");
|
||||||
|
console.Lines[2].ShouldBe(" │ Foo │ Bar │ Baz │ ");
|
||||||
|
console.Lines[3].ShouldBe(" ├────────┼────────┼───────┤ ");
|
||||||
|
console.Lines[4].ShouldBe(" │ Qux │ Corgi │ Waldo │ ");
|
||||||
|
console.Lines[5].ShouldBe(" │ Grault │ Garply │ Fred │ ");
|
||||||
|
console.Lines[6].ShouldBe(" ╰────────┴────────┴───────╯ ");
|
||||||
|
console.Lines[7].ShouldBe(" Goodbye World ");
|
||||||
|
}
|
||||||
|
|
||||||
|
[Fact]
|
||||||
|
public void Should_Right_Align_Table_With_Title_And_Caption_Correctly()
|
||||||
|
{
|
||||||
|
// Given
|
||||||
|
var console = new PlainConsole(width: 80);
|
||||||
|
var table = new Table { Border = TableBorder.Rounded };
|
||||||
|
table.RightAligned();
|
||||||
|
table.Title = new TableTitle("Hello World");
|
||||||
|
table.Caption = new TableTitle("Goodbye World");
|
||||||
|
table.AddColumns("Foo", "Bar", "Baz");
|
||||||
|
table.AddRow("Qux", "Corgi", "Waldo");
|
||||||
|
table.AddRow("Grault", "Garply", "Fred");
|
||||||
|
|
||||||
|
// When
|
||||||
|
console.Render(table);
|
||||||
|
|
||||||
|
// Then
|
||||||
|
console.Lines.Count.ShouldBe(8);
|
||||||
|
console.Lines[0].ShouldBe(" Hello World ");
|
||||||
|
console.Lines[1].ShouldBe(" ╭────────┬────────┬───────╮");
|
||||||
|
console.Lines[2].ShouldBe(" │ Foo │ Bar │ Baz │");
|
||||||
|
console.Lines[3].ShouldBe(" ├────────┼────────┼───────┤");
|
||||||
|
console.Lines[4].ShouldBe(" │ Qux │ Corgi │ Waldo │");
|
||||||
|
console.Lines[5].ShouldBe(" │ Grault │ Garply │ Fred │");
|
||||||
|
console.Lines[6].ShouldBe(" ╰────────┴────────┴───────╯");
|
||||||
|
console.Lines[7].ShouldBe(" Goodbye World ");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -108,7 +108,7 @@ namespace Spectre.Console.Tests.Unit
|
|||||||
// Given
|
// Given
|
||||||
var console = new PlainConsole(14);
|
var console = new PlainConsole(14);
|
||||||
var text = new Text("foo pneumonoultramicroscopicsilicovolcanoconiosis bar qux")
|
var text = new Text("foo pneumonoultramicroscopicsilicovolcanoconiosis bar qux")
|
||||||
.SetOverflow(overflow);
|
.Overflow(overflow);
|
||||||
|
|
||||||
// When
|
// When
|
||||||
console.Render(text);
|
console.Render(text);
|
||||||
|
|||||||
@@ -44,7 +44,13 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "GitHub", "GitHub", "{C3E2CB
|
|||||||
..\.github\workflows\publish.yaml = ..\.github\workflows\publish.yaml
|
..\.github\workflows\publish.yaml = ..\.github\workflows\publish.yaml
|
||||||
EndProjectSection
|
EndProjectSection
|
||||||
EndProject
|
EndProject
|
||||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Calendars", "..\examples\Calendars\Calendars.csproj", "{57691C7D-683D-46E6-AA4F-57A8C5F65D25}"
|
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Calendars", "..\examples\Calendars\Calendars.csproj", "{57691C7D-683D-46E6-AA4F-57A8C5F65D25}"
|
||||||
|
EndProject
|
||||||
|
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Rules", "..\examples\Rules\Rules.csproj", "{8622A261-02C6-40CA-9797-E3F01ED87D6B}"
|
||||||
|
EndProject
|
||||||
|
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Cursor", "..\examples\Cursor\Cursor.csproj", "{75C608C3-ABB4-4168-A229-7F8250B946D1}"
|
||||||
|
EndProject
|
||||||
|
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Prompt", "..\examples\Prompt\Prompt.csproj", "{6351C70F-F368-46DB-BAED-9B87CCD69353}"
|
||||||
EndProject
|
EndProject
|
||||||
Global
|
Global
|
||||||
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
||||||
@@ -212,6 +218,42 @@ Global
|
|||||||
{57691C7D-683D-46E6-AA4F-57A8C5F65D25}.Release|x64.Build.0 = Release|Any CPU
|
{57691C7D-683D-46E6-AA4F-57A8C5F65D25}.Release|x64.Build.0 = Release|Any CPU
|
||||||
{57691C7D-683D-46E6-AA4F-57A8C5F65D25}.Release|x86.ActiveCfg = Release|Any CPU
|
{57691C7D-683D-46E6-AA4F-57A8C5F65D25}.Release|x86.ActiveCfg = Release|Any CPU
|
||||||
{57691C7D-683D-46E6-AA4F-57A8C5F65D25}.Release|x86.Build.0 = Release|Any CPU
|
{57691C7D-683D-46E6-AA4F-57A8C5F65D25}.Release|x86.Build.0 = Release|Any CPU
|
||||||
|
{8622A261-02C6-40CA-9797-E3F01ED87D6B}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||||
|
{8622A261-02C6-40CA-9797-E3F01ED87D6B}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||||
|
{8622A261-02C6-40CA-9797-E3F01ED87D6B}.Debug|x64.ActiveCfg = Debug|Any CPU
|
||||||
|
{8622A261-02C6-40CA-9797-E3F01ED87D6B}.Debug|x64.Build.0 = Debug|Any CPU
|
||||||
|
{8622A261-02C6-40CA-9797-E3F01ED87D6B}.Debug|x86.ActiveCfg = Debug|Any CPU
|
||||||
|
{8622A261-02C6-40CA-9797-E3F01ED87D6B}.Debug|x86.Build.0 = Debug|Any CPU
|
||||||
|
{8622A261-02C6-40CA-9797-E3F01ED87D6B}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||||
|
{8622A261-02C6-40CA-9797-E3F01ED87D6B}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||||
|
{8622A261-02C6-40CA-9797-E3F01ED87D6B}.Release|x64.ActiveCfg = Release|Any CPU
|
||||||
|
{8622A261-02C6-40CA-9797-E3F01ED87D6B}.Release|x64.Build.0 = Release|Any CPU
|
||||||
|
{8622A261-02C6-40CA-9797-E3F01ED87D6B}.Release|x86.ActiveCfg = Release|Any CPU
|
||||||
|
{8622A261-02C6-40CA-9797-E3F01ED87D6B}.Release|x86.Build.0 = Release|Any CPU
|
||||||
|
{75C608C3-ABB4-4168-A229-7F8250B946D1}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||||
|
{75C608C3-ABB4-4168-A229-7F8250B946D1}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||||
|
{75C608C3-ABB4-4168-A229-7F8250B946D1}.Debug|x64.ActiveCfg = Debug|Any CPU
|
||||||
|
{75C608C3-ABB4-4168-A229-7F8250B946D1}.Debug|x64.Build.0 = Debug|Any CPU
|
||||||
|
{75C608C3-ABB4-4168-A229-7F8250B946D1}.Debug|x86.ActiveCfg = Debug|Any CPU
|
||||||
|
{75C608C3-ABB4-4168-A229-7F8250B946D1}.Debug|x86.Build.0 = Debug|Any CPU
|
||||||
|
{75C608C3-ABB4-4168-A229-7F8250B946D1}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||||
|
{75C608C3-ABB4-4168-A229-7F8250B946D1}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||||
|
{75C608C3-ABB4-4168-A229-7F8250B946D1}.Release|x64.ActiveCfg = Release|Any CPU
|
||||||
|
{75C608C3-ABB4-4168-A229-7F8250B946D1}.Release|x64.Build.0 = Release|Any CPU
|
||||||
|
{75C608C3-ABB4-4168-A229-7F8250B946D1}.Release|x86.ActiveCfg = Release|Any CPU
|
||||||
|
{75C608C3-ABB4-4168-A229-7F8250B946D1}.Release|x86.Build.0 = Release|Any CPU
|
||||||
|
{6351C70F-F368-46DB-BAED-9B87CCD69353}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||||
|
{6351C70F-F368-46DB-BAED-9B87CCD69353}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||||
|
{6351C70F-F368-46DB-BAED-9B87CCD69353}.Debug|x64.ActiveCfg = Debug|Any CPU
|
||||||
|
{6351C70F-F368-46DB-BAED-9B87CCD69353}.Debug|x64.Build.0 = Debug|Any CPU
|
||||||
|
{6351C70F-F368-46DB-BAED-9B87CCD69353}.Debug|x86.ActiveCfg = Debug|Any CPU
|
||||||
|
{6351C70F-F368-46DB-BAED-9B87CCD69353}.Debug|x86.Build.0 = Debug|Any CPU
|
||||||
|
{6351C70F-F368-46DB-BAED-9B87CCD69353}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||||
|
{6351C70F-F368-46DB-BAED-9B87CCD69353}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||||
|
{6351C70F-F368-46DB-BAED-9B87CCD69353}.Release|x64.ActiveCfg = Release|Any CPU
|
||||||
|
{6351C70F-F368-46DB-BAED-9B87CCD69353}.Release|x64.Build.0 = Release|Any CPU
|
||||||
|
{6351C70F-F368-46DB-BAED-9B87CCD69353}.Release|x86.ActiveCfg = Release|Any CPU
|
||||||
|
{6351C70F-F368-46DB-BAED-9B87CCD69353}.Release|x86.Build.0 = Release|Any CPU
|
||||||
EndGlobalSection
|
EndGlobalSection
|
||||||
GlobalSection(SolutionProperties) = preSolution
|
GlobalSection(SolutionProperties) = preSolution
|
||||||
HideSolutionNode = FALSE
|
HideSolutionNode = FALSE
|
||||||
@@ -229,6 +271,9 @@ Global
|
|||||||
{90C081A7-7C1D-4A4A-82B6-8FF473C3EA32} = {F0575243-121F-4DEE-9F6B-246E26DC0844}
|
{90C081A7-7C1D-4A4A-82B6-8FF473C3EA32} = {F0575243-121F-4DEE-9F6B-246E26DC0844}
|
||||||
{C3E2CB5C-1517-4C75-B59A-93D4E22BEC8D} = {20595AD4-8D75-4AF8-B6BC-9C38C160423F}
|
{C3E2CB5C-1517-4C75-B59A-93D4E22BEC8D} = {20595AD4-8D75-4AF8-B6BC-9C38C160423F}
|
||||||
{57691C7D-683D-46E6-AA4F-57A8C5F65D25} = {F0575243-121F-4DEE-9F6B-246E26DC0844}
|
{57691C7D-683D-46E6-AA4F-57A8C5F65D25} = {F0575243-121F-4DEE-9F6B-246E26DC0844}
|
||||||
|
{8622A261-02C6-40CA-9797-E3F01ED87D6B} = {F0575243-121F-4DEE-9F6B-246E26DC0844}
|
||||||
|
{75C608C3-ABB4-4168-A229-7F8250B946D1} = {F0575243-121F-4DEE-9F6B-246E26DC0844}
|
||||||
|
{6351C70F-F368-46DB-BAED-9B87CCD69353} = {F0575243-121F-4DEE-9F6B-246E26DC0844}
|
||||||
EndGlobalSection
|
EndGlobalSection
|
||||||
GlobalSection(ExtensibilityGlobals) = postSolution
|
GlobalSection(ExtensibilityGlobals) = postSolution
|
||||||
SolutionGuid = {5729B071-67A0-48FB-8B1B-275E6822086C}
|
SolutionGuid = {5729B071-67A0-48FB-8B1B-275E6822086C}
|
||||||
|
|||||||
47
src/Spectre.Console/AnsiConsole.Prompt.cs
Normal file
47
src/Spectre.Console/AnsiConsole.Prompt.cs
Normal file
@@ -0,0 +1,47 @@
|
|||||||
|
using System;
|
||||||
|
|
||||||
|
namespace Spectre.Console
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// A console capable of writing ANSI escape sequences.
|
||||||
|
/// </summary>
|
||||||
|
public static partial class AnsiConsole
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Displays a prompt to the user.
|
||||||
|
/// </summary>
|
||||||
|
/// <typeparam name="T">The prompt result type.</typeparam>
|
||||||
|
/// <param name="prompt">The prompt to display.</param>
|
||||||
|
/// <returns>The prompt input result.</returns>
|
||||||
|
public static T Prompt<T>(IPrompt<T> prompt)
|
||||||
|
{
|
||||||
|
if (prompt is null)
|
||||||
|
{
|
||||||
|
throw new ArgumentNullException(nameof(prompt));
|
||||||
|
}
|
||||||
|
|
||||||
|
return prompt.Show(Console);
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Displays a prompt to the user.
|
||||||
|
/// </summary>
|
||||||
|
/// <typeparam name="T">The prompt result type.</typeparam>
|
||||||
|
/// <param name="prompt">The prompt markup text.</param>
|
||||||
|
/// <returns>The prompt input result.</returns>
|
||||||
|
public static T Ask<T>(string prompt)
|
||||||
|
{
|
||||||
|
return new TextPrompt<T>(prompt).Show(Console);
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Displays a prompt with two choices, yes or no.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="prompt">The prompt markup text.</param>
|
||||||
|
/// <returns><c>true</c> if the user selected "yes", otherwise <c>false</c>.</returns>
|
||||||
|
public static bool Confirm(string prompt)
|
||||||
|
{
|
||||||
|
return new ConfirmationPrompt(prompt).Show(Console);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -14,7 +14,7 @@ namespace Spectre.Console
|
|||||||
public static Color Foreground
|
public static Color Foreground
|
||||||
{
|
{
|
||||||
get => CurrentStyle.Foreground;
|
get => CurrentStyle.Foreground;
|
||||||
set => CurrentStyle = CurrentStyle.WithForeground(value);
|
set => CurrentStyle = CurrentStyle.Foreground(value);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
@@ -23,7 +23,7 @@ namespace Spectre.Console
|
|||||||
public static Color Background
|
public static Color Background
|
||||||
{
|
{
|
||||||
get => CurrentStyle.Background;
|
get => CurrentStyle.Background;
|
||||||
set => CurrentStyle = CurrentStyle.WithBackground(value);
|
set => CurrentStyle = CurrentStyle.Background(value);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
@@ -32,7 +32,7 @@ namespace Spectre.Console
|
|||||||
public static Decoration Decoration
|
public static Decoration Decoration
|
||||||
{
|
{
|
||||||
get => CurrentStyle.Decoration;
|
get => CurrentStyle.Decoration;
|
||||||
set => CurrentStyle = CurrentStyle.WithDecoration(value);
|
set => CurrentStyle = CurrentStyle.Decoration(value);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
|
|||||||
@@ -27,6 +27,11 @@ namespace Spectre.Console
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
public static IAnsiConsole Console => _recorder ?? _console.Value;
|
public static IAnsiConsole Console => _recorder ?? _console.Value;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Gets the <see cref="IAnsiConsoleCursor"/>.
|
||||||
|
/// </summary>
|
||||||
|
public static IAnsiConsoleCursor Cursor => _recorder?.Cursor ?? _console.Value.Cursor;
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Gets the console's capabilities.
|
/// Gets the console's capabilities.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
@@ -56,7 +61,7 @@ namespace Spectre.Console
|
|||||||
/// <returns>An <see cref="IAnsiConsole"/> instance.</returns>
|
/// <returns>An <see cref="IAnsiConsole"/> instance.</returns>
|
||||||
public static IAnsiConsole Create(AnsiConsoleSettings settings)
|
public static IAnsiConsole Create(AnsiConsoleSettings settings)
|
||||||
{
|
{
|
||||||
return AnsiConsoleBuilder.Build(settings);
|
return BackendBuilder.Build(settings);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
62
src/Spectre.Console/ConfirmationPrompt.cs
Normal file
62
src/Spectre.Console/ConfirmationPrompt.cs
Normal file
@@ -0,0 +1,62 @@
|
|||||||
|
namespace Spectre.Console
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// A prompt that is answered with a yes or no.
|
||||||
|
/// </summary>
|
||||||
|
public sealed class ConfirmationPrompt : IPrompt<bool>
|
||||||
|
{
|
||||||
|
private readonly string _prompt;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Gets or sets the character that represents "yes".
|
||||||
|
/// </summary>
|
||||||
|
public char Yes { get; set; } = 'y';
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Gets or sets the character that represents "no".
|
||||||
|
/// </summary>
|
||||||
|
public char No { get; set; } = 'n';
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Gets or sets the message for invalid choices.
|
||||||
|
/// </summary>
|
||||||
|
public string InvalidChoiceMessage { get; set; } = "[red]Please select one of the available options[/]";
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Gets or sets a value indicating whether or not
|
||||||
|
/// choices should be shown.
|
||||||
|
/// </summary>
|
||||||
|
public bool ShowChoices { get; set; } = true;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Gets or sets a value indicating whether or not
|
||||||
|
/// default values should be shown.
|
||||||
|
/// </summary>
|
||||||
|
public bool ShowDefaultValue { get; set; } = true;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Initializes a new instance of the <see cref="ConfirmationPrompt"/> class.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="prompt">The prompt markup text.</param>
|
||||||
|
public ConfirmationPrompt(string prompt)
|
||||||
|
{
|
||||||
|
_prompt = prompt ?? throw new System.ArgumentNullException(nameof(prompt));
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <inheritdoc/>
|
||||||
|
public bool Show(IAnsiConsole console)
|
||||||
|
{
|
||||||
|
var prompt = new TextPrompt<char>(_prompt)
|
||||||
|
.InvalidChoiceMessage(InvalidChoiceMessage)
|
||||||
|
.ValidationErrorMessage(InvalidChoiceMessage)
|
||||||
|
.ShowChoices(ShowChoices)
|
||||||
|
.ShowDefaultValue(ShowDefaultValue)
|
||||||
|
.DefaultValue(Yes)
|
||||||
|
.AddChoice(Yes)
|
||||||
|
.AddChoice(No);
|
||||||
|
|
||||||
|
var result = prompt.Show(console);
|
||||||
|
return result == Yes;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
28
src/Spectre.Console/CursorDirection.cs
Normal file
28
src/Spectre.Console/CursorDirection.cs
Normal file
@@ -0,0 +1,28 @@
|
|||||||
|
namespace Spectre.Console
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Represents cursor direction.
|
||||||
|
/// </summary>
|
||||||
|
public enum CursorDirection
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Up
|
||||||
|
/// </summary>
|
||||||
|
Up,
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Down
|
||||||
|
/// </summary>
|
||||||
|
Down,
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Left
|
||||||
|
/// </summary>
|
||||||
|
Left,
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Right
|
||||||
|
/// </summary>
|
||||||
|
Right,
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -12,7 +12,7 @@ namespace Spectre.Console
|
|||||||
/// <param name="obj">The alignable object.</param>
|
/// <param name="obj">The alignable object.</param>
|
||||||
/// <param name="alignment">The alignment.</param>
|
/// <param name="alignment">The alignment.</param>
|
||||||
/// <returns>The same instance so that multiple calls can be chained.</returns>
|
/// <returns>The same instance so that multiple calls can be chained.</returns>
|
||||||
public static T SetAlignment<T>(this T obj, Justify alignment)
|
public static T Alignment<T>(this T obj, Justify? alignment)
|
||||||
where T : class, IAlignable
|
where T : class, IAlignable
|
||||||
{
|
{
|
||||||
if (obj is null)
|
if (obj is null)
|
||||||
|
|||||||
@@ -0,0 +1,49 @@
|
|||||||
|
using System;
|
||||||
|
|
||||||
|
namespace Spectre.Console
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Contains extension methods for <see cref="IAnsiConsole"/>.
|
||||||
|
/// </summary>
|
||||||
|
public static partial class AnsiConsoleExtensions
|
||||||
|
{
|
||||||
|
internal static string ReadLine(this IAnsiConsole console, Style? style, bool secret)
|
||||||
|
{
|
||||||
|
if (console is null)
|
||||||
|
{
|
||||||
|
throw new ArgumentNullException(nameof(console));
|
||||||
|
}
|
||||||
|
|
||||||
|
style ??= Style.Plain;
|
||||||
|
|
||||||
|
var result = string.Empty;
|
||||||
|
while (true)
|
||||||
|
{
|
||||||
|
var key = console.Input.ReadKey(true);
|
||||||
|
|
||||||
|
if (key.Key == ConsoleKey.Enter)
|
||||||
|
{
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (key.Key == ConsoleKey.Backspace)
|
||||||
|
{
|
||||||
|
if (result.Length > 0)
|
||||||
|
{
|
||||||
|
result = result.Substring(0, result.Length - 1);
|
||||||
|
console.Write("\b \b");
|
||||||
|
}
|
||||||
|
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
result += key.KeyChar.ToString();
|
||||||
|
|
||||||
|
if (!char.IsControl(key.KeyChar))
|
||||||
|
{
|
||||||
|
console.Write(secret ? "*" : key.KeyChar.ToString(), style);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,50 @@
|
|||||||
|
using System;
|
||||||
|
|
||||||
|
namespace Spectre.Console
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Contains extension methods for <see cref="IAnsiConsole"/>.
|
||||||
|
/// </summary>
|
||||||
|
public static partial class AnsiConsoleExtensions
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Displays a prompt to the user.
|
||||||
|
/// </summary>
|
||||||
|
/// <typeparam name="T">The prompt result type.</typeparam>
|
||||||
|
/// <param name="console">The console.</param>
|
||||||
|
/// <param name="prompt">The prompt to display.</param>
|
||||||
|
/// <returns>The prompt input result.</returns>
|
||||||
|
public static T Prompt<T>(this IAnsiConsole console, IPrompt<T> prompt)
|
||||||
|
{
|
||||||
|
if (prompt is null)
|
||||||
|
{
|
||||||
|
throw new ArgumentNullException(nameof(prompt));
|
||||||
|
}
|
||||||
|
|
||||||
|
return prompt.Show(console);
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Displays a prompt to the user.
|
||||||
|
/// </summary>
|
||||||
|
/// <typeparam name="T">The prompt result type.</typeparam>
|
||||||
|
/// <param name="console">The console.</param>
|
||||||
|
/// <param name="prompt">The prompt markup text.</param>
|
||||||
|
/// <returns>The prompt input result.</returns>
|
||||||
|
public static T Ask<T>(this IAnsiConsole console, string prompt)
|
||||||
|
{
|
||||||
|
return new TextPrompt<T>(prompt).Show(console);
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Displays a prompt with two choices, yes or no.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="console">The console.</param>
|
||||||
|
/// <param name="prompt">The prompt markup text.</param>
|
||||||
|
/// <returns><c>true</c> if the user selected "yes", otherwise <c>false</c>.</returns>
|
||||||
|
public static bool Confirm(this IAnsiConsole console, string prompt)
|
||||||
|
{
|
||||||
|
return new ConfirmationPrompt(prompt).Show(console);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -18,6 +18,16 @@ namespace Spectre.Console
|
|||||||
return new Recorder(console);
|
return new Recorder(console);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Writes the specified string value to the console.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="console">The console to write to.</param>
|
||||||
|
/// <param name="text">The text to write.</param>
|
||||||
|
public static void Write(this IAnsiConsole console, string text)
|
||||||
|
{
|
||||||
|
Write(console, text, Style.Plain);
|
||||||
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Writes the specified string value to the console.
|
/// Writes the specified string value to the console.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
@@ -31,6 +41,11 @@ namespace Spectre.Console
|
|||||||
throw new ArgumentNullException(nameof(console));
|
throw new ArgumentNullException(nameof(console));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (text is null)
|
||||||
|
{
|
||||||
|
throw new ArgumentNullException(nameof(text));
|
||||||
|
}
|
||||||
|
|
||||||
console.Write(new Segment(text, style));
|
console.Write(new Segment(text, style));
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -48,6 +63,16 @@ namespace Spectre.Console
|
|||||||
console.Write(Environment.NewLine, Style.Plain);
|
console.Write(Environment.NewLine, Style.Plain);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Writes the specified string value, followed by the current line terminator, to the console.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="console">The console to write to.</param>
|
||||||
|
/// <param name="text">The text to write.</param>
|
||||||
|
public static void WriteLine(this IAnsiConsole console, string text)
|
||||||
|
{
|
||||||
|
WriteLine(console, text, Style.Plain);
|
||||||
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Writes the specified string value, followed by the current line terminator, to the console.
|
/// Writes the specified string value, followed by the current line terminator, to the console.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
@@ -61,6 +86,11 @@ namespace Spectre.Console
|
|||||||
throw new ArgumentNullException(nameof(console));
|
throw new ArgumentNullException(nameof(console));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (text is null)
|
||||||
|
{
|
||||||
|
throw new ArgumentNullException(nameof(text));
|
||||||
|
}
|
||||||
|
|
||||||
console.Write(new Segment(text, style));
|
console.Write(new Segment(text, style));
|
||||||
console.WriteLine();
|
console.WriteLine();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -69,7 +69,7 @@ namespace Spectre.Console
|
|||||||
/// <param name="calendar">The calendar.</param>
|
/// <param name="calendar">The calendar.</param>
|
||||||
/// <param name="style">The highlight style.</param>
|
/// <param name="style">The highlight style.</param>
|
||||||
/// <returns>The same instance so that multiple calls can be chained.</returns>
|
/// <returns>The same instance so that multiple calls can be chained.</returns>
|
||||||
public static Calendar SetHighlightStyle(this Calendar calendar, Style? style)
|
public static Calendar HighlightStyle(this Calendar calendar, Style? style)
|
||||||
{
|
{
|
||||||
if (calendar is null)
|
if (calendar is null)
|
||||||
{
|
{
|
||||||
@@ -79,5 +79,54 @@ namespace Spectre.Console
|
|||||||
calendar.HightlightStyle = style ?? Style.Plain;
|
calendar.HightlightStyle = style ?? Style.Plain;
|
||||||
return calendar;
|
return calendar;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Sets the calendar's header <see cref="Style"/>.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="calendar">The calendar.</param>
|
||||||
|
/// <param name="style">The header style.</param>
|
||||||
|
/// <returns>The same instance so that multiple calls can be chained.</returns>
|
||||||
|
public static Calendar HeaderStyle(this Calendar calendar, Style? style)
|
||||||
|
{
|
||||||
|
if (calendar is null)
|
||||||
|
{
|
||||||
|
throw new ArgumentNullException(nameof(calendar));
|
||||||
|
}
|
||||||
|
|
||||||
|
calendar.HeaderStyle = style ?? Style.Plain;
|
||||||
|
return calendar;
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Shows the calendar header.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="calendar">The calendar.</param>
|
||||||
|
/// <returns>The same instance so that multiple calls can be chained.</returns>
|
||||||
|
public static Calendar ShowHeader(this Calendar calendar)
|
||||||
|
{
|
||||||
|
if (calendar is null)
|
||||||
|
{
|
||||||
|
throw new ArgumentNullException(nameof(calendar));
|
||||||
|
}
|
||||||
|
|
||||||
|
calendar.ShowHeader = true;
|
||||||
|
return calendar;
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Hides the calendar header.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="calendar">The calendar.</param>
|
||||||
|
/// <returns>The same instance so that multiple calls can be chained.</returns>
|
||||||
|
public static Calendar HideHeader(this Calendar calendar)
|
||||||
|
{
|
||||||
|
if (calendar is null)
|
||||||
|
{
|
||||||
|
throw new ArgumentNullException(nameof(calendar));
|
||||||
|
}
|
||||||
|
|
||||||
|
calendar.ShowHeader = false;
|
||||||
|
return calendar;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -24,5 +24,24 @@ namespace Spectre.Console
|
|||||||
obj.NoWrap = true;
|
obj.NoWrap = true;
|
||||||
return obj;
|
return obj;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Sets the width of the column.
|
||||||
|
/// </summary>
|
||||||
|
/// <typeparam name="T">An object implementing <see cref="IColumn"/>.</typeparam>
|
||||||
|
/// <param name="obj">The column.</param>
|
||||||
|
/// <param name="width">The column width.</param>
|
||||||
|
/// <returns>The same instance so that multiple calls can be chained.</returns>
|
||||||
|
public static T Width<T>(this T obj, int? width)
|
||||||
|
where T : class, IColumn
|
||||||
|
{
|
||||||
|
if (obj is null)
|
||||||
|
{
|
||||||
|
throw new ArgumentNullException(nameof(obj));
|
||||||
|
}
|
||||||
|
|
||||||
|
obj.Width = width;
|
||||||
|
return obj;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
135
src/Spectre.Console/Extensions/ConfirmationPromptExtensions.cs
Normal file
135
src/Spectre.Console/Extensions/ConfirmationPromptExtensions.cs
Normal file
@@ -0,0 +1,135 @@
|
|||||||
|
using System;
|
||||||
|
|
||||||
|
namespace Spectre.Console
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Contains extension methods for <see cref="ConfirmationPrompt"/>.
|
||||||
|
/// </summary>
|
||||||
|
public static class ConfirmationPromptExtensions
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Show or hide choices.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="obj">The prompt.</param>
|
||||||
|
/// <param name="show">Whether or not the choices should be visible.</param>
|
||||||
|
/// <returns>The same instance so that multiple calls can be chained.</returns>
|
||||||
|
public static ConfirmationPrompt ShowChoices(this ConfirmationPrompt obj, bool show)
|
||||||
|
{
|
||||||
|
if (obj is null)
|
||||||
|
{
|
||||||
|
throw new ArgumentNullException(nameof(obj));
|
||||||
|
}
|
||||||
|
|
||||||
|
obj.ShowChoices = show;
|
||||||
|
return obj;
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Shows choices.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="obj">The prompt.</param>
|
||||||
|
/// <returns>The same instance so that multiple calls can be chained.</returns>
|
||||||
|
public static ConfirmationPrompt ShowChoices(this ConfirmationPrompt obj)
|
||||||
|
{
|
||||||
|
return ShowChoices(obj, true);
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Hides choices.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="obj">The prompt.</param>
|
||||||
|
/// <returns>The same instance so that multiple calls can be chained.</returns>
|
||||||
|
public static ConfirmationPrompt HideChoices(this ConfirmationPrompt obj)
|
||||||
|
{
|
||||||
|
return ShowChoices(obj, false);
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Show or hide the default value.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="obj">The prompt.</param>
|
||||||
|
/// <param name="show">Whether or not the default value should be visible.</param>
|
||||||
|
/// <returns>The same instance so that multiple calls can be chained.</returns>
|
||||||
|
public static ConfirmationPrompt ShowDefaultValue(this ConfirmationPrompt obj, bool show)
|
||||||
|
{
|
||||||
|
if (obj is null)
|
||||||
|
{
|
||||||
|
throw new ArgumentNullException(nameof(obj));
|
||||||
|
}
|
||||||
|
|
||||||
|
obj.ShowDefaultValue = show;
|
||||||
|
return obj;
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Shows the default value.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="obj">The prompt.</param>
|
||||||
|
/// <returns>The same instance so that multiple calls can be chained.</returns>
|
||||||
|
public static ConfirmationPrompt ShowDefaultValue(this ConfirmationPrompt obj)
|
||||||
|
{
|
||||||
|
return ShowDefaultValue(obj, true);
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Hides the default value.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="obj">The prompt.</param>
|
||||||
|
/// <returns>The same instance so that multiple calls can be chained.</returns>
|
||||||
|
public static ConfirmationPrompt HideDefaultValue(this ConfirmationPrompt obj)
|
||||||
|
{
|
||||||
|
return ShowDefaultValue(obj, false);
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Sets the "invalid choice" message for the prompt.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="obj">The prompt.</param>
|
||||||
|
/// <param name="message">The "invalid choice" message.</param>
|
||||||
|
/// <returns>The same instance so that multiple calls can be chained.</returns>
|
||||||
|
public static ConfirmationPrompt InvalidChoiceMessage(this ConfirmationPrompt obj, string message)
|
||||||
|
{
|
||||||
|
if (obj is null)
|
||||||
|
{
|
||||||
|
throw new ArgumentNullException(nameof(obj));
|
||||||
|
}
|
||||||
|
|
||||||
|
obj.InvalidChoiceMessage = message;
|
||||||
|
return obj;
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Sets the character to interpret as "yes".
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="obj">The confirmation prompt.</param>
|
||||||
|
/// <param name="character">The character to interpret as "yes".</param>
|
||||||
|
/// <returns>The same instance so that multiple calls can be chained.</returns>
|
||||||
|
public static ConfirmationPrompt Yes(this ConfirmationPrompt obj, char character)
|
||||||
|
{
|
||||||
|
if (obj is null)
|
||||||
|
{
|
||||||
|
throw new ArgumentNullException(nameof(obj));
|
||||||
|
}
|
||||||
|
|
||||||
|
obj.Yes = character;
|
||||||
|
return obj;
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Sets the character to interpret as "no".
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="obj">The confirmation prompt.</param>
|
||||||
|
/// <param name="character">The character to interpret as "no".</param>
|
||||||
|
/// <returns>The same instance so that multiple calls can be chained.</returns>
|
||||||
|
public static ConfirmationPrompt No(this ConfirmationPrompt obj, char character)
|
||||||
|
{
|
||||||
|
if (obj is null)
|
||||||
|
{
|
||||||
|
throw new ArgumentNullException(nameof(obj));
|
||||||
|
}
|
||||||
|
|
||||||
|
obj.No = character;
|
||||||
|
return obj;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
152
src/Spectre.Console/Extensions/CursorExtensions.cs
Normal file
152
src/Spectre.Console/Extensions/CursorExtensions.cs
Normal file
@@ -0,0 +1,152 @@
|
|||||||
|
namespace Spectre.Console
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Contains extension methods for <see cref="IAnsiConsoleCursor"/>.
|
||||||
|
/// </summary>
|
||||||
|
public static class CursorExtensions
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Shows the cursor.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="cursor">The cursor.</param>
|
||||||
|
public static void Show(this IAnsiConsoleCursor cursor)
|
||||||
|
{
|
||||||
|
if (cursor is null)
|
||||||
|
{
|
||||||
|
throw new System.ArgumentNullException(nameof(cursor));
|
||||||
|
}
|
||||||
|
|
||||||
|
cursor.Show(true);
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Hides the cursor.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="cursor">The cursor.</param>
|
||||||
|
public static void Hide(this IAnsiConsoleCursor cursor)
|
||||||
|
{
|
||||||
|
if (cursor is null)
|
||||||
|
{
|
||||||
|
throw new System.ArgumentNullException(nameof(cursor));
|
||||||
|
}
|
||||||
|
|
||||||
|
cursor.Show(false);
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Moves the cursor up.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="cursor">The cursor.</param>
|
||||||
|
public static void MoveUp(this IAnsiConsoleCursor cursor)
|
||||||
|
{
|
||||||
|
if (cursor is null)
|
||||||
|
{
|
||||||
|
throw new System.ArgumentNullException(nameof(cursor));
|
||||||
|
}
|
||||||
|
|
||||||
|
cursor.Move(CursorDirection.Up, 1);
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Moves the cursor up.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="cursor">The cursor.</param>
|
||||||
|
/// <param name="steps">The number of steps to move the cursor.</param>
|
||||||
|
public static void MoveUp(this IAnsiConsoleCursor cursor, int steps)
|
||||||
|
{
|
||||||
|
if (cursor is null)
|
||||||
|
{
|
||||||
|
throw new System.ArgumentNullException(nameof(cursor));
|
||||||
|
}
|
||||||
|
|
||||||
|
cursor.Move(CursorDirection.Up, steps);
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Moves the cursor down.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="cursor">The cursor.</param>
|
||||||
|
public static void MoveDown(this IAnsiConsoleCursor cursor)
|
||||||
|
{
|
||||||
|
if (cursor is null)
|
||||||
|
{
|
||||||
|
throw new System.ArgumentNullException(nameof(cursor));
|
||||||
|
}
|
||||||
|
|
||||||
|
cursor.Move(CursorDirection.Down, 1);
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Moves the cursor down.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="cursor">The cursor.</param>
|
||||||
|
/// <param name="steps">The number of steps to move the cursor.</param>
|
||||||
|
public static void MoveDown(this IAnsiConsoleCursor cursor, int steps)
|
||||||
|
{
|
||||||
|
if (cursor is null)
|
||||||
|
{
|
||||||
|
throw new System.ArgumentNullException(nameof(cursor));
|
||||||
|
}
|
||||||
|
|
||||||
|
cursor.Move(CursorDirection.Down, steps);
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Moves the cursor to the left.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="cursor">The cursor.</param>
|
||||||
|
public static void MoveLeft(this IAnsiConsoleCursor cursor)
|
||||||
|
{
|
||||||
|
if (cursor is null)
|
||||||
|
{
|
||||||
|
throw new System.ArgumentNullException(nameof(cursor));
|
||||||
|
}
|
||||||
|
|
||||||
|
cursor.Move(CursorDirection.Left, 1);
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Moves the cursor to the left.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="cursor">The cursor.</param>
|
||||||
|
/// <param name="steps">The number of steps to move the cursor.</param>
|
||||||
|
public static void MoveLeft(this IAnsiConsoleCursor cursor, int steps)
|
||||||
|
{
|
||||||
|
if (cursor is null)
|
||||||
|
{
|
||||||
|
throw new System.ArgumentNullException(nameof(cursor));
|
||||||
|
}
|
||||||
|
|
||||||
|
cursor.Move(CursorDirection.Left, steps);
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Moves the cursor to the right.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="cursor">The cursor.</param>
|
||||||
|
public static void MoveRight(this IAnsiConsoleCursor cursor)
|
||||||
|
{
|
||||||
|
if (cursor is null)
|
||||||
|
{
|
||||||
|
throw new System.ArgumentNullException(nameof(cursor));
|
||||||
|
}
|
||||||
|
|
||||||
|
cursor.Move(CursorDirection.Right, 1);
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Moves the cursor to the right.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="cursor">The cursor.</param>
|
||||||
|
/// <param name="steps">The number of steps to move the cursor.</param>
|
||||||
|
public static void MoveRight(this IAnsiConsoleCursor cursor, int steps)
|
||||||
|
{
|
||||||
|
if (cursor is null)
|
||||||
|
{
|
||||||
|
throw new System.ArgumentNullException(nameof(cursor));
|
||||||
|
}
|
||||||
|
|
||||||
|
cursor.Move(CursorDirection.Right, steps);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -8,14 +8,9 @@ namespace Spectre.Console.Internal
|
|||||||
public static string GetAbbreviatedDayName(this DayOfWeek day, CultureInfo culture)
|
public static string GetAbbreviatedDayName(this DayOfWeek day, CultureInfo culture)
|
||||||
{
|
{
|
||||||
culture ??= CultureInfo.InvariantCulture;
|
culture ??= CultureInfo.InvariantCulture;
|
||||||
var name = culture.DateTimeFormat.GetAbbreviatedDayName(day);
|
return culture.DateTimeFormat
|
||||||
|
.GetAbbreviatedDayName(day)
|
||||||
if (name.Length > 0 && char.IsLower(name[0]))
|
.Capitalize(culture);
|
||||||
{
|
|
||||||
name = string.Format(culture, "{0}{1}", char.ToUpper(name[0], culture), name.Substring(1));
|
|
||||||
}
|
|
||||||
|
|
||||||
return name;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public static DayOfWeek GetNextWeekDay(this DayOfWeek day)
|
public static DayOfWeek GetNextWeekDay(this DayOfWeek day)
|
||||||
@@ -6,6 +6,21 @@ namespace Spectre.Console.Internal
|
|||||||
{
|
{
|
||||||
internal static class EnumerableExtensions
|
internal static class EnumerableExtensions
|
||||||
{
|
{
|
||||||
|
public static int GetCount<T>(this IEnumerable<T> source)
|
||||||
|
{
|
||||||
|
if (source is IList<T> list)
|
||||||
|
{
|
||||||
|
return list.Count;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (source is T[] array)
|
||||||
|
{
|
||||||
|
return array.Length;
|
||||||
|
}
|
||||||
|
|
||||||
|
return source.Count();
|
||||||
|
}
|
||||||
|
|
||||||
public static void ForEach<T>(this IEnumerable<T> source, Action<T> action)
|
public static void ForEach<T>(this IEnumerable<T> source, Action<T> action)
|
||||||
{
|
{
|
||||||
foreach (var item in source)
|
foreach (var item in source)
|
||||||
@@ -54,11 +69,13 @@ namespace Spectre.Console.Internal
|
|||||||
return source.Select((value, index) => func(value, index));
|
return source.Select((value, index) => func(value, index));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#if !NET5_0
|
||||||
public static IEnumerable<(TFirst First, TSecond Second)> Zip<TFirst, TSecond>(
|
public static IEnumerable<(TFirst First, TSecond Second)> Zip<TFirst, TSecond>(
|
||||||
this IEnumerable<TFirst> source, IEnumerable<TSecond> first)
|
this IEnumerable<TFirst> source, IEnumerable<TSecond> first)
|
||||||
{
|
{
|
||||||
return source.Zip(first, (first, second) => (first, second));
|
return source.Zip(first, (first, second) => (first, second));
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
public static IEnumerable<(TFirst First, TSecond Second, TThird Third)> Zip<TFirst, TSecond, TThird>(
|
public static IEnumerable<(TFirst First, TSecond Second, TThird Third)> Zip<TFirst, TSecond, TThird>(
|
||||||
this IEnumerable<TFirst> first, IEnumerable<TSecond> second, IEnumerable<TThird> third)
|
this IEnumerable<TFirst> first, IEnumerable<TSecond> second, IEnumerable<TThird> third)
|
||||||
@@ -1,4 +1,5 @@
|
|||||||
using System;
|
using System;
|
||||||
|
using Spectre.Console.Internal;
|
||||||
using Spectre.Console.Rendering;
|
using Spectre.Console.Rendering;
|
||||||
|
|
||||||
namespace Spectre.Console
|
namespace Spectre.Console
|
||||||
|
|||||||
@@ -17,7 +17,12 @@ namespace Spectre.Console
|
|||||||
public static T Collapse<T>(this T obj)
|
public static T Collapse<T>(this T obj)
|
||||||
where T : class, IExpandable
|
where T : class, IExpandable
|
||||||
{
|
{
|
||||||
SetExpand<T>(obj, false);
|
if (obj is null)
|
||||||
|
{
|
||||||
|
throw new ArgumentNullException(nameof(obj));
|
||||||
|
}
|
||||||
|
|
||||||
|
obj.Expand = false;
|
||||||
return obj;
|
return obj;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -29,20 +34,14 @@ namespace Spectre.Console
|
|||||||
/// <returns>The same instance so that multiple calls can be chained.</returns>
|
/// <returns>The same instance so that multiple calls can be chained.</returns>
|
||||||
public static T Expand<T>(this T obj)
|
public static T Expand<T>(this T obj)
|
||||||
where T : class, IExpandable
|
where T : class, IExpandable
|
||||||
{
|
|
||||||
SetExpand<T>(obj, true);
|
|
||||||
return obj;
|
|
||||||
}
|
|
||||||
|
|
||||||
private static void SetExpand<T>(T obj, bool value)
|
|
||||||
where T : class, IExpandable
|
|
||||||
{
|
{
|
||||||
if (obj is null)
|
if (obj is null)
|
||||||
{
|
{
|
||||||
throw new ArgumentNullException(nameof(obj));
|
throw new ArgumentNullException(nameof(obj));
|
||||||
}
|
}
|
||||||
|
|
||||||
obj.Expand = value;
|
obj.Expand = true;
|
||||||
|
return obj;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -69,8 +69,8 @@ namespace Spectre.Console
|
|||||||
throw new ArgumentNullException(nameof(grid));
|
throw new ArgumentNullException(nameof(grid));
|
||||||
}
|
}
|
||||||
|
|
||||||
var columns = new IRenderable[grid.ColumnCount];
|
var columns = new IRenderable[grid.Columns.Count];
|
||||||
Enumerable.Range(0, grid.ColumnCount).ForEach(index => columns[index] = Text.Empty);
|
Enumerable.Range(0, grid.Columns.Count).ForEach(index => columns[index] = Text.Empty);
|
||||||
grid.AddRow(columns);
|
grid.AddRow(columns);
|
||||||
|
|
||||||
return grid;
|
return grid;
|
||||||
|
|||||||
@@ -7,11 +7,29 @@ namespace Spectre.Console
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
public static class HasBorderExtensions
|
public static class HasBorderExtensions
|
||||||
{
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Enables the safe border.
|
||||||
|
/// </summary>
|
||||||
|
/// <typeparam name="T">An object type with a border.</typeparam>
|
||||||
|
/// <param name="obj">The object to enable the safe border for.</param>
|
||||||
|
/// <returns>The same instance so that multiple calls can be chained.</returns>
|
||||||
|
public static T SafeBorder<T>(this T obj)
|
||||||
|
where T : class, IHasBorder
|
||||||
|
{
|
||||||
|
if (obj is null)
|
||||||
|
{
|
||||||
|
throw new ArgumentNullException(nameof(obj));
|
||||||
|
}
|
||||||
|
|
||||||
|
obj.UseSafeBorder = true;
|
||||||
|
return obj;
|
||||||
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Disables the safe border.
|
/// Disables the safe border.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <typeparam name="T">An object type with a border.</typeparam>
|
/// <typeparam name="T">An object type with a border.</typeparam>
|
||||||
/// <param name="obj">The object to set the border for.</param>
|
/// <param name="obj">The object to disable the safe border for.</param>
|
||||||
/// <returns>The same instance so that multiple calls can be chained.</returns>
|
/// <returns>The same instance so that multiple calls can be chained.</returns>
|
||||||
public static T NoSafeBorder<T>(this T obj)
|
public static T NoSafeBorder<T>(this T obj)
|
||||||
where T : class, IHasBorder
|
where T : class, IHasBorder
|
||||||
@@ -29,10 +47,10 @@ namespace Spectre.Console
|
|||||||
/// Sets the border style.
|
/// Sets the border style.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <typeparam name="T">An object type with a border.</typeparam>
|
/// <typeparam name="T">An object type with a border.</typeparam>
|
||||||
/// <param name="obj">The object to set the border color for.</param>
|
/// <param name="obj">The object to set the border style for.</param>
|
||||||
/// <param name="style">The border style to set.</param>
|
/// <param name="style">The border style to set.</param>
|
||||||
/// <returns>The same instance so that multiple calls can be chained.</returns>
|
/// <returns>The same instance so that multiple calls can be chained.</returns>
|
||||||
public static T SetBorderStyle<T>(this T obj, Style style)
|
public static T BorderStyle<T>(this T obj, Style style)
|
||||||
where T : class, IHasBorder
|
where T : class, IHasBorder
|
||||||
{
|
{
|
||||||
if (obj is null)
|
if (obj is null)
|
||||||
@@ -51,7 +69,7 @@ namespace Spectre.Console
|
|||||||
/// <param name="obj">The object to set the border color for.</param>
|
/// <param name="obj">The object to set the border color for.</param>
|
||||||
/// <param name="color">The border color to set.</param>
|
/// <param name="color">The border color to set.</param>
|
||||||
/// <returns>The same instance so that multiple calls can be chained.</returns>
|
/// <returns>The same instance so that multiple calls can be chained.</returns>
|
||||||
public static T SetBorderColor<T>(this T obj, Color color)
|
public static T BorderColor<T>(this T obj, Color color)
|
||||||
where T : class, IHasBorder
|
where T : class, IHasBorder
|
||||||
{
|
{
|
||||||
if (obj is null)
|
if (obj is null)
|
||||||
@@ -59,7 +77,7 @@ namespace Spectre.Console
|
|||||||
throw new ArgumentNullException(nameof(obj));
|
throw new ArgumentNullException(nameof(obj));
|
||||||
}
|
}
|
||||||
|
|
||||||
obj.BorderStyle = (obj.BorderStyle ?? Style.Plain).WithForeground(color);
|
obj.BorderStyle = (obj.BorderStyle ?? Style.Plain).Foreground(color);
|
||||||
return obj;
|
return obj;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -7,6 +7,25 @@ namespace Spectre.Console
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
public static class HasBoxBorderExtensions
|
public static class HasBoxBorderExtensions
|
||||||
{
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Sets the border.
|
||||||
|
/// </summary>
|
||||||
|
/// <typeparam name="T">An object type with a border.</typeparam>
|
||||||
|
/// <param name="obj">The object to set the border for.</param>
|
||||||
|
/// <param name="border">The border to use.</param>
|
||||||
|
/// <returns>The same instance so that multiple calls can be chained.</returns>
|
||||||
|
public static T Border<T>(this T obj, BoxBorder border)
|
||||||
|
where T : class, IHasBoxBorder
|
||||||
|
{
|
||||||
|
if (obj is null)
|
||||||
|
{
|
||||||
|
throw new ArgumentNullException(nameof(obj));
|
||||||
|
}
|
||||||
|
|
||||||
|
obj.Border = border;
|
||||||
|
return obj;
|
||||||
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Do not display a border.
|
/// Do not display a border.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
@@ -16,7 +35,7 @@ namespace Spectre.Console
|
|||||||
public static T NoBorder<T>(this T obj)
|
public static T NoBorder<T>(this T obj)
|
||||||
where T : class, IHasBoxBorder
|
where T : class, IHasBoxBorder
|
||||||
{
|
{
|
||||||
return SetBorder(obj, BoxBorder.None);
|
return Border(obj, BoxBorder.None);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
@@ -28,7 +47,7 @@ namespace Spectre.Console
|
|||||||
public static T SquareBorder<T>(this T obj)
|
public static T SquareBorder<T>(this T obj)
|
||||||
where T : class, IHasBoxBorder
|
where T : class, IHasBoxBorder
|
||||||
{
|
{
|
||||||
return SetBorder(obj, BoxBorder.Square);
|
return Border(obj, BoxBorder.Square);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
@@ -40,7 +59,7 @@ namespace Spectre.Console
|
|||||||
public static T AsciiBorder<T>(this T obj)
|
public static T AsciiBorder<T>(this T obj)
|
||||||
where T : class, IHasBoxBorder
|
where T : class, IHasBoxBorder
|
||||||
{
|
{
|
||||||
return SetBorder(obj, BoxBorder.Ascii);
|
return Border(obj, BoxBorder.Ascii);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
@@ -52,7 +71,7 @@ namespace Spectre.Console
|
|||||||
public static T RoundedBorder<T>(this T obj)
|
public static T RoundedBorder<T>(this T obj)
|
||||||
where T : class, IHasBoxBorder
|
where T : class, IHasBoxBorder
|
||||||
{
|
{
|
||||||
return SetBorder(obj, BoxBorder.Rounded);
|
return Border(obj, BoxBorder.Rounded);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
@@ -64,7 +83,7 @@ namespace Spectre.Console
|
|||||||
public static T HeavyBorder<T>(this T obj)
|
public static T HeavyBorder<T>(this T obj)
|
||||||
where T : class, IHasBoxBorder
|
where T : class, IHasBoxBorder
|
||||||
{
|
{
|
||||||
return SetBorder(obj, BoxBorder.Heavy);
|
return Border(obj, BoxBorder.Heavy);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
@@ -76,26 +95,7 @@ namespace Spectre.Console
|
|||||||
public static T DoubleBorder<T>(this T obj)
|
public static T DoubleBorder<T>(this T obj)
|
||||||
where T : class, IHasBoxBorder
|
where T : class, IHasBoxBorder
|
||||||
{
|
{
|
||||||
return SetBorder(obj, BoxBorder.Double);
|
return Border(obj, BoxBorder.Double);
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Sets the border.
|
|
||||||
/// </summary>
|
|
||||||
/// <typeparam name="T">An object type with a border.</typeparam>
|
|
||||||
/// <param name="obj">The object to set the border for.</param>
|
|
||||||
/// <param name="border">The border to use.</param>
|
|
||||||
/// <returns>The same instance so that multiple calls can be chained.</returns>
|
|
||||||
public static T SetBorder<T>(this T obj, BoxBorder border)
|
|
||||||
where T : class, IHasBoxBorder
|
|
||||||
{
|
|
||||||
if (obj is null)
|
|
||||||
{
|
|
||||||
throw new ArgumentNullException(nameof(obj));
|
|
||||||
}
|
|
||||||
|
|
||||||
obj.Border = border;
|
|
||||||
return obj;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -15,7 +15,7 @@ namespace Spectre.Console
|
|||||||
/// <param name="obj">The object to set the culture for.</param>
|
/// <param name="obj">The object to set the culture for.</param>
|
||||||
/// <param name="culture">The culture to set.</param>
|
/// <param name="culture">The culture to set.</param>
|
||||||
/// <returns>The same instance so that multiple calls can be chained.</returns>
|
/// <returns>The same instance so that multiple calls can be chained.</returns>
|
||||||
public static T SetCulture<T>(this T obj, CultureInfo culture)
|
public static T Culture<T>(this T obj, CultureInfo culture)
|
||||||
where T : class, IHasCulture
|
where T : class, IHasCulture
|
||||||
{
|
{
|
||||||
if (obj is null)
|
if (obj is null)
|
||||||
@@ -39,16 +39,15 @@ namespace Spectre.Console
|
|||||||
/// <param name="obj">The object to set the culture for.</param>
|
/// <param name="obj">The object to set the culture for.</param>
|
||||||
/// <param name="name">The culture to set.</param>
|
/// <param name="name">The culture to set.</param>
|
||||||
/// <returns>The same instance so that multiple calls can be chained.</returns>
|
/// <returns>The same instance so that multiple calls can be chained.</returns>
|
||||||
public static T SetCulture<T>(this T obj, string name)
|
public static T Culture<T>(this T obj, string name)
|
||||||
where T : class, IHasCulture
|
where T : class, IHasCulture
|
||||||
{
|
{
|
||||||
if (obj is null)
|
if (name is null)
|
||||||
{
|
{
|
||||||
throw new ArgumentNullException(nameof(obj));
|
throw new ArgumentNullException(nameof(name));
|
||||||
}
|
}
|
||||||
|
|
||||||
obj.Culture = CultureInfo.GetCultureInfo(name);
|
return Culture(obj, CultureInfo.GetCultureInfo(name));
|
||||||
return obj;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
@@ -56,18 +55,12 @@ namespace Spectre.Console
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
/// <typeparam name="T">An object type with a culture.</typeparam>
|
/// <typeparam name="T">An object type with a culture.</typeparam>
|
||||||
/// <param name="obj">The object to set the culture for.</param>
|
/// <param name="obj">The object to set the culture for.</param>
|
||||||
/// <param name="name">The culture to set.</param>
|
/// <param name="culture">The culture to set.</param>
|
||||||
/// <returns>The same instance so that multiple calls can be chained.</returns>
|
/// <returns>The same instance so that multiple calls can be chained.</returns>
|
||||||
public static T SetCulture<T>(this T obj, int name)
|
public static T Culture<T>(this T obj, int culture)
|
||||||
where T : class, IHasCulture
|
where T : class, IHasCulture
|
||||||
{
|
{
|
||||||
if (obj is null)
|
return Culture(obj, CultureInfo.GetCultureInfo(culture));
|
||||||
{
|
|
||||||
throw new ArgumentNullException(nameof(obj));
|
|
||||||
}
|
|
||||||
|
|
||||||
obj.Culture = CultureInfo.GetCultureInfo(name);
|
|
||||||
return obj;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -16,7 +16,7 @@ namespace Spectre.Console
|
|||||||
public static T NoBorder<T>(this T obj)
|
public static T NoBorder<T>(this T obj)
|
||||||
where T : class, IHasTableBorder
|
where T : class, IHasTableBorder
|
||||||
{
|
{
|
||||||
return SetBorder(obj, TableBorder.None);
|
return Border(obj, TableBorder.None);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
@@ -28,7 +28,7 @@ namespace Spectre.Console
|
|||||||
public static T SquareBorder<T>(this T obj)
|
public static T SquareBorder<T>(this T obj)
|
||||||
where T : class, IHasTableBorder
|
where T : class, IHasTableBorder
|
||||||
{
|
{
|
||||||
return SetBorder(obj, TableBorder.Square);
|
return Border(obj, TableBorder.Square);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
@@ -40,7 +40,7 @@ namespace Spectre.Console
|
|||||||
public static T AsciiBorder<T>(this T obj)
|
public static T AsciiBorder<T>(this T obj)
|
||||||
where T : class, IHasTableBorder
|
where T : class, IHasTableBorder
|
||||||
{
|
{
|
||||||
return SetBorder(obj, TableBorder.Ascii);
|
return Border(obj, TableBorder.Ascii);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
@@ -52,7 +52,7 @@ namespace Spectre.Console
|
|||||||
public static T Ascii2Border<T>(this T obj)
|
public static T Ascii2Border<T>(this T obj)
|
||||||
where T : class, IHasTableBorder
|
where T : class, IHasTableBorder
|
||||||
{
|
{
|
||||||
return SetBorder(obj, TableBorder.Ascii2);
|
return Border(obj, TableBorder.Ascii2);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
@@ -64,7 +64,7 @@ namespace Spectre.Console
|
|||||||
public static T AsciiDoubleHeadBorder<T>(this T obj)
|
public static T AsciiDoubleHeadBorder<T>(this T obj)
|
||||||
where T : class, IHasTableBorder
|
where T : class, IHasTableBorder
|
||||||
{
|
{
|
||||||
return SetBorder(obj, TableBorder.AsciiDoubleHead);
|
return Border(obj, TableBorder.AsciiDoubleHead);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
@@ -76,7 +76,7 @@ namespace Spectre.Console
|
|||||||
public static T RoundedBorder<T>(this T obj)
|
public static T RoundedBorder<T>(this T obj)
|
||||||
where T : class, IHasTableBorder
|
where T : class, IHasTableBorder
|
||||||
{
|
{
|
||||||
return SetBorder(obj, TableBorder.Rounded);
|
return Border(obj, TableBorder.Rounded);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
@@ -88,7 +88,7 @@ namespace Spectre.Console
|
|||||||
public static T MinimalBorder<T>(this T obj)
|
public static T MinimalBorder<T>(this T obj)
|
||||||
where T : class, IHasTableBorder
|
where T : class, IHasTableBorder
|
||||||
{
|
{
|
||||||
return SetBorder(obj, TableBorder.Minimal);
|
return Border(obj, TableBorder.Minimal);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
@@ -100,7 +100,7 @@ namespace Spectre.Console
|
|||||||
public static T MinimalHeavyHeadBorder<T>(this T obj)
|
public static T MinimalHeavyHeadBorder<T>(this T obj)
|
||||||
where T : class, IHasTableBorder
|
where T : class, IHasTableBorder
|
||||||
{
|
{
|
||||||
return SetBorder(obj, TableBorder.MinimalHeavyHead);
|
return Border(obj, TableBorder.MinimalHeavyHead);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
@@ -112,7 +112,7 @@ namespace Spectre.Console
|
|||||||
public static T MinimalDoubleHeadBorder<T>(this T obj)
|
public static T MinimalDoubleHeadBorder<T>(this T obj)
|
||||||
where T : class, IHasTableBorder
|
where T : class, IHasTableBorder
|
||||||
{
|
{
|
||||||
return SetBorder(obj, TableBorder.MinimalDoubleHead);
|
return Border(obj, TableBorder.MinimalDoubleHead);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
@@ -124,7 +124,7 @@ namespace Spectre.Console
|
|||||||
public static T SimpleBorder<T>(this T obj)
|
public static T SimpleBorder<T>(this T obj)
|
||||||
where T : class, IHasTableBorder
|
where T : class, IHasTableBorder
|
||||||
{
|
{
|
||||||
return SetBorder(obj, TableBorder.Simple);
|
return Border(obj, TableBorder.Simple);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
@@ -136,7 +136,7 @@ namespace Spectre.Console
|
|||||||
public static T SimpleHeavyBorder<T>(this T obj)
|
public static T SimpleHeavyBorder<T>(this T obj)
|
||||||
where T : class, IHasTableBorder
|
where T : class, IHasTableBorder
|
||||||
{
|
{
|
||||||
return SetBorder(obj, TableBorder.SimpleHeavy);
|
return Border(obj, TableBorder.SimpleHeavy);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
@@ -148,7 +148,7 @@ namespace Spectre.Console
|
|||||||
public static T HorizontalBorder<T>(this T obj)
|
public static T HorizontalBorder<T>(this T obj)
|
||||||
where T : class, IHasTableBorder
|
where T : class, IHasTableBorder
|
||||||
{
|
{
|
||||||
return SetBorder(obj, TableBorder.Horizontal);
|
return Border(obj, TableBorder.Horizontal);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
@@ -160,7 +160,7 @@ namespace Spectre.Console
|
|||||||
public static T HeavyBorder<T>(this T obj)
|
public static T HeavyBorder<T>(this T obj)
|
||||||
where T : class, IHasTableBorder
|
where T : class, IHasTableBorder
|
||||||
{
|
{
|
||||||
return SetBorder(obj, TableBorder.Heavy);
|
return Border(obj, TableBorder.Heavy);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
@@ -172,7 +172,7 @@ namespace Spectre.Console
|
|||||||
public static T HeavyEdgeBorder<T>(this T obj)
|
public static T HeavyEdgeBorder<T>(this T obj)
|
||||||
where T : class, IHasTableBorder
|
where T : class, IHasTableBorder
|
||||||
{
|
{
|
||||||
return SetBorder(obj, TableBorder.HeavyEdge);
|
return Border(obj, TableBorder.HeavyEdge);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
@@ -184,7 +184,7 @@ namespace Spectre.Console
|
|||||||
public static T HeavyHeadBorder<T>(this T obj)
|
public static T HeavyHeadBorder<T>(this T obj)
|
||||||
where T : class, IHasTableBorder
|
where T : class, IHasTableBorder
|
||||||
{
|
{
|
||||||
return SetBorder(obj, TableBorder.HeavyHead);
|
return Border(obj, TableBorder.HeavyHead);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
@@ -196,7 +196,7 @@ namespace Spectre.Console
|
|||||||
public static T DoubleBorder<T>(this T obj)
|
public static T DoubleBorder<T>(this T obj)
|
||||||
where T : class, IHasTableBorder
|
where T : class, IHasTableBorder
|
||||||
{
|
{
|
||||||
return SetBorder(obj, TableBorder.Double);
|
return Border(obj, TableBorder.Double);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
@@ -208,7 +208,7 @@ namespace Spectre.Console
|
|||||||
public static T DoubleEdgeBorder<T>(this T obj)
|
public static T DoubleEdgeBorder<T>(this T obj)
|
||||||
where T : class, IHasTableBorder
|
where T : class, IHasTableBorder
|
||||||
{
|
{
|
||||||
return SetBorder(obj, TableBorder.DoubleEdge);
|
return Border(obj, TableBorder.DoubleEdge);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
@@ -220,7 +220,7 @@ namespace Spectre.Console
|
|||||||
public static T MarkdownBorder<T>(this T obj)
|
public static T MarkdownBorder<T>(this T obj)
|
||||||
where T : class, IHasTableBorder
|
where T : class, IHasTableBorder
|
||||||
{
|
{
|
||||||
return SetBorder(obj, TableBorder.Markdown);
|
return Border(obj, TableBorder.Markdown);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
@@ -230,7 +230,7 @@ namespace Spectre.Console
|
|||||||
/// <param name="obj">The object to set the border for.</param>
|
/// <param name="obj">The object to set the border for.</param>
|
||||||
/// <param name="border">The border to use.</param>
|
/// <param name="border">The border to use.</param>
|
||||||
/// <returns>The same instance so that multiple calls can be chained.</returns>
|
/// <returns>The same instance so that multiple calls can be chained.</returns>
|
||||||
public static T SetBorder<T>(this T obj, TableBorder border)
|
public static T Border<T>(this T obj, TableBorder border)
|
||||||
where T : class, IHasTableBorder
|
where T : class, IHasTableBorder
|
||||||
{
|
{
|
||||||
if (obj is null)
|
if (obj is null)
|
||||||
|
|||||||
@@ -0,0 +1,32 @@
|
|||||||
|
using System;
|
||||||
|
using System.ComponentModel;
|
||||||
|
|
||||||
|
namespace Spectre.Console
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Contains extension methods for <see cref="IAlignable"/>.
|
||||||
|
/// </summary>
|
||||||
|
public static class ObsoleteAlignableExtensions
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Sets the alignment for an <see cref="IAlignable"/> object.
|
||||||
|
/// </summary>
|
||||||
|
/// <typeparam name="T">The alignable object type.</typeparam>
|
||||||
|
/// <param name="obj">The alignable object.</param>
|
||||||
|
/// <param name="alignment">The alignment.</param>
|
||||||
|
/// <returns>The same instance so that multiple calls can be chained.</returns>
|
||||||
|
[Obsolete("Use Alignment(..) instead.")]
|
||||||
|
[EditorBrowsable(EditorBrowsableState.Never)]
|
||||||
|
public static T SetAlignment<T>(this T obj, Justify alignment)
|
||||||
|
where T : class, IAlignable
|
||||||
|
{
|
||||||
|
if (obj is null)
|
||||||
|
{
|
||||||
|
throw new System.ArgumentNullException(nameof(obj));
|
||||||
|
}
|
||||||
|
|
||||||
|
obj.Alignment = alignment;
|
||||||
|
return obj;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,49 @@
|
|||||||
|
using System;
|
||||||
|
using System.ComponentModel;
|
||||||
|
|
||||||
|
namespace Spectre.Console
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Contains extension methods for <see cref="Calendar"/>.
|
||||||
|
/// </summary>
|
||||||
|
public static class ObsoleteCalendarExtensions
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Sets the calendar's highlight <see cref="Style"/>.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="calendar">The calendar.</param>
|
||||||
|
/// <param name="style">The highlight style.</param>
|
||||||
|
/// <returns>The same instance so that multiple calls can be chained.</returns>
|
||||||
|
[Obsolete("Use HighlightStyle(..) instead.")]
|
||||||
|
[EditorBrowsable(EditorBrowsableState.Never)]
|
||||||
|
public static Calendar SetHighlightStyle(this Calendar calendar, Style? style)
|
||||||
|
{
|
||||||
|
if (calendar is null)
|
||||||
|
{
|
||||||
|
throw new ArgumentNullException(nameof(calendar));
|
||||||
|
}
|
||||||
|
|
||||||
|
calendar.HightlightStyle = style ?? Style.Plain;
|
||||||
|
return calendar;
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Sets the calendar's header <see cref="Style"/>.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="calendar">The calendar.</param>
|
||||||
|
/// <param name="style">The header style.</param>
|
||||||
|
/// <returns>The same instance so that multiple calls can be chained.</returns>
|
||||||
|
[Obsolete("Use HeaderStyle(..) instead.")]
|
||||||
|
[EditorBrowsable(EditorBrowsableState.Never)]
|
||||||
|
public static Calendar SetHeaderStyle(this Calendar calendar, Style? style)
|
||||||
|
{
|
||||||
|
if (calendar is null)
|
||||||
|
{
|
||||||
|
throw new ArgumentNullException(nameof(calendar));
|
||||||
|
}
|
||||||
|
|
||||||
|
calendar.HeaderStyle = style ?? Style.Plain;
|
||||||
|
return calendar;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,53 @@
|
|||||||
|
using System;
|
||||||
|
using System.ComponentModel;
|
||||||
|
|
||||||
|
namespace Spectre.Console
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Contains extension methods for <see cref="IHasBorder"/>.
|
||||||
|
/// </summary>
|
||||||
|
public static class ObsoleteHasBorderExtensions
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Sets the border style.
|
||||||
|
/// </summary>
|
||||||
|
/// <typeparam name="T">An object type with a border.</typeparam>
|
||||||
|
/// <param name="obj">The object to set the border color for.</param>
|
||||||
|
/// <param name="style">The border style to set.</param>
|
||||||
|
/// <returns>The same instance so that multiple calls can be chained.</returns>
|
||||||
|
[Obsolete("Use BorderStyle(..) instead.")]
|
||||||
|
[EditorBrowsable(EditorBrowsableState.Never)]
|
||||||
|
public static T SetBorderStyle<T>(this T obj, Style style)
|
||||||
|
where T : class, IHasBorder
|
||||||
|
{
|
||||||
|
if (obj is null)
|
||||||
|
{
|
||||||
|
throw new ArgumentNullException(nameof(obj));
|
||||||
|
}
|
||||||
|
|
||||||
|
obj.BorderStyle = style;
|
||||||
|
return obj;
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Sets the border color.
|
||||||
|
/// </summary>
|
||||||
|
/// <typeparam name="T">An object type with a border.</typeparam>
|
||||||
|
/// <param name="obj">The object to set the border color for.</param>
|
||||||
|
/// <param name="color">The border color to set.</param>
|
||||||
|
/// <returns>The same instance so that multiple calls can be chained.</returns>
|
||||||
|
[Obsolete("Use BorderColor(..) instead.")]
|
||||||
|
[EditorBrowsable(EditorBrowsableState.Never)]
|
||||||
|
public static T SetBorderColor<T>(this T obj, Color color)
|
||||||
|
where T : class, IHasBorder
|
||||||
|
{
|
||||||
|
if (obj is null)
|
||||||
|
{
|
||||||
|
throw new ArgumentNullException(nameof(obj));
|
||||||
|
}
|
||||||
|
|
||||||
|
obj.BorderStyle = (obj.BorderStyle ?? Style.Plain).Foreground(color);
|
||||||
|
return obj;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,32 @@
|
|||||||
|
using System;
|
||||||
|
using System.ComponentModel;
|
||||||
|
|
||||||
|
namespace Spectre.Console
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Contains extension methods for <see cref="IHasBoxBorder"/>.
|
||||||
|
/// </summary>
|
||||||
|
public static class ObsoleteHasBoxBorderExtensions
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Sets the border.
|
||||||
|
/// </summary>
|
||||||
|
/// <typeparam name="T">An object type with a border.</typeparam>
|
||||||
|
/// <param name="obj">The object to set the border for.</param>
|
||||||
|
/// <param name="border">The border to use.</param>
|
||||||
|
/// <returns>The same instance so that multiple calls can be chained.</returns>
|
||||||
|
[Obsolete("Use Border(..) instead.")]
|
||||||
|
[EditorBrowsable(EditorBrowsableState.Never)]
|
||||||
|
public static T SetBorder<T>(this T obj, BoxBorder border)
|
||||||
|
where T : class, IHasBoxBorder
|
||||||
|
{
|
||||||
|
if (obj is null)
|
||||||
|
{
|
||||||
|
throw new ArgumentNullException(nameof(obj));
|
||||||
|
}
|
||||||
|
|
||||||
|
obj.Border = border;
|
||||||
|
return obj;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,80 @@
|
|||||||
|
using System;
|
||||||
|
using System.ComponentModel;
|
||||||
|
using System.Globalization;
|
||||||
|
|
||||||
|
namespace Spectre.Console
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Contains extension methods for <see cref="IHasCulture"/>.
|
||||||
|
/// </summary>
|
||||||
|
public static class ObsoleteHasCultureExtensions
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Sets the culture.
|
||||||
|
/// </summary>
|
||||||
|
/// <typeparam name="T">An object type with a culture.</typeparam>
|
||||||
|
/// <param name="obj">The object to set the culture for.</param>
|
||||||
|
/// <param name="culture">The culture to set.</param>
|
||||||
|
/// <returns>The same instance so that multiple calls can be chained.</returns>
|
||||||
|
[Obsolete("Use Culture(..) instead.")]
|
||||||
|
[EditorBrowsable(EditorBrowsableState.Never)]
|
||||||
|
public static T SetCulture<T>(this T obj, CultureInfo culture)
|
||||||
|
where T : class, IHasCulture
|
||||||
|
{
|
||||||
|
if (obj is null)
|
||||||
|
{
|
||||||
|
throw new ArgumentNullException(nameof(obj));
|
||||||
|
}
|
||||||
|
|
||||||
|
if (culture is null)
|
||||||
|
{
|
||||||
|
throw new ArgumentNullException(nameof(culture));
|
||||||
|
}
|
||||||
|
|
||||||
|
obj.Culture = culture;
|
||||||
|
return obj;
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Sets the culture.
|
||||||
|
/// </summary>
|
||||||
|
/// <typeparam name="T">An object type with a culture.</typeparam>
|
||||||
|
/// <param name="obj">The object to set the culture for.</param>
|
||||||
|
/// <param name="name">The culture to set.</param>
|
||||||
|
/// <returns>The same instance so that multiple calls can be chained.</returns>
|
||||||
|
[Obsolete("Use Culture(..) instead.")]
|
||||||
|
[EditorBrowsable(EditorBrowsableState.Never)]
|
||||||
|
public static T SetCulture<T>(this T obj, string name)
|
||||||
|
where T : class, IHasCulture
|
||||||
|
{
|
||||||
|
if (obj is null)
|
||||||
|
{
|
||||||
|
throw new ArgumentNullException(nameof(obj));
|
||||||
|
}
|
||||||
|
|
||||||
|
obj.Culture = CultureInfo.GetCultureInfo(name);
|
||||||
|
return obj;
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Sets the culture.
|
||||||
|
/// </summary>
|
||||||
|
/// <typeparam name="T">An object type with a culture.</typeparam>
|
||||||
|
/// <param name="obj">The object to set the culture for.</param>
|
||||||
|
/// <param name="name">The culture to set.</param>
|
||||||
|
/// <returns>The same instance so that multiple calls can be chained.</returns>
|
||||||
|
[Obsolete("Use Culture(..) instead.")]
|
||||||
|
[EditorBrowsable(EditorBrowsableState.Never)]
|
||||||
|
public static T SetCulture<T>(this T obj, int name)
|
||||||
|
where T : class, IHasCulture
|
||||||
|
{
|
||||||
|
if (obj is null)
|
||||||
|
{
|
||||||
|
throw new ArgumentNullException(nameof(obj));
|
||||||
|
}
|
||||||
|
|
||||||
|
obj.Culture = CultureInfo.GetCultureInfo(name);
|
||||||
|
return obj;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,32 @@
|
|||||||
|
using System;
|
||||||
|
using System.ComponentModel;
|
||||||
|
|
||||||
|
namespace Spectre.Console
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Contains extension methods for <see cref="IHasTableBorder"/>.
|
||||||
|
/// </summary>
|
||||||
|
public static class ObsoleteHasTableBorderExtensions
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Sets the border.
|
||||||
|
/// </summary>
|
||||||
|
/// <typeparam name="T">An object type with a border.</typeparam>
|
||||||
|
/// <param name="obj">The object to set the border for.</param>
|
||||||
|
/// <param name="border">The border to use.</param>
|
||||||
|
/// <returns>The same instance so that multiple calls can be chained.</returns>
|
||||||
|
[Obsolete("Use Border(..) instead.")]
|
||||||
|
[EditorBrowsable(EditorBrowsableState.Never)]
|
||||||
|
public static T SetBorder<T>(this T obj, TableBorder border)
|
||||||
|
where T : class, IHasTableBorder
|
||||||
|
{
|
||||||
|
if (obj is null)
|
||||||
|
{
|
||||||
|
throw new ArgumentNullException(nameof(obj));
|
||||||
|
}
|
||||||
|
|
||||||
|
obj.Border = border;
|
||||||
|
return obj;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,32 @@
|
|||||||
|
using System;
|
||||||
|
using System.ComponentModel;
|
||||||
|
|
||||||
|
namespace Spectre.Console
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Contains extension methods for <see cref="IOverflowable"/>.
|
||||||
|
/// </summary>
|
||||||
|
public static class ObsoleteOverflowableExtensions
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Sets the overflow strategy.
|
||||||
|
/// </summary>
|
||||||
|
/// <typeparam name="T">An object implementing <see cref="IOverflowable"/>.</typeparam>
|
||||||
|
/// <param name="obj">The overflowable object instance.</param>
|
||||||
|
/// <param name="overflow">The overflow strategy to use.</param>
|
||||||
|
/// <returns>The same instance so that multiple calls can be chained.</returns>
|
||||||
|
[Obsolete("Use Overflow(..) instead.")]
|
||||||
|
[EditorBrowsable(EditorBrowsableState.Never)]
|
||||||
|
public static T SetOverflow<T>(this T obj, Overflow overflow)
|
||||||
|
where T : class, IOverflowable
|
||||||
|
{
|
||||||
|
if (obj is null)
|
||||||
|
{
|
||||||
|
throw new ArgumentNullException(nameof(obj));
|
||||||
|
}
|
||||||
|
|
||||||
|
obj.Overflow = overflow;
|
||||||
|
return obj;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,50 @@
|
|||||||
|
using System;
|
||||||
|
using System.ComponentModel;
|
||||||
|
|
||||||
|
namespace Spectre.Console
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Contains extension methods for <see cref="IPaddable"/>.
|
||||||
|
/// </summary>
|
||||||
|
public static class ObsoletePaddableExtensions
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Sets the left and right padding.
|
||||||
|
/// </summary>
|
||||||
|
/// <typeparam name="T">An object implementing <see cref="IPaddable"/>.</typeparam>
|
||||||
|
/// <param name="obj">The paddable object instance.</param>
|
||||||
|
/// <param name="left">The left padding to apply.</param>
|
||||||
|
/// <param name="top">The top padding to apply.</param>
|
||||||
|
/// <param name="right">The right padding to apply.</param>
|
||||||
|
/// <param name="bottom">The bottom padding to apply.</param>
|
||||||
|
/// <returns>The same instance so that multiple calls can be chained.</returns>
|
||||||
|
[Obsolete("Use Padding(..) instead.")]
|
||||||
|
[EditorBrowsable(EditorBrowsableState.Never)]
|
||||||
|
public static T SetPadding<T>(this T obj, int left, int top, int right, int bottom)
|
||||||
|
where T : class, IPaddable
|
||||||
|
{
|
||||||
|
return SetPadding(obj, new Padding(left, top, right, bottom));
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Sets the padding.
|
||||||
|
/// </summary>
|
||||||
|
/// <typeparam name="T">An object implementing <see cref="IPaddable"/>.</typeparam>
|
||||||
|
/// <param name="obj">The paddable object instance.</param>
|
||||||
|
/// <param name="padding">The padding to apply.</param>
|
||||||
|
/// <returns>The same instance so that multiple calls can be chained.</returns>
|
||||||
|
[Obsolete("Use Padding(..) instead.")]
|
||||||
|
[EditorBrowsable(EditorBrowsableState.Never)]
|
||||||
|
public static T SetPadding<T>(this T obj, Padding padding)
|
||||||
|
where T : class, IPaddable
|
||||||
|
{
|
||||||
|
if (obj is null)
|
||||||
|
{
|
||||||
|
throw new ArgumentNullException(nameof(obj));
|
||||||
|
}
|
||||||
|
|
||||||
|
obj.Padding = padding;
|
||||||
|
return obj;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user