FSC-Terminal 1.3.1

dotnet add package FSC-Terminal --version 1.3.1
NuGet\Install-Package FSC-Terminal -Version 1.3.1
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="FSC-Terminal" Version="1.3.1" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add FSC-Terminal --version 1.3.1
#r "nuget: FSC-Terminal, 1.3.1"
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
// Install FSC-Terminal as a Cake Addin
#addin nuget:?package=FSC-Terminal&version=1.3.1

// Install FSC-Terminal as a Cake Tool
#tool nuget:?package=FSC-Terminal&version=1.3.1

FSC.Terminal

A better version of the console class in C#

What is FSC.Terminal?

Terminal is the same like the console class. It uses generics in some methods and offers the possibility to write a hidden password. You can choose a password char or just use nothing like in the most linux software. Try it out and you will notice how similar it is to the default console class, but still so much advanced

Example Script

using FSC;

namespace ConsoleApp1
{
    internal class Program
    {
        static void Main(string[] args)
        {
            Terminal.Title = "Example";

            Terminal.WriteLine("Welcome!");
            Terminal.WriteLine();

            string? name = Terminal.ReadLine("Please enter your username: ");
            string? password = Terminal.ReadLine("Please enter your password: ", TerminalPasswordMode.Hide);
            
            Terminal.WriteLine("Thank you. You are logged in. If you want to see your inputted data, write yes");
            
            if (Terminal.ReadLine() == "yes")
            {
                Terminal.WriteLine($"Username: {name}{Environment.NewLine}Password: {password}");
            }

            Terminal.ReadKey();
        }
    }
}

Output

Welcome!

Please enter your username: JohnDoe
Please enter your password:
Thank you. You are logged in. If you want to see your inputted data, write yes
yes
Username: JohnDoe
Password: 12345678

If you choose the right password mode, the password will not be visible

Example Script 2

Terminal.WriteLine("Hello User,");
string[] starSelection = { "*", "**", "***", "****", "*****" };

int index = ReadSelection("if you like, what we do, rate us with 5 stars, please", starSelection);

if (index >= 0 && index <= 2)
{
    Terminal.WriteLine("Oh, we are sorry to hear about this sad feedback");
}
else
{
    Terminal.WriteLine("Wow, thank you for your feedback");
}

Terminal.ReadKey();

The index is the index of the array or list that is given

Output 2

Hello User,
if you like, what we do, rate us with 5 stars, please
> *
**
***
****
*****

After pressing enter

Hello User,
if you like, what we do, rate us with 5 stars, please
*****
Wow, thank you for your feedback

Example Script 3

bool userAgreed = Terminal.ReadYesNo("Do you agree our ToS and privacy policy?", 'y', 'N')

The user can only input y or N. This can not be canceled with the escape key.

Example 4

static void Main(string[] args)
{
    Terminal.Title = "License Input";
    while (true)
    {
        Terminal.WriteLine("Hello");
        if (Terminal.ReadLicense("Please enter a license: ", out string value, 4, 4))
        {
            Terminal.WriteLine("You entered " + value);
            break;
        }
        else
        {
            Terminal.WriteLine("Invalid license ...");
        }
    }
    Terminal.ReadKey(true);
}

Output 4

Hello
Please enter a license: ____-____-____-____

How a program could look like:

using FSC;

namespace TestApp
{
    internal class Program
    {
        static void Main(string[] args)
        {
            Terminal.Title = "Delivery Service - Login";

            Terminal.WriteLine("Hello and welcome. What is your name?");

            string? username = Terminal.ReadLine("Username: ");

            bool showPassword = Terminal.ReadYesNo("Do you want to show your Password as * or keep it totally invisible? Choose between ", '*', 'i');

            Terminal.WriteLine("Awesome.");
            string? password = Terminal.ReadLine("Please enter your password: ", showPassword ? TerminalPasswordMode.HideByChar : TerminalPasswordMode.Hide);

            if (username != "john" || password != "doe")
            {
                Terminal.WriteLine("We are sorry, this account is not part of our organisation.");
                Terminal.ReadKey(true);
                return;
            }

            Terminal.WriteLine("Great, you are logged in!");

            Thread.Sleep(2_000);

            Terminal.Clear();

            Terminal.Title = "Delivery Service";

            string[] foodOfTheDay = { "Greek food", "Chinese food", "Italian food", "German food", "French food", "American food" };

            int index = Terminal.ReadSelection("Today is random food day, but you may still select, what kind of food you want (Press Escape to cancel the order):", true, foodOfTheDay);

            if (index == -1)
            {
                Terminal.WriteLine("Oh, we are sorry to hear that. We hope you change your mind and come back soon.");
                Terminal.ReadKey(true);
                return;
            }

            Thread.Sleep(2_000);

            DateTime time = DateTime.Now;

            while (true)
            {
                Terminal.Clear();
                Terminal.WriteLine($"Thank you for ordering at <Delivery Service>. Your order #{index}#{foodOfTheDay[index]}# got submitted and will arrive in {(time - DateTime.Now).Minutes + 25} minutes.");
                Thread.Sleep(60_000);
            }
        }
    }
}
Product Compatible and additional computed target framework versions.
.NET net5.0 was computed.  net5.0-windows was computed.  net6.0 is compatible.  net6.0-android was computed.  net6.0-ios was computed.  net6.0-maccatalyst was computed.  net6.0-macos was computed.  net6.0-tvos was computed.  net6.0-windows was computed.  net7.0 is compatible.  net7.0-android was computed.  net7.0-ios was computed.  net7.0-maccatalyst was computed.  net7.0-macos was computed.  net7.0-tvos was computed.  net7.0-windows was computed.  net8.0 is compatible.  net8.0-android was computed.  net8.0-browser was computed.  net8.0-ios was computed.  net8.0-maccatalyst was computed.  net8.0-macos was computed.  net8.0-tvos was computed.  net8.0-windows was computed. 
.NET Core netcoreapp2.0 was computed.  netcoreapp2.1 was computed.  netcoreapp2.2 was computed.  netcoreapp3.0 was computed.  netcoreapp3.1 was computed. 
.NET Standard netstandard2.0 is compatible.  netstandard2.1 was computed. 
.NET Framework net46 is compatible.  net461 was computed.  net462 was computed.  net463 was computed.  net47 is compatible.  net471 was computed.  net472 was computed.  net48 is compatible.  net481 was computed. 
MonoAndroid monoandroid was computed. 
MonoMac monomac was computed. 
MonoTouch monotouch was computed. 
Tizen tizen40 was computed.  tizen60 was computed. 
Xamarin.iOS xamarinios was computed. 
Xamarin.Mac xamarinmac was computed. 
Xamarin.TVOS xamarintvos was computed. 
Xamarin.WatchOS xamarinwatchos was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last updated
1.3.1 186 12/9/2023
1.3.0 97 12/9/2023
1.2.0 196 4/4/2023
1.1.0 191 2/22/2023
1.0.0 217 2/14/2023

Added WritePicture to display a picture on the console as ASCII art. Added the possibility to set the title on other platforms than windows.