Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add documentation for TextPath widget #757

Merged
merged 1 commit into from
Mar 1, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
6 changes: 6 additions & 0 deletions docs/input/assets/casts/text-path-plain.cast
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{"version": 2, "width": 42, "height": 23, "title": "text-path (plain)", "env": {"TERM": "Spectre.Console"}}
[0, "o", "\u001B[37m\u250C\u2500Windows path\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2510\u001B[0m\r\n\u001B[37m\u2502\u001B[0m \u001B[37m\u2502\u001B[0m\r\n\u001B[37m\u2502\u001B[0m C:/.../That/Will/Be/Truncated.txt \u001B[37m\u2502\u001B[0m\r\n\u001B[37m\u2502\u001B[0m \u001B[37m\u2502\u001B[0m\r\n\u001B[37m\u2514\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2518\u001B[0m\r\n"]
[0.015, "o", "\u001B[37m\u250C\u2500Unix path\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2510\u001B[0m\r\n\u001B[37m\u2502\u001B[0m \u001B[37m\u2502\u001B[0m\r\n\u001B[37m\u2502\u001B[0m /.../That/Will/Be/Truncated.txt \u001B[37m\u2502\u001B[0m\r\n\u001B[37m\u2502\u001B[0m \u001B[37m\u2502\u001B[0m\r\n\u001B[37m\u2514\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2518\u001B[0m\r\n"]
[0.015, "o", "\u001B[37m\u250C\u2500Styling\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2510\u001B[0m\r\n\u001B[37m\u2502\u001B[0m \u001B[37m\u2502\u001B[0m\r\n\u001B[37m\u2502\u001B[0m \u001B[32m/\u001B[0m\u001B[37m...\u001B[0m\u001B[31m/\u001B[0m\u001B[37mThat\u001B[0m\u001B[31m/\u001B[0m\u001B[37mWill\u001B[0m\u001B[31m/\u001B[0m\u001B[37mBe\u001B[0m\u001B[31m/\u001B[0m\u001B[34mTruncated.txt\u001B[0m \u001B[37m\u2502\u001B[0m\r\n\u001B[37m\u2502\u001B[0m \u001B[37m\u2502\u001B[0m\r\n\u001B[37m\u2514\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2518\u001B[0m\r\n"]
[0.015, "o", "\u001B[37m\u250C\u2500Alignment\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2510\u001B[0m\r\n\u001B[37m\u2502\u001B[0m \u001B[37m\u2502\u001B[0m\r\n\u001B[37m\u2502\u001B[0m /.../That/Will/Be/Truncated.txt \u001B[37m\u2502\u001B[0m\r\n\u001B[37m\u2502\u001B[0m /.../That/Will/Be/Truncated.txt \u001B[37m\u2502\u001B[0m\r\n\u001B[37m\u2502\u001B[0m /.../That/Will/Be/Truncated.txt \u001B[37m\u2502\u001B[0m\r\n\u001B[37m\u2502\u001B[0m \u001B[37m\u2502\u001B[0m\r\n\u001B[37m\u2514\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2518\u001B[0m\r\n"]

6 changes: 6 additions & 0 deletions docs/input/assets/casts/text-path-rich.cast
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{"version": 2, "width": 42, "height": 23, "title": "text-path (rich)", "env": {"TERM": "Spectre.Console"}}
[0, "o", "\u001B[38;5;8m\u250C\u2500Windows path\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2510\u001B[0m\r\n\u001B[38;5;8m\u2502\u001B[0m \u001B[38;5;8m\u2502\u001B[0m\r\n\u001B[38;5;8m\u2502\u001B[0m C:/\u2026/Path/That/Will/Be/Truncated.txt \u001B[38;5;8m\u2502\u001B[0m\r\n\u001B[38;5;8m\u2502\u001B[0m \u001B[38;5;8m\u2502\u001B[0m\r\n\u001B[38;5;8m\u2514\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2518\u001B[0m\r\n"]
[0, "o", "\u001B[38;5;8m\u250C\u2500Unix path\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2510\u001B[0m\r\n\u001B[38;5;8m\u2502\u001B[0m \u001B[38;5;8m\u2502\u001B[0m\r\n\u001B[38;5;8m\u2502\u001B[0m /\u2026/Path/That/Will/Be/Truncated.txt \u001B[38;5;8m\u2502\u001B[0m\r\n\u001B[38;5;8m\u2502\u001B[0m \u001B[38;5;8m\u2502\u001B[0m\r\n\u001B[38;5;8m\u2514\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2518\u001B[0m\r\n"]
[0, "o", "\u001B[38;5;8m\u250C\u2500Styling\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2510\u001B[0m\r\n\u001B[38;5;8m\u2502\u001B[0m \u001B[38;5;8m\u2502\u001B[0m\r\n\u001B[38;5;8m\u2502\u001B[0m \u001B[38;5;2m/\u001B[0m\u001B[38;5;11m\u2026\u001B[0m\u001B[38;5;9m/\u001B[0m\u001B[38;5;11mPath\u001B[0m\u001B[38;5;9m/\u001B[0m\u001B[38;5;11mThat\u001B[0m\u001B[38;5;9m/\u001B[0m\u001B[38;5;11mWill\u001B[0m\u001B[38;5;9m/\u001B[0m\u001B[38;5;11mBe\u001B[0m\u001B[38;5;9m/\u001B[0m\u001B[38;5;12mTruncated.txt\u001B[0m \u001B[38;5;8m\u2502\u001B[0m\r\n\u001B[38;5;8m\u2502\u001B[0m \u001B[38;5;8m\u2502\u001B[0m\r\n\u001B[38;5;8m\u2514\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2518\u001B[0m\r\n"]
[0, "o", "\u001B[38;5;8m\u250C\u2500Alignment\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2510\u001B[0m\r\n\u001B[38;5;8m\u2502\u001B[0m \u001B[38;5;8m\u2502\u001B[0m\r\n\u001B[38;5;8m\u2502\u001B[0m /\u2026/Path/That/Will/Be/Truncated.txt \u001B[38;5;8m\u2502\u001B[0m\r\n\u001B[38;5;8m\u2502\u001B[0m /\u2026/Path/That/Will/Be/Truncated.txt \u001B[38;5;8m\u2502\u001B[0m\r\n\u001B[38;5;8m\u2502\u001B[0m /\u2026/Path/That/Will/Be/Truncated.txt \u001B[38;5;8m\u2502\u001B[0m\r\n\u001B[38;5;8m\u2502\u001B[0m \u001B[38;5;8m\u2502\u001B[0m\r\n\u001B[38;5;8m\u2514\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2518\u001B[0m\r\n"]

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
71 changes: 71 additions & 0 deletions docs/input/widgets/path.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
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.

