ConsolaUI 0.0.4

dotnet add package ConsolaUI --version 0.0.4
                    
NuGet\Install-Package ConsolaUI -Version 0.0.4
                    
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="ConsolaUI" Version="0.0.4" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="ConsolaUI" Version="0.0.4" />
                    
Directory.Packages.props
<PackageReference Include="ConsolaUI" />
                    
Project file
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add ConsolaUI --version 0.0.4
                    
#r "nuget: ConsolaUI, 0.0.4"
                    
#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.
#:package ConsolaUI@0.0.4
                    
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=ConsolaUI&version=0.0.4
                    
Install as a Cake Addin
#tool nuget:?package=ConsolaUI&version=0.0.4
                    
Install as a Cake Tool

ConsolaUI

For a programming project, I needed to create a console UI. Instead of hardcoding a basic UI with the standard library, I quickly built my own framework for console interfaces. It's simple, but probably better than just using Console.WriteLine. (maybe)

Usage

App

First of all, you need to create a class that inherits from AppBase.
For a most basic application, you only need to override a GetInitialPage method. This method will provide a basic page that will be displayed when the application starts.

Page

A page is a screen that will be displayed to the user.
You can create a page by inheriting from PageBase.

In the constructor you need to pass your AppBase object (just using this).
You need to override the Markup method to define the content of the page.

Elements

You can add elements to the page by using the AddElement method.
Or use pre-defined methods in PageBase class such as Text, InputField, Button, etc.

Also, you can create your own elements by inheriting from ElementBase class.

Example

class Program
{
    static void Main(string[] args)
    {
        MyApp app = new MyApp();
        app.Run();
    }
}

class MyApp : AppBase
{
    protected override PageBase GetInitialPage()
    {
        return new MainPage(this);
    }
}
class MainPage : PageBase 
{
    private string? _name = null;
    private bool _clicked = false;
    
    public MainPage(AppBase app) : base(app) 
    {
    }
    
    protected override void Markup() 
    {
        Text($"Hello, {_name}");
        NewLine();
        InputField("Enter your name: ", input =>
        {
            _name = input;
            Redraw();
        });
        NewLine();
        Button("Click me", () =>
        {
            _clicked = true;
            Redraw();
        });
        if (_clicked)
        {
            NewLine();
            Text("You clicked me!");
        }
    }
}

Tips

You can use ChangePage() method in your PageBase class to change the current page of an app.

Product Compatible and additional computed target framework versions.
.NET net9.0 is compatible.  net9.0-android was computed.  net9.0-browser was computed.  net9.0-ios was computed.  net9.0-maccatalyst was computed.  net9.0-macos was computed.  net9.0-tvos was computed.  net9.0-windows was computed.  net10.0 was computed.  net10.0-android was computed.  net10.0-browser was computed.  net10.0-ios was computed.  net10.0-maccatalyst was computed.  net10.0-macos was computed.  net10.0-tvos was computed.  net10.0-windows was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.
  • net9.0

    • No dependencies.

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
0.0.4 244 3/17/2025
0.0.3 177 2/27/2025
0.0.2 183 2/26/2025
0.0.1 170 2/26/2025