-
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
Draft
Copilot
wants to merge
10
commits into
main
Choose a base branch
from
copilot/add-figlett-text-widget-for-h1-headings
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
Changes from all commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
5a2e081
Add FigletTextStyle for rendering headings as FIGlet ASCII art
Copilot fc60c6e
Clarify cast safety in FigletTextStyle.Equals
Copilot d91ad53
Rework FigletTextStyle as IHeaderStyle peer; cover all FIGlet branche…
Copilot 76c99a8
Address PR review: extend IHeaderStyle, simplify renderer, FontPath, …
Copilot ab27fe6
Address PR review: migration guide, AssertCrossPlatStringMatch, cover…
Copilot a8d6f4b
Address PR review: AssertCrossPlatStringMatch, eager font load + Load…
Copilot 3f53bc9
Check cancellation between async font read and parse
Copilot 718a52b
FigletTextStyle: Create/CreateAsync pattern, trim IHeaderStyle, TempF…
Copilot 258dda1
Make FigletTextStyle constructor private; require Create/CreateAsync …
Copilot 1777dd3
Consolidate FigletTextStyle constructors into a single private constr…
Copilot 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,154 @@ | ||
| 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_PropertiesArePreserved() | ||
| { | ||
| var style = FigletTextStyle.Create( | ||
| justification: TextJustification.Center, | ||
| foreground: TextColor.Red); | ||
|
|
||
| Assert.AreEqual(TextJustification.Center, style.Justification); | ||
| Assert.AreEqual(TextColor.Red, style.Foreground); | ||
| } | ||
|
|
||
| [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_ImplementsIHeaderStyle() | ||
| { | ||
| // Both FigletTextStyle and the existing TextStyle satisfy the shared IHeaderStyle | ||
| // contract so they can be assigned to DisplayOptions.Header / Headers interchangeably. | ||
| IHeaderStyle figlet = FigletTextStyle.Create(foreground: TextColor.Green); | ||
| IHeaderStyle plain = new TextStyle(decoration: TextDecoration.Bold); | ||
|
|
||
| Assert.AreEqual(TextColor.Green, figlet.Foreground); | ||
| Assert.AreEqual(TextDecoration.Bold, plain.Decoration); | ||
| } | ||
|
|
||
| [TestMethod] | ||
| public void TextStyle_ExposesForegroundBackgroundDecorationViaIHeaderStyle() | ||
| { | ||
| // Foreground/Background/Decoration on TextStyle round-trip through the | ||
| // IHeaderStyle interface unchanged. | ||
| IHeaderStyle plain = new TextStyle( | ||
| decoration: TextDecoration.Italic, | ||
| foreground: TextColor.Red, | ||
| background: TextColor.Blue); | ||
|
|
||
| Assert.AreEqual(TextDecoration.Italic, plain.Decoration); | ||
| Assert.AreEqual(TextColor.Red, plain.Foreground); | ||
| Assert.AreEqual(TextColor.Blue, plain.Background); | ||
| } | ||
|
|
||
| [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()); | ||
| } | ||
| } | ||
| } |
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.