Skip to content

guylangston/ConsoleZ

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

ConsoleZ

A modern multi-target (console/web/gui/tests) console rendering library

Why use this library? What use cases?

  • Want a common interface/experiance across console and web apps?
  • Want a richer output (colours, progress graphs)?
  • Want to make a retro-console game like Tetris, Snake?
  • Want Markdown in the console?

What this library does NOT do:

  • Console Argument parsing
  • Midnight-Commander like console forms. Rather use the wonderful GUI.cs
  • Unix support (Windows-only at this stage)

Why?

Key Features (done vs. in-progress):

  • Windows 10 Console: ANSI Escape Codes
  • Alternative human readble inline colour formatting "^red;Error:^; Message"
  • Fast full-screen updates. Allows Retro Console games. https://onelonecoder.com/olcconsolegameengine/
  • Unified IConsole working with HTML, WinForms, Console
  • UI Components : Percentage Complete Graph, etc
  • ASCII large fonts
  • Markdown formatting
  • Safe Chaining (write to file)

NuGet Packages

Status

This library is ALPHA status. Meaning core interfaces may change. At present this library is not ready for production.

Please create a github issue for any features/bugs.

Screenshots

ANSI Colour in Console HTML Console Tetris

Key C# interface

What will I be programming against?

public interface ITextWriter
{
    int WriteLine(string s);        // We don't use Write, rather update the whole line
    int WriteFormatted(FormattableString formatted);
}

public interface IConsole : ITextWriter
{
    string Handle { get; }
    int Version { get;  }

    int Width { get; }
    int Height { get; }
    int DisplayStart { get;  }
    int DisplayEnd { get; }

    void UpdateLine(int line, string txt);
    void UpdateFormatted(int line, FormattableString formatted);
}

The Idea?

In my current project we have lots of command logic that output calculation reports to the console. As the functionaliy matures, or reaches a larger audience, the it gets ported to the web.

Would it not be great if the console and html versions share the same interface and rendering abilities:

  • Console Renders Markdown with ASCII-art and Console standard colours (Find closest Color -< ConsoleColour)
  • Html Renders to a virtual console (thread-safe) and renders HTML Markdown

Features:

  • Markdown is the common format (Rendering to Console or HTML)
  • ANSI escaping (+ HTML mapping)
  • Threadsafe for the web (many IVirtualConsoles at once)
  • Easy inline colours "Hello ^red;World^;" <-> string.Format("Hello {0}World{1}", Color.Red, Color.Default)
  • Updating progress bars [###... 50%]
  • Standard ASP.NET core console terminal
  • Very Fast console update/FPS see: https://github.com/OneLoneCoder/videos/blob/master/olcConsoleGameEngine.h

Stretch:

  • Wolfram-style cell input/output consoles
  • SignalR polling to update console (vs polling ever sec)

Getting started

You can start with a normal console app then:

static void Main(string[] args)
{
    var cons = AnsiConsole.Singleton;
    cons.WriteLine("Hello World");
    cons.WriteLine("Have a ^red;wonderful^; day!");
    var idx = cons.WriteLine("Replace me");
    cons.UpdateLine(ids, "I was replaced. ;-)");
}

Hello World

Research / Related projects

Search Terms:

  • "color console C#"
  • "enhanced c# console"

About

Enhanced Console featuring color encoding, fast rendering, markdown, html mapper

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published