Skip to content

Commit 86023b2

Browse files
committed
Add new hierarchical and tabular data display how-to guides, example implementations, and widget discovery documentation
1 parent c439dd1 commit 86023b2

28 files changed

Lines changed: 1661 additions & 72 deletions
Lines changed: 240 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,240 @@
1+
# C# Example Templates for Tutorials
2+
3+
Create example files at:
4+
- Console: `Spectre.Docs.Examples/SpectreConsole/Tutorials/{TutorialName}Tutorial.cs`
5+
- CLI: `Spectre.Docs.Examples/SpectreCli/Tutorials/{TutorialName}Tutorial.cs`
6+
7+
## Key Concept: Visible Progress
8+
9+
Unlike how-to guides (which build incrementally toward a solution), tutorial examples focus on **immediate, visible results**. Each method should produce output that the learner can see and verify—building their confidence step by step.
10+
11+
## File Structure Template
12+
13+
```csharp
14+
using Spectre.Console;
15+
16+
namespace Spectre.Docs.Examples.SpectreConsole.Tutorials;
17+
18+
/// <summary>
19+
/// {Brief description of what this tutorial builds}.
20+
/// </summary>
21+
public class {TutorialName}Tutorial
22+
{
23+
/// <summary>
24+
/// {What this step teaches - matches step title}.
25+
/// </summary>
26+
public void {StepMethodName}()
27+
{
28+
// Implementation that produces visible output
29+
AnsiConsole.MarkupLine("[green]Hello[/] [red]World[/]!");
30+
}
31+
32+
/// <summary>
33+
/// {What the next step teaches}.
34+
/// </summary>
35+
public void {NextStepMethodName}()
36+
{
37+
// Next step implementation with visible output
38+
}
39+
40+
// Additional steps...
41+
42+
/// <summary>
43+
/// Complete example demonstrating all tutorial concepts.
44+
/// </summary>
45+
public void ShowComplete{Feature}()
46+
{
47+
// Combined implementation showing the full output
48+
AnsiConsole.MarkupLine("[green]✓ Build completed successfully[/]");
49+
// ... rest of the complete output
50+
}
51+
}
52+
```
53+
54+
## Rules
55+
56+
1. **XML Doc Required**: Every public method and the class MUST have a `<summary>` comment
57+
2. **Class Signature**: Always `public class {TutorialName}Tutorial`
58+
3. **Method Signature**: Always `public void` (instance methods)
59+
4. **Visible Output**: Every step MUST produce output the learner can see
60+
5. **Self-Contained Steps**: Each method should work independently (no shared state)
61+
6. **Descriptive Names**: Use names that match the tutorial step titles
62+
7. **Complete Method Required**: Include `ShowComplete{Feature}()` demonstrating the full output
63+
8. **Realistic Data**: Use meaningful sample data that tells a story
64+
65+
## Example: Markup Styling Tutorial
66+
67+
```csharp
68+
using Spectre.Console;
69+
70+
namespace Spectre.Docs.Examples.SpectreConsole.Tutorials;
71+
72+
/// <summary>
73+
/// A tutorial that builds a styled build-output display step by step.
74+
/// Teaches markup syntax, custom colors, combined styles, links, and safe interpolation.
75+
/// </summary>
76+
public class MarkupStylingTutorial
77+
{
78+
/// <summary>
79+
/// Displays a success message in green using basic markup syntax.
80+
/// </summary>
81+
public void ShowSuccessMessage()
82+
{
83+
AnsiConsole.MarkupLine("[green]✓ Build completed successfully[/]");
84+
}
85+
86+
/// <summary>
87+
/// Displays a warning message using a custom hex color and mixed styling.
88+
/// </summary>
89+
public void ShowWarningMessage()
90+
{
91+
AnsiConsole.MarkupLine("[#FFA500]⚠[/] [yellow]3 warnings[/] in Authentication.cs");
92+
}
93+
94+
/// <summary>
95+
/// Displays an error message using combined bold and red styling.
96+
/// </summary>
97+
public void ShowErrorMessage()
98+
{
99+
AnsiConsole.MarkupLine("[bold red]✗ Error:[/] Missing dependency 'Newtonsoft.Json'");
100+
}
101+
102+
/// <summary>
103+
/// Displays a clickable documentation link.
104+
/// </summary>
105+
public void ShowDocumentationLink()
106+
{
107+
AnsiConsole.MarkupLine(" → See: [link=https://docs.example.com/dependencies]documentation[/]");
108+
}
109+
110+
/// <summary>
111+
/// Demonstrates safe interpolation for dynamic content that might contain brackets.
112+
/// </summary>
113+
public void ShowDynamicContent()
114+
{
115+
var fileName = "Authentication.cs";
116+
var warningCount = 3;
117+
AnsiConsole.MarkupLineInterpolated($"[#FFA500]⚠[/] [yellow]{warningCount} warnings[/] in {fileName}");
118+
}
119+
120+
/// <summary>
121+
/// Displays the complete build output combining all techniques.
122+
/// </summary>
123+
public void ShowCompleteBuildOutput()
124+
{
125+
var fileName = "Authentication.cs";
126+
var dependency = "Newtonsoft.Json";
127+
128+
AnsiConsole.MarkupLine("[green]✓ Build completed successfully[/]");
129+
AnsiConsole.MarkupLineInterpolated($"[#FFA500]⚠[/] [yellow]3 warnings[/] in {fileName}");
130+
AnsiConsole.MarkupLineInterpolated($"[bold red]✗ Error:[/] Missing dependency '{dependency}'");
131+
AnsiConsole.MarkupLine(" → See: [link=https://docs.example.com/dependencies]documentation[/]");
132+
}
133+
}
134+
```
135+
136+
## Method Naming Guidelines
137+
138+
Method names should match the step titles in the tutorial:
139+
140+
| Step Title | Method Name |
141+
|------------|-------------|
142+
| "Display a Success Message" | `ShowSuccessMessage` |
143+
| "Add a Warning Message" | `ShowWarningMessage` |
144+
| "Show an Error Message" | `ShowErrorMessage` |
145+
| "Include a Documentation Link" | `ShowDocumentationLink` |
146+
| "Complete Build Output" | `ShowCompleteBuildOutput` |
147+
148+
Use action verbs that describe what the learner will see:
149+
- `Show{Feature}` - Displays something
150+
- `Create{Thing}` - Builds and displays something
151+
- `ShowComplete{Feature}` - The final method showing everything together
152+
153+
## Visible Output Requirements
154+
155+
Every tutorial step must produce output. This is critical for learner confidence:
156+
157+
**Good - produces visible output:**
158+
```csharp
159+
public void ShowBasicTable()
160+
{
161+
var table = new Table();
162+
table.AddColumn("Name");
163+
table.AddRow("Alice");
164+
AnsiConsole.Write(table); // Learner sees the table
165+
}
166+
```
167+
168+
**Bad - no visible output:**
169+
```csharp
170+
public void CreateTable()
171+
{
172+
var table = new Table();
173+
table.AddColumn("Name");
174+
table.AddRow("Alice");
175+
// Nothing displayed - learner can't verify it worked!
176+
}
177+
```
178+
179+
## Self-Contained Steps
180+
181+
Each method should work independently. Don't rely on state from previous steps:
182+
183+
**Good - self-contained:**
184+
```csharp
185+
public void ShowStyledTable()
186+
{
187+
var table = new Table()
188+
.Border(TableBorder.Rounded)
189+
.BorderColor(Color.Blue);
190+
table.AddColumn("Name");
191+
table.AddRow("Alice");
192+
AnsiConsole.Write(table);
193+
}
194+
```
195+
196+
**Bad - depends on previous state:**
197+
```csharp
198+
private Table _table; // Shared state
199+
200+
public void CreateTable()
201+
{
202+
_table = new Table();
203+
_table.AddColumn("Name");
204+
}
205+
206+
public void StyleTable()
207+
{
208+
_table.Border(TableBorder.Rounded); // Fails if CreateTable wasn't called first
209+
AnsiConsole.Write(_table);
210+
}
211+
```
212+
213+
## XmlDocId Reference
214+
215+
The XmlDocId for referencing examples in markdown:
216+
217+
```
218+
M:Spectre.Docs.Examples.SpectreConsole.Tutorials.{TutorialName}Tutorial.{MethodName}
219+
M:Spectre.Docs.Examples.SpectreCli.Tutorials.{TutorialName}Tutorial.{MethodName}
220+
```
221+
222+
Examples:
223+
```
224+
M:Spectre.Docs.Examples.SpectreConsole.Tutorials.MarkupStylingTutorial.ShowSuccessMessage
225+
M:Spectre.Docs.Examples.SpectreConsole.Tutorials.MarkupStylingTutorial.ShowCompleteBuildOutput
226+
```
227+
228+
## Checklist
229+
230+
- [ ] File is in correct Tutorials folder (`SpectreConsole/Tutorials/` or `SpectreCli/Tutorials/`)
231+
- [ ] Class is `public class {TutorialName}Tutorial`
232+
- [ ] Namespace matches folder structure
233+
- [ ] Class has XML doc `<summary>`
234+
- [ ] Every method has XML doc `<summary>`
235+
- [ ] Every method is `public void` (instance method)
236+
- [ ] Every method produces visible output
237+
- [ ] Methods are self-contained (no shared state)
238+
- [ ] Method names match tutorial step titles
239+
- [ ] `ShowComplete{Feature}()` method demonstrates the full output
240+
- [ ] Examples use realistic, meaningful data
Lines changed: 112 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,112 @@
1+
# Widget Discovery Guide
2+
3+
This guide teaches you how to systematically discover all capabilities of a Spectre.Console widget.
4+
5+
## Key Locations
6+
7+
| What | Where |
8+
|------|-------|
9+
| Widget source | `B:/spectre/spectre.console/src/Spectre.Console/Widgets/` |
10+
| Extension methods | `B:/spectre/spectre.console/src/Spectre.Console/Extensions/` |
11+
| Interface definitions | `B:/spectre/spectre.console/src/Spectre.Console/I*.cs` |
12+
13+
## Step 1: Find the Widget Source
14+
15+
Widgets are located at:
16+
- `B:/spectre/spectre.console/src/Spectre.Console/Widgets/{Widget}.cs`
17+
- Or in a subfolder: `B:/spectre/spectre.console/src/Spectre.Console/Widgets/{Widget}/{Widget}.cs`
18+
19+
## Step 2: Identify Implemented Interfaces
20+
21+
Look at the class declaration for implemented interfaces. Each interface indicates capabilities:
22+
23+
```csharp
24+
// Example from Panel.cs
25+
public sealed class Panel : Renderable, IHasBoxBorder, IHasBorder, IExpandable, IPaddable
26+
```
27+
28+
## Step 3: Find Extension Methods for Each Interface
29+
30+
For each interface `I{Capability}`, search for extension methods:
31+
32+
| Interface | Extension File Pattern | Common Methods |
33+
|-----------|----------------------|----------------|
34+
| `IExpandable` | `ExpandableExtensions.cs` | `Expand()`, `Collapse()` |
35+
| `IPaddable` | `PaddableExtensions.cs` | `Padding()`, `PadLeft()`, `PadRight()`, `PadTop()`, `PadBottom()` |
36+
| `IHasBoxBorder` | `HasBoxBorderExtensions.cs` | `Border()`, `NoBorder()`, `SquareBorder()`, `RoundedBorder()`, `HeavyBorder()`, `DoubleBorder()`, `AsciiBorder()` |
37+
| `IHasBorder` | `HasBorderExtensions.cs` | `BorderColor()`, `BorderStyle()`, `SafeBorder()`, `NoSafeBorder()` |
38+
| `IHasTableBorder` | `HasTableBorderExtensions.cs` | All box borders plus `MinimalBorder()`, `MarkdownBorder()`, etc. |
39+
| `IHasJustification` | `HasJustificationExtensions.cs` | `LeftJustified()`, `Centered()`, `RightJustified()` |
40+
| `IOverflowable` | `OverflowableExtensions.cs` | `Overflow()` |
41+
| `IAlignable` | `AlignableExtensions.cs` | Alignment property |
42+
| `IHasTreeNodes` | `HasTreeNodeExtensions.cs` | `AddNode()` |
43+
| `IHasCulture` | `HasCultureExtensions.cs` | `Culture()` |
44+
45+
## Step 4: Find Widget-Specific Extensions
46+
47+
Check for `{Widget}Extensions.cs` in the Extensions folder:
48+
49+
```
50+
B:/spectre/spectre.console/src/Spectre.Console/Extensions/{Widget}Extensions.cs
51+
```
52+
53+
These contain widget-specific fluent methods like:
54+
- `Table`: `Title()`, `Caption()`, `ShowHeaders()`, `HideHeaders()`, `ShowRowSeparators()`
55+
- `Panel`: `Header()`, `HeaderAlignment()`
56+
57+
## Step 5: Examine Public Properties
58+
59+
In the widget source, identify public properties that can be configured:
60+
61+
```csharp
62+
// Look for patterns like:
63+
public bool Expand { get; set; }
64+
public Padding? Padding { get; set; }
65+
public BoxBorder Border { get; set; }
66+
```
67+
68+
## Step 6: Check Constructors
69+
70+
Note constructor parameters to understand instantiation patterns:
71+
72+
```csharp
73+
// What's required vs optional?
74+
public Panel(IRenderable content) // content is required
75+
public Table() // no required parameters
76+
```
77+
78+
## Step 7: Look for Related Types
79+
80+
Search for supporting types in the same folder:
81+
- `{Widget}Column.cs` (e.g., TableColumn)
82+
- `{Widget}Row.cs` (e.g., TableRow)
83+
- `{Widget}Title.cs` (e.g., TableTitle)
84+
85+
These often have their own extension methods.
86+
87+
## Step 8: Identify Related Widgets for Cross-Referencing
88+
89+
Determine which widgets serve similar or complementary purposes:
90+
91+
| Widget | Related Widgets | When to Cross-Reference |
92+
|--------|-----------------|------------------------|
93+
| BarChart | BreakdownChart | Part-to-whole vs comparison |
94+
| BreakdownChart | BarChart | Comparison vs part-to-whole |
95+
| Table | Grid | Simple layouts vs structured data |
96+
| Panel | Table | Single content vs tabular data |
97+
| Tree | Table | Hierarchical vs flat data |
98+
| Columns | Grid, Table | Side-by-side layout alternatives |
99+
100+
In documentation, guide users to alternatives:
101+
- "For **X scenario**, use [Widget](/console/widgets/widget) instead."
102+
103+
## Discovery Checklist
104+
105+
- [ ] Found widget source file
106+
- [ ] Listed all implemented interfaces
107+
- [ ] Found extension methods for each interface
108+
- [ ] Checked for widget-specific extensions
109+
- [ ] Listed public properties
110+
- [ ] Noted constructor requirements
111+
- [ ] Identified related/supporting types
112+
- [ ] Identified related widgets for cross-references

0 commit comments

Comments
 (0)