mirror of
https://github.com/nsnail/spectre.console.git
synced 2025-04-16 00:42:51 +08:00
Add documentation for tables
Also moves "Colors" and "Styles" sections to appendix.
This commit is contained in:
parent
3e9796849b
commit
003e15686f
@ -1,5 +1,5 @@
|
||||
Title: Colors
|
||||
Order: 4
|
||||
Order: 0
|
||||
---
|
||||
|
||||
The following is a list of the standard 8-bit colors supported in terminals.
|
3
docs/input/appendix/index.md
Normal file
3
docs/input/appendix/index.md
Normal file
@ -0,0 +1,3 @@
|
||||
Title: Appendix
|
||||
Order: 10
|
||||
---
|
44
docs/input/appendix/styles.md
Normal file
44
docs/input/appendix/styles.md
Normal file
@ -0,0 +1,44 @@
|
||||
Title: Styles
|
||||
Order: 0
|
||||
---
|
||||
|
||||
Note that what styles that can be used is defined by the system or your terminal software, and may not appear as they should.
|
||||
|
||||
<table class="table">
|
||||
<tr>
|
||||
<td><code>bold</code></td>
|
||||
<td>Bold text</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td><code>dim</code></td>
|
||||
<td>Dim or faint text</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td><code>italic</code></td>
|
||||
<td>Italic text</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td><code>underline</code></td>
|
||||
<td>Underlined text</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td><code>invert</code></td>
|
||||
<td>Swaps the foreground and background colors</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td><code>conceal</code></td>
|
||||
<td>Hides the text</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td><code>slowblink</code></td>
|
||||
<td>Makes text blink slowly</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td><code>rapidblink</code></td>
|
||||
<td>Makes text blink</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td><code>strikethrough</code></td>
|
||||
<td>Shows text with a horizontal line through the center</td>
|
||||
</tr>
|
||||
</table>
|
BIN
docs/input/assets/images/table.png
Normal file
BIN
docs/input/assets/images/table.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 55 KiB |
@ -1,21 +1,19 @@
|
||||
Title: Markup
|
||||
Order: 3
|
||||
Hidden: False
|
||||
Order: 2
|
||||
---
|
||||
|
||||
In `Spectre.Console` there's a class called `Markup` that
|
||||
allows you to output rich text to the console.
|
||||
|
||||
# Syntax
|
||||
|
||||
Console markup uses a syntax inspired by bbcode. If you write the style (see Styles)
|
||||
in square brackets, e.g. `[bold red]`, that style will apply until it is closed with a `[/]`.
|
||||
|
||||
```csharp
|
||||
AnsiConsole.Render(new Markup("[bold yellow]Hello[/] [red]World![/]"));
|
||||
```
|
||||
|
||||
Which should output something similar to the image below. Note that the
|
||||
actual appearance might vary depending on your terminal.
|
||||
|
||||

