-
Notifications
You must be signed in to change notification settings - Fork 0
Render headings via Spectre.Console FigletText (IHeaderStyle, default H1) #113
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
Merged
boxofyellow
merged 11 commits into
main
from
copilot/add-figlett-text-widget-for-h1-headings
May 15, 2026
Merged
Changes from all commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
6165c3b
Add FigletTextStyle for rendering headings as FIGlet ASCII art
Copilot 64ace32
Clarify cast safety in FigletTextStyle.Equals
Copilot fc3395e
Rework FigletTextStyle as IHeaderStyle peer; cover all FIGlet branche…
Copilot 8007d52
Address PR review: extend IHeaderStyle, simplify renderer, FontPath, …
Copilot e531542
Address PR review: migration guide, AssertCrossPlatStringMatch, cover…
Copilot 804d79c
Address PR review: AssertCrossPlatStringMatch, eager font load + Load…
Copilot b6434e6
Check cancellation between async font read and parse
Copilot 0d04e60
FigletTextStyle: Create/CreateAsync pattern, trim IHeaderStyle, TempF…
Copilot 89606a0
Make FigletTextStyle constructor private; require Create/CreateAsync …
Copilot 33e3cd0
Consolidate FigletTextStyle constructors into a single private constr…
Copilot 884e972
Apply suggestions from code review
boxofyellow File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,116 @@ | ||
| using BoxOfYellow.ConsoleMarkdownRenderer.Styling; | ||
|
|
||
| namespace BoxOfYellow.ConsoleMarkdownRenderer.Tests | ||
| { | ||
| /// <summary> | ||
| /// Tests for <see cref="FigletTextStyle"/> and the shared <see cref="IHeaderStyle"/> contract. | ||
| /// </summary> | ||
| [TestClass] | ||
| public class FigletTextStyleTests : TestWithFileCleanupBase | ||
| { | ||
| [TestMethod] | ||
| public void FigletTextStyle_DefaultsAreNull() | ||
| { | ||
| var style = FigletTextStyle.Create(); | ||
| Assert.IsNull(style.Justification); | ||
| Assert.IsNull(style.Foreground); | ||
| Assert.IsNull(style.FontPath); | ||
| Assert.IsNull(style.Font); | ||
| } | ||
|
|
||
| [TestMethod] | ||
| public void FigletTextStyle_Create_PreservesProperties() | ||
| { | ||
| var created = FigletTextStyle.Create( | ||
| justification: TextJustification.Right, | ||
| foreground: TextColor.Green); | ||
|
|
||
| Assert.AreEqual(TextJustification.Right, created.Justification); | ||
| Assert.AreEqual(TextColor.Green, created.Foreground); | ||
| Assert.IsNull(created.FontPath); | ||
| Assert.IsNull(created.Font); | ||
| Assert.AreEqual(FigletTextStyle.Create(TextJustification.Right, TextColor.Green), created); | ||
| } | ||
|
|
||
| [TestMethod] | ||
| public void FigletTextStyle_Equality_SameValues() | ||
| { | ||
| var a = FigletTextStyle.Create(justification: TextJustification.Right, foreground: TextColor.Green); | ||
| var b = FigletTextStyle.Create(justification: TextJustification.Right, foreground: TextColor.Green); | ||
|
|
||
| Assert.AreEqual(a, b); | ||
| Assert.AreEqual(a.GetHashCode(), b.GetHashCode()); | ||
| } | ||
|
|
||
| [TestMethod] | ||
| public void FigletTextStyle_Equality_DifferentJustification() | ||
| { | ||
| var a = FigletTextStyle.Create(justification: TextJustification.Left); | ||
| var b = FigletTextStyle.Create(justification: TextJustification.Right); | ||
|
|
||
| Assert.AreNotEqual(a, b); | ||
| } | ||
|
|
||
| [TestMethod] | ||
| public void FigletTextStyle_Equality_DifferentForeground() | ||
| { | ||
| var a = FigletTextStyle.Create(foreground: TextColor.Red); | ||
| var b = FigletTextStyle.Create(foreground: TextColor.Blue); | ||
|
|
||
| Assert.AreNotEqual(a, b); | ||
| } | ||
|
|
||
| [TestMethod] | ||
| public void FigletTextStyle_BackgroundAndDecoration_HardCodedViaIHeaderStyle() | ||
| { | ||
| // FigletText does not support a background color or text decoration so those | ||
| // members on the IHeaderStyle interface are hard-coded. | ||
| IHeaderStyle figlet = FigletTextStyle.Create(foreground: TextColor.Green); | ||
|
|
||
| Assert.AreEqual(TextColor.Green, figlet.Foreground); | ||
| Assert.IsNull(figlet.Background); | ||
| Assert.AreEqual(TextDecoration.None, figlet.Decoration); | ||
| } | ||
|
|
||
| private static string BundledFontPath | ||
| => Path.Combine(AppContext.BaseDirectory, "data", "fonts", "shadow.flf"); | ||
|
|
||
| [TestMethod] | ||
| public async Task FigletTextStyle_CreateAsync_LoadsFont() | ||
| { | ||
| var style = await FigletTextStyle.CreateAsync( | ||
| BundledFontPath, | ||
| justification: TextJustification.Center, | ||
| foreground: TextColor.Green); | ||
|
|
||
| Assert.AreEqual(BundledFontPath, style.FontPath); | ||
| Assert.AreEqual(TextJustification.Center, style.Justification); | ||
| Assert.AreEqual(TextColor.Green, style.Foreground); | ||
| Assert.IsNotNull(style.Font); | ||
| } | ||
|
|
||
| [TestMethod] | ||
| public async Task FigletTextStyle_CreateAsync_InvalidPath_Throws() | ||
| { | ||
| // Loading happens at CreateAsync time so an invalid path surfaces there | ||
| // (rather than later at render time). | ||
| await Assert.ThrowsExactlyAsync<FileNotFoundException>( | ||
| () => FigletTextStyle.CreateAsync( | ||
| Path.Combine(AppContext.BaseDirectory, "data", "fonts", "does-not-exist.flf"))); | ||
| } | ||
|
|
||
| [TestMethod] | ||
| public async Task FigletTextStyle_Equality_DifferentFontPath() | ||
| { | ||
| // Copy the bundled font to a temp location so equality has two distinct, valid | ||
| // .flf paths to compare. TempFileManager cleans up the copy at test teardown. | ||
| var tempPath = TempFiles.GetTempFile(); | ||
| File.Copy(BundledFontPath, tempPath, overwrite: true); | ||
|
|
||
| var a = await FigletTextStyle.CreateAsync(BundledFontPath); | ||
| var b = await FigletTextStyle.CreateAsync(tempPath); | ||
|
|
||
| Assert.AreNotEqual(a, b); | ||
| } | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,43 @@ | ||
| using BoxOfYellow.ConsoleMarkdownRenderer.Styling; | ||
| using Spectre.Console; | ||
|
|
||
| namespace BoxOfYellow.ConsoleMarkdownRenderer.Tests | ||
| { | ||
| /// <summary> | ||
| /// Tests for <see cref="TextJustification"/> to ensure it stays in sync with | ||
| /// Spectre.Console's <see cref="Justify"/> enum. The pattern mirrors | ||
| /// <see cref="TextDecorationTests"/>. | ||
| /// </summary> | ||
| [TestClass] | ||
| public class TextJustificationTests | ||
| { | ||
| /// <summary> | ||
| /// Verifies that every value of Spectre.Console's <see cref="Justify"/> enum has a | ||
| /// corresponding value in our <see cref="TextJustification"/> enum. If Spectre adds | ||
| /// new justifications, this test will fail to remind us to update. | ||
| /// </summary> | ||
| [TestMethod] | ||
| public void TextJustification_HasAllSpectreJustifyValues() | ||
| { | ||
| var spectreNames = Enum.GetNames(typeof(Justify)).ToList(); | ||
| var ourNames = Enum.GetNames(typeof(TextJustification)).ToList(); | ||
|
|
||
| var missing = spectreNames.Where(name => !ourNames.Contains(name)).ToList(); | ||
|
|
||
| if (missing.Count > 0) | ||
| { | ||
| Assert.Fail( | ||
| $"TextJustification is missing the following values from Spectre.Console.Justify: {string.Join(", ", missing)}"); | ||
| } | ||
| } | ||
|
|
||
| [TestMethod] | ||
| [DataRow(TextJustification.Left, Justify.Left)] | ||
| [DataRow(TextJustification.Right, Justify.Right)] | ||
| [DataRow(TextJustification.Center, Justify.Center)] | ||
| public void TextJustification_ConvertsToSpectreJustify(TextJustification source, Justify expected) | ||
| { | ||
| Assert.AreEqual(expected, source.ToSpectreJustify()); | ||
| } | ||
| } | ||
| } |
7 changes: 7 additions & 0 deletions
7
ConsoleMarkdownRenderer.Tests/data/expected/figletCustomFont.txt
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,7 @@ | ||
| ┌──────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────┐ | ||
| │ | | _) │ | ||
| │ | | | │ | ||
| │ ___ | | │ | ||
| │ _| _| _| │ | ||
| │ │ | ||
| └──────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────┘ |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.