Skip to content

Commit

Permalink
Add documentation for TextPath widget
Browse files Browse the repository at this point in the history
  • Loading branch information
patriksvensson committed Feb 27, 2022
1 parent eb4a7d3 commit d5464d4
Show file tree
Hide file tree
Showing 4 changed files with 112 additions and 0 deletions.
1 change: 1 addition & 0 deletions docs/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ await Bootstrapper.Factory
.AddShortcode("ColorTable", typeof(ColorTableShortcode))
.AddShortcode("EmojiTable", typeof(EmojiTableShortcode))
.AddShortcode("Alert", typeof(AlertShortcode))
.AddShortcode("Info", typeof(InfoShortcode))
.AddShortcode("AsciiCast", typeof(AsciiCastShortcode))
.AddShortcode("Example", typeof(ExampleSnippet))
.AddPipelines()
Expand Down
8 changes: 8 additions & 0 deletions docs/input/tailwind.css
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,14 @@ and the ascii terminal player.
@apply m-0;
}

.alert-info {
@apply p-4 border border-green-300 bg-green-100 text-green-800 dark:border-green-700/50 dark:bg-green-800/50 dark:text-gray-300/90 rounded shadow-sm text-sm;
}

.alert-info p {
@apply m-0;
}

[type='search'] {
@apply shadow-sm focus:ring-indigo-300 focus:border-indigo-300 block w-full sm:text-sm border-gray-300 rounded-md;
}
Expand Down
90 changes: 90 additions & 0 deletions docs/input/widgets/path.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
Title: Text Path
Order: 80
Description: "The **TextPath** class is used to render a horizontal rule (line) to the terminal."
Highlights:
- Automatically shrinks paths to fit.
- Custom colors for segments of the path.
- Specify left, center or right aligned paths.
Reference: T:Spectre.Console.TextPath

---

The `TextPath` class is used to render a Windows or Unix disk path.

<?# Info ?>
In the examples below, we wrap the paths in a `Panel` to emphasize
what it does and how it behaves.
<?#/ Info ?>

## Usage

To render a text path:

```csharp
var path = new TextPath("C:/This/Path/Is/Too/Long/To/Fit/In/The/Area.txt");

AnsiConsole.Write(new Panel(path));
```

```text
┌────────────────────────────────────────────────┐
│ C:/…/Is/Too/Long/To/Fit/In/The/Area.txt │
└────────────────────────────────────────────────┘
```

## Alignment

You can set the rule title markup text.

```csharp
var path = new TextPath("C:/This/Path/Is/Too/Long/To/Fit/In/The/Area.txt");
path.Alignment = Justify.Right;

AnsiConsole.Write(new Panel(path));
```

```text
┌────────────────────────────────────────────────┐
│ C:/…/Is/Too/Long/To/Fit/In/The/Area.txt │
└────────────────────────────────────────────────┘
```

You can also specify styles via extension methods:

```csharp
var path = new TextPath("C:/This/Path/Is/Too/Long/To/Fit/In/The/Area.txt")
.RightAligned();
```

## Styling

All the segments in the path can be customized to have different styles.

```csharp
var path = new TextPath("C:/This/Path/Is/Too/Long/To/Fit/In/The/Area.txt");

path.RootStyle = new Style(foreground: Color.Red);
path.SeparatorStyle = new Style(foreground: Color.Green);
path.StemStyle = new Style(foreground: Color.Blue);
path.LeafStyle = new Style(foreground: Color.Yellow);
```

You can also specify styles via extension methods:

```csharp
var path = new TextPath("C:/This/Path/Is/Too/Long/To/Fit/In/The/Area.txt")
.RootStyle(new Style(foreground: Color.Red))
.SeparatorStyle(new Style(foreground: Color.Green))
.StemStyle(new Style(foreground: Color.Blue))
.LeafStyle(new Style(foreground: Color.Yellow));
```

Or just set the colors via extension methods:

```text
var path = new TextPath("C:/This/Path/Is/Too/Long/To/Fit/In/The/Area.txt")
.RootColor(Color.Red)
.SeparatorColor(Color.Green)
.StemColor(Color.Blue)
.LeafColor(Color.Yellow);
```
13 changes: 13 additions & 0 deletions docs/src/Shortcodes/InfoShortcode.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
using System.Collections.Generic;
using Statiq.Common;

namespace Docs.Shortcodes
{
public class InfoShortcode : SyncShortcode
{
public override ShortcodeResult Execute(KeyValuePair<string, string>[] args, string content, IDocument document, IExecutionContext context)
{
return $"<div class=\"alert-info\">{content}</div>";
}
}
}

0 comments on commit d5464d4

Please sign in to comment.