mirror of
https://github.com/nsnail/spectre.console.git
synced 2025-06-18 21:08:15 +08:00
Move table and calendar docs
This commit is contained in:

committed by
Patrik Svensson

parent
5a1b8a1710
commit
3941fd81ab
84
docs/input/widgets/calendar.md
Normal file
84
docs/input/widgets/calendar.md
Normal file
@ -0,0 +1,84 @@
|
||||
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);
|
||||
|
||||
┌─────┬─────┬─────┬─────┬─────┬─────┬─────┐
|
||||
│ 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.SetCulture("ja-JP");
|
||||
AnsiConsole.Render(calendar);
|
||||
|
||||
┌────┬────┬────┬────┬────┬────┬────┐
|
||||
│ 日 │ 月 │ 火 │ 水 │ 木 │ 金 │ 土 │
|
||||
├────┼────┼────┼────┼────┼────┼────┤
|
||||
│ │ │ │ │ 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 │
|
||||
│ │ │ │ │ │ │ │
|
||||
└────┴────┴────┴────┴────┴────┴────┘
|
||||
|
||||
```
|
||||
|
||||
## Calendar Event
|
||||
|
||||
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);
|
||||
|
||||
┌─────┬─────┬─────┬─────┬─────┬─────┬─────┐
|
||||
│ 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.SetHighlightStyle(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
|
||||
---
|
121
docs/input/widgets/table.md
Normal file
121
docs/input/widgets/table.md
Normal file
@ -0,0 +1,121 @@
|
||||
Title: Table
|
||||
Order: 3
|
||||
RedirectFrom: tables
|
||||
---
|
||||
|
||||
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
|
||||
|
||||
For a list of borders, see the [Borders](xref:borders) appendix section.
|
||||
|
||||
```csharp
|
||||
// Sets the border
|
||||
table.SetBorder(Border.None);
|
||||
table.SetBorder(Border.Ascii);
|
||||
table.SetBorder(Border.Square);
|
||||
table.SetBorder(Border.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;
|
||||
```
|
Reference in New Issue
Block a user