Skip to content

Commit

Permalink
Merge pull request #19 from lechu445/fix_multiple_show_
Browse files Browse the repository at this point in the history
Fix Show already active menu causing StackOverflow
  • Loading branch information
lechu445 committed Sep 2, 2023
2 parents 4612a9a + 7b49268 commit 7d4c750
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 14 deletions.
15 changes: 9 additions & 6 deletions ConsoleMenu/ConsoleMenu.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ public class ConsoleMenu : IEnumerable
private readonly CloseTrigger closeTrigger;
private MenuConfig config = new MenuConfig();
private ConsoleMenu? parent = null;
private bool isShown = false;

/// <summary>
/// Initializes a new instance of the <see cref="ConsoleMenu"/> class.
Expand Down Expand Up @@ -283,19 +284,21 @@ public ConsoleMenu Configure(MenuConfig config)
/// </summary>
public void Show()
{
new ConsoleMenuDisplay(
this.menuItems,
this.Console,
new List<string>(this.Titles),
this.config,
this.closeTrigger).ShowAsync(CancellationToken.None).GetAwaiter().GetResult();
ShowAsync(CancellationToken.None).GetAwaiter().GetResult();
}

/// <summary>
/// Displays the menu in console.
/// </summary>
public async Task ShowAsync(CancellationToken cancellationToken = default)
{
if (isShown)
{
this.menuItems.UnsetSelectedIndex();
}

isShown = true;

await new ConsoleMenuDisplay(
this.menuItems,
this.Console,
Expand Down
4 changes: 2 additions & 2 deletions ConsoleMenu/ConsoleMenu.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,10 @@
<Authors>lechu445</Authors>
<Product>ConsoleMenu-simple</Product>
<Description>A simple, highly customizable, DOS-like console menu</Description>
<PackageReleaseNotes>- added async API</PackageReleaseNotes>
<PackageReleaseNotes>- Fix Show already active menu causing StackOverflow (#16)</PackageReleaseNotes>
<PackageProjectUrl>https://github.com/lechu445/ConsoleMenu</PackageProjectUrl>
<PublishRepositoryUrl>true</PublishRepositoryUrl>
<Version>2.6.0</Version>
<Version>2.6.1</Version>
<RepositoryUrl>https://github.com/lechu445/ConsoleMenu</RepositoryUrl>
<PackageTags>console, menu, simple</PackageTags>
<PackageLicenseFile>LICENSE.txt</PackageLicenseFile>
Expand Down
2 changes: 1 addition & 1 deletion ConsoleMenuSampleApp/ConsoleMenuSampleApp.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net5.0</TargetFramework>
<TargetFramework>net6.0</TargetFramework>
</PropertyGroup>

<ItemGroup>
Expand Down
8 changes: 4 additions & 4 deletions ConsoleMenuTests/ConsoleMenuTests.csproj
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>net5.0</TargetFramework>
<TargetFramework>net6.0</TargetFramework>

<IsPackable>false</IsPackable>
<Nullable>enable</Nullable>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.4.1" />
<PackageReference Include="xunit" Version="2.4.2" />
<PackageReference Include="xunit.runner.visualstudio" Version="2.4.5">
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.7.2" />
<PackageReference Include="xunit" Version="2.5.0" />
<PackageReference Include="xunit.runner.visualstudio" Version="2.5.0">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
Expand Down
2 changes: 1 addition & 1 deletion ConsoleMenuTests/TestHelpers/AssertHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ public static void Equal(string expected, string actual)
}
catch (Xunit.Sdk.EqualException ex)
{
throw new Xunit.Sdk.AssertActualExpectedException(expected, actual, "Expected was not equal to actual", "Expected", "Actual", ex);
throw new Xunit.Sdk.XunitException("Expected was not equal to actual", ex);
}
}
}
Expand Down

0 comments on commit 7d4c750

Please sign in to comment.