<?# AsciiCast cast="text-path" /?>

## Usage

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

AnsiConsole.Write(path);
```

## Alignment

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

AnsiConsole.Write(path);
```

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:

```csharp
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);
```
1 change: 0 additions & 1 deletion docs/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

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>";
}
}
}
8 changes: 4 additions & 4 deletions examples/Console/Paths/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -40,15 +40,15 @@ private static void WriteColorized(string windowsPath, string unixPath)
new TextPath(windowsPath)
.RootColor(Color.Blue)
.SeparatorColor(Color.Yellow)
.StemStyle(Color.Red)
.LeafStyle(Color.Green));
.StemColor(Color.Red)
.LeafColor(Color.Green));

table.AddRow(new Text("Unix"),
new TextPath(unixPath)
.RootColor(Color.Blue)
.SeparatorColor(Color.Yellow)
.StemStyle(Color.Red)
.LeafStyle(Color.Green));
.StemColor(Color.Red)
.LeafColor(Color.Green));

AnsiConsole.Write(table);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
using DocExampleGenerator;
using Spectre.Console;

namespace Generator.Commands.Samples
{
internal class TextPathSample : BaseSample
{
public override (int Cols, int Rows) ConsoleSize => (40, 23);

public override void Run(IAnsiConsole console)
{
console.Write(
new Panel(
new Padder(new TextPath("C:/This/Is/A/Super/Long/Path/That/Will/Be/Truncated.txt"), new Padding(0,1)))
.BorderStyle(new Style(foreground: Color.Grey))
.Header("Windows path"));

console.Write(
new Panel(
new Padder(new TextPath("/This/Is/A/Super/Long/Path/That/Will/Be/Truncated.txt"), new Padding(0,1)))
.BorderStyle(new Style(foreground: Color.Grey))
.Header("Unix path"));

console.Write(
new Panel(
new Padder(new TextPath("/This/Is/A/Long/Path/That/Will/Be/Truncated.txt")
.RootColor(Color.Green)
.SeparatorColor(Color.Red)
.StemColor(Color.Yellow)
.LeafColor(Color.Blue), new Padding(0,1)))
.BorderStyle(new Style(foreground: Color.Grey))
.Header("Styling"));

console.Write(
new Panel(
new Padder(new Rows(
new TextPath("/This/Is/A/Long/Path/That/Will/Be/Truncated.txt").LeftAligned(),
new TextPath("/This/Is/A/Long/Path/That/Will/Be/Truncated.txt").Centered(),
new TextPath("/This/Is/A/Long/Path/That/Will/Be/Truncated.txt").RightAligned()), new Padding(0,1)))
.BorderStyle(new Style(foreground: Color.Grey))
.Header("Alignment"));
}
}
}
4 changes: 2 additions & 2 deletions src/Spectre.Console/Extensions/TextPathExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ public static TextPath StemStyle(this TextPath obj, Style style)
/// <param name="obj">The path.</param>
/// <param name="color">The stem color.</param>
/// <returns>The same instance so that multiple calls can be chained.</returns>
public static TextPath StemStyle(this TextPath obj, Color color)
public static TextPath StemColor(this TextPath obj, Color color)
{
return StemStyle(obj, new Style(foreground: color));
}
Expand Down Expand Up @@ -112,7 +112,7 @@ public static TextPath LeafStyle(this TextPath obj, Style style)
/// <param name="obj">The path.</param>
/// <param name="color">The leaf color.</param>
/// <returns>The same instance so that multiple calls can be chained.</returns>
public static TextPath LeafStyle(this TextPath obj, Color color)
public static TextPath LeafColor(this TextPath obj, Color color)
{
return LeafStyle(obj, new Style(foreground: color));
}
Expand Down