-
Notifications
You must be signed in to change notification settings - Fork 0
Setting Up the Terminal
In order to use Sharpie one needs the following prerequisites:
- NCurses installed. Most Unix-like systems have this library installed by default,
- PDCurses or PDCursesMod installed. These can be obtained from https://github.com/wmcbrine/PDCurses or https://github.com/Bill-Gray/PDCursesMod and built for the local environment.
- .NET 6.0+,
- The Nuget package installed,
- A console app project.
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.
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.