|
||||
|
||||
|
||||
The `Markup` class implements `IRenderable` which means that you
|
||||
can use this in tables, grids, and panels. Most classes that support
|
||||
rendering of `IRenderable` also have overloads for rendering rich text.
|
||||
@ -58,47 +56,8 @@ You can set the background color in markup by prefixing the color with
|
||||
|
||||
# Colors
|
||||
|
||||
For a list of colors, see the [Colors](xref:colors) section.
|
||||
For a list of colors, see the [Colors](xref:colors) appendix section.
|
||||
|
||||
# Styles
|
||||
|
||||
Note that what styles that can be used is defined by the system or your terminal software, and may not appear as they should.
|
||||
|
||||
<table class="table">
|
||||
<tr>
|
||||
<td><code>bold</code></td>
|
||||
<td>Bold text</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td><code>dim</code></td>
|
||||
<td>Dim or faint text</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td><code>italic</code></td>
|
||||
<td>Italic text</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td><code>underline</code></td>
|
||||
<td>Underlined text</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td><code>invert</code></td>
|
||||
<td>Swaps the foreground and background colors</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td><code>conceal</code></td>
|
||||
<td>Hides the text</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td><code>slowblink</code></td>
|
||||
<td>Makes text blink slowly</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td><code>rapidblink</code></td>
|
||||
<td>Makes text blink</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td><code>strikethrough</code></td>
|
||||
<td>Shows text with a horizontal line through the center</td>
|
||||
</tr>
|
||||
</table>
|
||||
For a list of styles, see the [Styles](xref:styles) appendix section.
|
118
docs/input/tables.md
Normal file
118
docs/input/tables.md
Normal file
@ -0,0 +1,118 @@
|
||||
Title: Tables
|
||||
Order: 3
|
||||
---
|
||||
|
||||
Tables are a perfect way of displaying tabular data in a terminal.
|
||||
|
||||
`Spectre.Console` is super smart about rendering tables and will adjust
|
||||
all columns to fit whatever is inside them. Anything that implements
|
||||
`IRenderable` can be used as a column header or column cell, even another table!
|
||||
|
||||
# Usage
|
||||
|
||||
<!------------------------->
|
||||
<!--- USAGE --->
|
||||
<!------------------------->
|
||||
|
||||
To render a table, create a `Table` instance, add the number of
|
||||
columns that you need, and then add the rows. Finish by passing the
|
||||
table to a console's `Render` method.
|
||||
|
||||
```csharp
|
||||
// Create a table
|
||||
var table = new Table();
|
||||
|
||||
// Add some columns
|
||||
table.AddColumn("Foo");
|
||||
table.AddColumn(new TableColumn("Bar").Centered());
|
||||
|
||||
// Add some rows
|
||||
table.AddRow("Baz", "[green]Qux[/]");
|
||||
table.AddRow(new Markup("[blue]Corgi[/]"), new Panel("Waldo"));
|
||||
|
||||
// Render the table to the console
|
||||
AnsiConsole.Render(table);
|
||||
```
|
||||
|
||||
This will render the following output:
|
||||
|
||||

|
||||
|
||||
# Table appearance
|
||||
|
||||
<!------------------------->
|
||||
<!--- TABLE APPEARANCE --->
|
||||
<!------------------------->
|
||||
|
||||
## Borders
|
||||
|
||||
```csharp
|
||||
// Sets the border kind
|
||||
table.SetBorderKind(BorderKind.None);
|
||||
table.SetBorderKind(BorderKind.Ascii);
|
||||
table.SetBorderKind(BorderKind.Square);
|
||||
table.SetBorderKind(BorderKind.Rounded);
|
||||
```
|
||||
|
||||
## Expand / Collapse
|
||||
|
||||
```csharp
|
||||
// Table will take up as much space as it can
|
||||
// with respect to other things.
|
||||
table.Expand();
|
||||
|
||||
// Table will take up minimal width
|
||||
table.Collapse();
|
||||
```
|
||||
|
||||
## Hide headers
|
||||
|
||||
```csharp
|
||||
// Hides all column headers
|
||||
table.HideHeaders();
|
||||
```
|
||||
|
||||
## Set table width
|
||||
|
||||
```csharp
|
||||
// Sets the table width to 50 cells
|
||||
table.SetWidth(50);
|
||||
```
|
||||
|
||||
# Column appearance
|
||||
|
||||
<!------------------------->
|
||||
<!--- COLUMN APPEARANCE --->
|
||||
<!------------------------->
|
||||
|
||||
## Alignment
|
||||
|
||||
```csharp
|
||||
// Set the alignment explicitly
|
||||
column.SetAlignment(Justify.Right);
|
||||
```
|
||||
|
||||
## Padding
|
||||
|
||||
```csharp
|
||||
// Set left and right padding
|
||||
column.SetPadding(left: 3, right: 5);
|
||||
|
||||
// Set padding individually.
|
||||
column.PadLeft(3);
|
||||
column.PadRight(5);
|
||||
```
|
||||
|
||||
## Disable column wrapping
|
||||
|
||||
```csharp
|
||||
// Disable column wrapping
|
||||
column.NoWrap();
|
||||
```
|
||||
|
||||
## Set column width
|
||||
|
||||
```csharp
|
||||
// Set the column width (no fluent extension method for this yet)
|
||||
column.Width = 15;
|
||||
```
|
Loading…
x
Reference in New Issue
Block a user