CGui 1.3.0

dotnet add package CGui --version 1.3.0
                    
NuGet\Install-Package CGui -Version 1.3.0
                    
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="CGui" Version="1.3.0" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="CGui" Version="1.3.0" />
                    
Directory.Packages.props
<PackageReference Include="CGui" />
                    
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 CGui --version 1.3.0
                    
#r "nuget: CGui, 1.3.0"
                    
#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 CGui@1.3.0
                    
#: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=CGui&version=1.3.0
                    
Install as a Cake Addin
#tool nuget:?package=CGui&version=1.3.0
                    
Install as a Cake Tool

CGui4Net

Library with controls to create application with console-based user interface.

Console Gui for .net

PM> Install-Package Cgui -Version 1.3.0

Curently supported controls:

  • Picklist - Shows a list of options and allows user to pick one
  • TextArea - Renders scrollable text
  • Header - Row rendered on top
  • Footer - Row rendered on bottom
  • Input - Allows user to input text
  • Viewport - groups UI elements and renders them asynchronously

Usage

This library was created to provide simple text based UI for console applications. I use it it my project cfeed - console feed reader.

Picklist

Picklist enables you to show scrollable list of items, and handle keyboard keys, wheter on selected item or globally. Example usage:

var l = new CGui.Gui.Picklist<string>(list, null)
{
    Left = 0,
    Top = 2,
    Width = 40,
    Height = 6,
    ShowScrollbar = true,
    TextAlignment = TextAlignment.Left,
};
l.OnItemKeyHandler += List_OnItemKeyHandler;
l.Show();

Here "list" variable is just list of strings, that are displayed in menu. List_OnItemKeyHandler is defined as:

private static bool List_OnItemKeyHandler
(ConsoleKeyInfo key, ListItem<string> selectedItem, Picklist<string> parent)
{
    if (key.Key == ConsoleKey.Enter)
    {
        Debug.WriteLine(selectedItem.Value);
    }
    if (key.Key == ConsoleKey.Escape)
    {
        ///returning false exits the keyboard loop
        return false;
    }
    ///return true to continue capturing keyboard input
    return true;
}

Resizing the console

Controls can be sized relative to the console: a negative Width or Height is the size of the console minus that number, so Width = -3 is the console width minus 3. Such a control follows the console when the window is resized.

var l = new CGui.Gui.Picklist<string>(list, null)
{
    Top = 1,
    Left = 2,
    Width = -3,   // console width - 3
    Height = -3,  // console height - 3
    ShowScrollBar = true
};

A viewport that is on screen draws all its controls again when the console is resized, once the new size has settled. The lists keep the selected item visible, the text areas wrap their text for the new width, and a header or footer that is longer than the window is shortened. This happens while a control waits for a key, so it needs no extra code. Set Viewport.RefreshOnResize to false to turn it off. The events Viewport.Resizing (before the redraw) and Viewport.Resized (after it) can be used to adjust elements that are not controls of the viewport. ConsoleWrapper.Instance.Resized is raised for every settled resize.

A list or text area that waits for keys but is not a control of the viewport, like a dialog, is not redrawn on top of it. The resize is applied when it closes.

A Viewport does not change the size of the console window when it is created. Set Viewport.Width and Viewport.Height to resize the window, for example once at startup. To try resizing, run CGuiDemo --resize list or CGuiDemo --resize text.

Product Compatible and additional computed target framework versions.
.NET Framework net461 is compatible.  net462 was computed.  net463 was computed.  net47 was computed.  net471 was computed.  net472 was computed.  net48 was computed.  net481 was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.
  • .NETFramework 4.6.1

    • 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
1.3.0 233 10/9/2026
1.2.1 3,043 1/30/2019

1.3.0
The console can be resized while the application runs. A viewport that is on screen is drawn again for the new size.
- A negative Width or Height of a control (relative to the console) is kept as it was set, and follows the console. Before it was turned into a fixed number when it was set.
- TextArea wraps its text again when its width changes, and does not fail for a very narrow width.
- Picklist keeps the selected item visible when its height changes. ListHeight is public.
- Header, Footer and Input rows shorten text that is longer than the window, instead of wrapping to the next line.
- New: Viewport.RefreshOnResize, Viewport.Resizing, Viewport.Resized and ConsoleWrapper.Resized.
- Breaking: the Viewport constructor no longer changes the size of the console window, set Viewport.Width and Height for that.

1.2.1
Fixed scrolling past the max pages count. Still some quirks, needs testing.

1.2.0
Changes in IScrollable class to support custom scroll char.