Started adding example projects

develop
Steve Cross 3 years ago
parent 9c67b408de
commit 9b7985f530
Signed by: hairlesshobo
GPG Key ID: A89EDFF0F5E08A30
  1. 62
      Examples/Examples.sln
  2. 13
      Examples/Menu/Menu.csproj
  3. 91
      Examples/Menu/Program.cs
  4. 51
      Examples/ProgressBar/Program.cs
  5. 13
      Examples/ProgressBar/ProgressBar.csproj
  6. 53
      Examples/_shared/TaskHelpers.cs
  7. 7
      Examples/_shared/_shared.csproj

@ -0,0 +1,62 @@

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio Version 16
VisualStudioVersion = 16.6.30114.105
MinimumVisualStudioVersion = 10.0.40219.1
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ProgressBar", "ProgressBar\ProgressBar.csproj", "{C7A784FB-A69B-4C40-BE52-823A292E191E}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "_shared", "_shared\_shared.csproj", "{07720A0E-5290-4C8A-A378-ECB44F3C8814}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Menu", "Menu\Menu.csproj", "{2B67FF6B-C77E-4A80-A232-B102CD929BD2}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Debug|x64 = Debug|x64
Debug|x86 = Debug|x86
Release|Any CPU = Release|Any CPU
Release|x64 = Release|x64
Release|x86 = Release|x86
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{C7A784FB-A69B-4C40-BE52-823A292E191E}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{C7A784FB-A69B-4C40-BE52-823A292E191E}.Debug|Any CPU.Build.0 = Debug|Any CPU
{C7A784FB-A69B-4C40-BE52-823A292E191E}.Debug|x64.ActiveCfg = Debug|Any CPU
{C7A784FB-A69B-4C40-BE52-823A292E191E}.Debug|x64.Build.0 = Debug|Any CPU
{C7A784FB-A69B-4C40-BE52-823A292E191E}.Debug|x86.ActiveCfg = Debug|Any CPU
{C7A784FB-A69B-4C40-BE52-823A292E191E}.Debug|x86.Build.0 = Debug|Any CPU
{C7A784FB-A69B-4C40-BE52-823A292E191E}.Release|Any CPU.ActiveCfg = Release|Any CPU
{C7A784FB-A69B-4C40-BE52-823A292E191E}.Release|Any CPU.Build.0 = Release|Any CPU
{C7A784FB-A69B-4C40-BE52-823A292E191E}.Release|x64.ActiveCfg = Release|Any CPU
{C7A784FB-A69B-4C40-BE52-823A292E191E}.Release|x64.Build.0 = Release|Any CPU
{C7A784FB-A69B-4C40-BE52-823A292E191E}.Release|x86.ActiveCfg = Release|Any CPU
{C7A784FB-A69B-4C40-BE52-823A292E191E}.Release|x86.Build.0 = Release|Any CPU
{07720A0E-5290-4C8A-A378-ECB44F3C8814}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{07720A0E-5290-4C8A-A378-ECB44F3C8814}.Debug|Any CPU.Build.0 = Debug|Any CPU
{07720A0E-5290-4C8A-A378-ECB44F3C8814}.Debug|x64.ActiveCfg = Debug|Any CPU
{07720A0E-5290-4C8A-A378-ECB44F3C8814}.Debug|x64.Build.0 = Debug|Any CPU
{07720A0E-5290-4C8A-A378-ECB44F3C8814}.Debug|x86.ActiveCfg = Debug|Any CPU
{07720A0E-5290-4C8A-A378-ECB44F3C8814}.Debug|x86.Build.0 = Debug|Any CPU
{07720A0E-5290-4C8A-A378-ECB44F3C8814}.Release|Any CPU.ActiveCfg = Release|Any CPU
{07720A0E-5290-4C8A-A378-ECB44F3C8814}.Release|Any CPU.Build.0 = Release|Any CPU
{07720A0E-5290-4C8A-A378-ECB44F3C8814}.Release|x64.ActiveCfg = Release|Any CPU
{07720A0E-5290-4C8A-A378-ECB44F3C8814}.Release|x64.Build.0 = Release|Any CPU
{07720A0E-5290-4C8A-A378-ECB44F3C8814}.Release|x86.ActiveCfg = Release|Any CPU
{07720A0E-5290-4C8A-A378-ECB44F3C8814}.Release|x86.Build.0 = Release|Any CPU
{2B67FF6B-C77E-4A80-A232-B102CD929BD2}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{2B67FF6B-C77E-4A80-A232-B102CD929BD2}.Debug|Any CPU.Build.0 = Debug|Any CPU
{2B67FF6B-C77E-4A80-A232-B102CD929BD2}.Debug|x64.ActiveCfg = Debug|Any CPU
{2B67FF6B-C77E-4A80-A232-B102CD929BD2}.Debug|x64.Build.0 = Debug|Any CPU
{2B67FF6B-C77E-4A80-A232-B102CD929BD2}.Debug|x86.ActiveCfg = Debug|Any CPU
{2B67FF6B-C77E-4A80-A232-B102CD929BD2}.Debug|x86.Build.0 = Debug|Any CPU
{2B67FF6B-C77E-4A80-A232-B102CD929BD2}.Release|Any CPU.ActiveCfg = Release|Any CPU
{2B67FF6B-C77E-4A80-A232-B102CD929BD2}.Release|Any CPU.Build.0 = Release|Any CPU
{2B67FF6B-C77E-4A80-A232-B102CD929BD2}.Release|x64.ActiveCfg = Release|Any CPU
{2B67FF6B-C77E-4A80-A232-B102CD929BD2}.Release|x64.Build.0 = Release|Any CPU
{2B67FF6B-C77E-4A80-A232-B102CD929BD2}.Release|x86.ActiveCfg = Release|Any CPU
{2B67FF6B-C77E-4A80-A232-B102CD929BD2}.Release|x86.Build.0 = Release|Any CPU
EndGlobalSection
EndGlobal

