Skip to content

Setting Up the Terminal

Alexandru Ciobanu edited this page Jan 5, 2023 · 5 revisions

Prerequisites

In order to use Sharpie one needs the following prerequisites:

Initialization

Before the Terminal is usable, one needs to initialize the desired Curses library. This can be achieved by using CursesBackend class as follows:

ICursesBackend backend;
try 
{
    backend = CursesBackend.Load()) 
} catch (CursesInitializationException error) 
{
    Console.WriteLine("Sorry, no compatible Curses library found.");
    return 1;
}

The CursesBackend.Load() can be invoked with an additional argument of type CursesBackend.Provider. This enumeration lists the supported backed. By default Load() uses CursesBackend.Provider.Any to try to load any of the available Curses libraries. You can, also, specify the library manually by calling Load(CursesBackend.Provider.NCurses, "/path/to/curses/or/lib/name").

The next step is selecting the terminal options by using the TerminalOptions class.

And finally, one needs to create an instance of the Terminal class, passing the ICursesProvider and TerminalOptions as arguments.

Example:

var backend = CursesBackend.NCurses();
var options = new TerminalOptions(UseMouse: false);
using var terminal = new Terminal(backend, options);

// .. the rest of your application here.

Note: One needs to make sure to Dispose of the terminal instances. Otherwise, the terminal state would not be restored upon application exit.

Next Steps

Once an instance of Terminal is created, one can use all its functionality to interface with Curses. The principal members to look for are:

  • Screen, which contains a reference to the main Screen window which is automatically set up by Curses,
  • Colors, which offers functionality to manage colors,
  • SoftLabelKeys, which allows the creation of bottom status-bar-like artifacts,
  • Events, to start processing events.

For more information about Curses visit this website.

Clone this wiki locally