@ -0,0 +1,13 @@
<Project Sdk="Microsoft.NET.Sdk">
<ItemGroup>
<ProjectReference Include="..\_shared\_shared.csproj" />
<ProjectReference Include="..\..\src\TerminalUI.csproj" />
</ItemGroup>
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net5.0</TargetFramework>
</PropertyGroup>
</Project>

@ -0,0 +1,91 @@
/*
* TerminalUI - Simple terminal widgets for C#
*
* Copyright (c) 2021 Steve Cross <flip@foxhollow.cc>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation; either version 2.1 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program; if not, see <http://www.gnu.org/licenses/>.
*/
using System;
using System.Collections.Generic;
using System.Threading;
using System.Threading.Tasks;
using FoxHollow.TerminalUI;
using FoxHollow.TerminalUI.Elements;
using FoxHollow.TerminalUI.Types;
namespace Examples.MenuExample
{
class Program
{
static void Main(string[] args)
{
Terminal.Run("Menu Example", "TerminalUI", RunExample);
}
static async Task RunExample(CancellationTokenSource cts)
{
List<MenuEntry> entries = new List<MenuEntry>()
{
new MenuEntry()
{
Name = "Header entry",
Header = true
},
new MenuEntry()
{
Name = "Standard entry",
Task = async (cToken) => await DoCountdown("You selected the standard entry", cToken)
},
new MenuEntry()
{
Name = "Disabled entry",
Task = (ctoken) => Task.CompletedTask,
Disabled = true
},
new MenuEntry()
{
Name = "Dangerous entry",
ForegroundColor = ConsoleColor.Red,
Task = async (cToken) => await DoCountdown("You seem to enjoy living dangeously...", cToken)
},
};
Menu menu = new Menu(entries);
menu.QuitCallback = () => {
cts.Cancel();
return Task.CompletedTask;
};
while (!cts.IsCancellationRequested)
await menu.ShowAsync(cts.Token);
}
private static async Task DoCountdown(string message, CancellationToken ctoken)
{
Text text = new Text(message, show: true);
Terminal.NextLine();
Terminal.NextLine();
Text countdown = new Text(show: true);
for (int i = 3; i > 0; i--)
{
countdown.UpdateValue($"{i}...");
if (!await TaskHelpers.Delay(1000, ctoken))
return;
}
}
}
}

@ -0,0 +1,51 @@
/*
* TerminalUI - Simple terminal widgets for C#
*
* Copyright (c) 2021 Steve Cross <flip@foxhollow.cc>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation; either version 2.1 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program; if not, see <http://www.gnu.org/licenses/>.
*/
using System.Threading;
using System.Threading.Tasks;
using FoxHollow.TerminalUI;
using FoxHollow.TerminalUI.Elements;
namespace Examples.ProgressBarExample
{
class Program
{
static void Main(string[] args)
{
Terminal.Run("ProgressBar Example", "TerminalUI", RunExample);
}
static async Task RunExample(CancellationTokenSource cts)
{
Text text = new Text("Loading the matrix ...", show: true);
Terminal.NextLine();
ProgressBar progress = new ProgressBar(show: true);
for (int i = 0; i <= 10; i++)
{
if (cts.IsCancellationRequested)
return;
progress.UpdateProgress((double)i / 10.0);
await TaskHelpers.Delay(400, cts.Token);
}
}
}
}

@ -0,0 +1,13 @@
<Project Sdk="Microsoft.NET.Sdk">
<ItemGroup>
<ProjectReference Include="..\..\src\TerminalUI.csproj" />
<ProjectReference Include="..\_shared\_shared.csproj" />
</ItemGroup>
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net5.0</TargetFramework>
</PropertyGroup>
</Project>

@ -0,0 +1,53 @@
/*
* TerminalUI - Simple terminal widgets for C#
*
* Copyright (c) 2021 Steve Cross <flip@foxhollow.cc>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation; either version 2.1 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program; if not, see <http://www.gnu.org/licenses/>.
*/
using System;
using System.Threading;
using System.Threading.Tasks;
namespace Examples
{
public static class TaskHelpers
{
/// <summary>
/// Simple wrapper for Task.Delay that returns a boolean indicating whether
/// the request was canceled or not.
/// </summary>
/// <param name="milliseconds">Milliseconds to delay</param>
/// <param name="cToken">Token that allows for cancellation of the delay</param>
/// <returns>
/// Booleaning indicating cancel status.
///
/// false = Delay was canceled prematurely
/// true = Delay executed to the end without being canceled
/// </returns>
public static async Task<bool> Delay(int milliseconds, CancellationToken cToken)
{
try {
await Task.Delay(milliseconds, cToken);
return true;
}
catch(TaskCanceledException)
{
return false;
}
}
}
}

@ -0,0 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>netstandard2.0</TargetFramework>
</PropertyGroup>
</Project>
Loading…
Cancel
Save