* touching publish.yml * ColorScheme->Scheme * ColorScheme->Scheme 2 * Prototype of GetAttributeForRole * Badly broke CM * Further Badly broke CM * Refactored CM big-time. View still broken * All unit test pass again. Tons added. CM is still WIP, but Schemes is not mostly refactored and working. * Actually: All unit test pass again. Tons added. CM is still WIP, but Schemes is not mostly refactored and working. * Bug fixes. DeepMemberWiseClone cleanup * Further cleanup of Scope<T>, ConfigProperty, etc. * Made ConfigManager thread safe. * WIP: Broken * WIP: new deep clone impl * WIP: new deep clone impl is done. Now fixing CM * WIP: - config.md - Working on AOT clean up - Core CM is broken; but known. * WIP * Merged. Removed CM from Application.Init * WIP * More WIP; Less broke * All CM unit tests pass... Not sure if it actually works though * All unit tests pass... Themes are broken though in UI Cat * CM Ready for review? * Fixed failures due to TextStyles PR * Working on Scheme/Attribute * Working on Scheme/Attribute 2 * Working on Scheme/Attribute 3 * Working on Scheme/Attribute 4 * Working on Scheme/Attribute 5 * Working on Scheme/Attribute 6 * Added test to show how awful memory usage is * Improved schema. Updated config.json * Nade Scope<T> concurrentdictionary and added test to prove * Made Themes ConcrurrentDictionary. Added bunches of tests * Code cleanup * Code cleanup 2 * Code cleanup 3 * Tweaking Scheme * ClearJsonErrors * ClearJsonErrors2 * Updated Attribute API * It all (mostly) works! * Skip odd unit test * Messed with Themes * Theme tweaks * Code reorg. New .md stuff * Fixed Enabled. Added mock driver * Fixed a bunch of View.Enabled related issues * Scheme -> Get/SetScheme() * Cleanup * Cleanup2 * Broke something * Fixed everything * Made CM.Enable better * Text Style Scenario * Added comments * Fixed UI Catalog Theme Changing * Fixed more dynamic CM update stuff * Warning cleanup * New Default Theme * fixed unit test * Refactoring Scheme and Attribute to fix inheritance * more unit tests * ConfigProperty is not updating schemes correctly * All unit tests pass. Code cleanup * All unit tests pass. Code cleanup2 * Fixed unit tests * Upgraded TextField and TextView * Fixed TextView !Enabled bug * More updates to TextView. More unit tests for SchemeManager * Upgraded CharMap * API docs * Fixe HexView API * upgrade HexView * Fixed shortcut KeyView * Fixed more bugs. Added new themes * updated themes * upgraded Border * Fixed themes memory usage...mostly * Fixed themes memory usage...mostly2 * Fixed themes memory usage...2 * Fixed themes memory usage...3 * Added new colors * Fixed GetHardCodedConfig bug * Added Themes Scenario - WIP * Added Themes Scenario * Tweaked Themes Scenario * Code cleanup * Fixed json schmea * updated deepdives * updated deepdives * Tweaked Themes Scenario * Made Schemes a concurrent dict * Test cleanup * Thread safe ConfigProperty tests * trying to make things more thread safe * more trying to make things more thread safe * Fixing bugs in shadowview * Fixing bugs in shadowview 2 * Refactored GetViewsUnderMouse to GetViewsUnderLocation etc... * Fixed dupe unit tests? * Added better description of layout and coordiantes to deep dive * Added better description of layout and coordiantes to deep dive * Modified tests that call v2.AddTimeout; they were returning true which means restart the timer! This was causing mac/linux unit test failures. I think * Fixed auto scheme. Broke TextView/TextField selection * Realized Attribute.IsExplicitlySet is stupid; just use nullable * Fixed Attribute. Simplified. MOre theme testing * Updated themes again * GetViewsUnderMouse to GetViewsUnderLocation broke TransparentMouse. * Fixing mouseunder bugs * rewriting... * All working again. Shadows are now slick as snot. GetViewsUnderLocation is rewritten to actually work and be readable. Tons more low-level unit tests. Margin is now actually ViewportSettings.Transparent. * Code cleanup * Code cleanup * Code cleanup of color apis * Fixed Hover/Highlight * Update Examples/UICatalog/Scenarios/AllViewsTester.cs Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> * Update Examples/UICatalog/Scenarios/CharacterMap/CharacterMap.cs Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> * Update Examples/UICatalog/Scenarios/Clipping.cs Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> * Fixed race condition? * reverted * Simplified Attribute API by removing events from SetAttributeForRole * Removed recursion from GetViewsAtLocation * Removed unneeded code * Code clean up. Fixed Scheme bug. * reverted temporary disable * Adjusted scheme algo * Upgraded TextValidateField * Fixed TextValidate bugs * Tweaks * Frameview rounded border by default * API doc cleanup * Readme fix * Addressed tznind feeback * Fixed more unit test issues by protecting Application statics from being set if Application.Initialized is not true * Fixed more unit test issues by protecting Application statics from being set if Application.Initialized is not true 2 * cleanup --------- Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
9.4 KiB
Terminal.Gui v2 Overview
A toolkit for building rich Terminal User Interface (TUI) apps with .NET that run on Windows, the Mac, and Linux/Unix.
(This is the v2 API documentation. For v1 go here: https://gui-cs.github.io/Terminal.Gui/api/Terminal.Gui.html)
Features
- Cross Platform - Windows, Mac, and Linux. Terminal drivers for Curses, Windows, and the .NET Console mean apps will work well on both color and monochrome terminals. Apps also work over SSH.
- Templates - The
dotnet newcommand can be used to create a new Terminal.Gui app. - Extensible UI - All visible UI elements are subclasses of the
Viewclass, and these in turn can contain an arbitrary number of sub-views. Dozens of Built-in Views are provided. - Keyboard and Mouse Input - The library handles all the details of input processing and provides a simple event-based API for applications to consume.
- Powerful Layout Engine - The layout engine makes it easy to lay out controls relative to each other and enables dynamic terminal UIs.
- Machine, User, and App-Level Configuration - Persistent configuration settings, including overriding default look & feel with Themes, keyboard bindings, and more via the ConfigurationManager class.
- Clipboard support - Cut, Copy, and Paste is provided through the [
Clipboard] class. - Multi-tasking - The Mainloop supports processing events, idle handlers, and timers. Most classes are safe for threading.
- Reactive Extensions - Use reactive extensions and benefit from increased code readability, and the ability to apply the MVVM pattern and ReactiveUI data bindings. See the source code of a sample app.
See What's New in V2 For more.
Conceptual Documentation
- Arrangement API
- Cancellable Work Pattern
- Configuration and Theme Manager
- Command Deep Dive
- Cursor Deep Dive
- Cross-platform Driver Model
- Dim.Auto Deep Dive
- Drawing
- Events Deep Dive
- Keyboard API
- Layout Engine
- Migrating from Terminal.Gui v1
- Mouse API
- Multi-tasking and the Application Main Loop
- Navigation
- Popovers
- View Deep Dive
- Views
- Scrolling Deep Dive
- TableView Deep Dive
- TreeView Deep Dive
The simplest application looks like this:
using Terminal.Gui;
ConfigurationManager.Enable(ConfigLocations.All);
Application.Init ();
var n = MessageBox.Query (50, 5, "Question", "Do you like TUI apps?", "Yes", "No");
Application.Shutdown ();
return n;
This example shows a prompt and returns an integer value depending on which value was selected by the user.
More interesting user interfaces can be created by composing some of the various View classes that are included.
In the example above, @Terminal.Gui.Application.Init(Terminal.Gui.IConsoleDriver,System.String) sets up the environment, initializes the color schemes, and clears the screen to start the application.
The Application class additionally creates an instance of the Toplevel View available in the Application.Top property, and can be used like this:
using Terminal.Gui;
ConfigurationManager.Enable(ConfigLocations.All);
Application.Init ();
var label = new Label () {
Title = "Hello World",
X = Pos.Center (),
Y = Pos.Center (),
Height = 1,
};
var app = new Toplevel ();
app.Add (label);
Application.Run (app);
app.Dispose ();
Application.Shutdown ();
This example includes a menu bar at the top of the screen and a button that shows a message box when clicked:
using Terminal.Gui;
ConfigurationManager.Enable(ConfigLocations.All);
Application.Init ();
var menu = new MenuBar (new MenuBarItem [] {
new MenuBarItem ("_File", new MenuItem [] {
new MenuItem ("_Quit", "", () => {
Application.RequestStop ();
})
}),
});
var button = new Button () {
Title = "_Hello",
X = 0,
Y = Pos.Bottom (menu),
Width = Dim.Fill (),
Height = Dim.Fill () - 1
};
button.Accepting += () => {
MessageBox.Query (50, 5, "Hi", "Hello World! This is a message box", "Ok");
};
var app = new Toplevel ();
// Add both menu and win in a single call
top.Add (menu, button);
Application.Run (top);
top.Dispose ();
Application.Shutdown ();
Views
All visible elements in a Terminal.Gui application are implemented as Views. Views are self-contained objects that take care of displaying themselves, can receive keyboard and mouse input and participate in the focus mechanism.
See the full list of Views provided by the Terminal.Gui library here.
Every view can contain an arbitrary number of child views, called SubViews. Call @Terminal.Gui.View.Add(View) to add a couple of buttons to a UI:
void SetupMyView (View myView)
{
var label = new Label () {
Title = "_Username:"
X = 1,
Y = 1,
Width = 20,
Height = 1
};
myView.Add (label);
var username = new TextField () {
X = Pos.Right (label) + 1,
Y = 2,
Width = 30,
Height = 1
};
myView.Add (username);
}
The container of a given view is called the SuperView and it is a property of every View.
Modal Views
Views can either be Modal or Non-modal. Modal views take over all user input until the user closes the View. Examples of Modal Views are Toplevel, Dialog, and Wizard. Non-modal views can be used to create a new experience in your application, one where you would have a new top-level menu for example. Setting the Modal property on a View to true makes it modal.
To run any View (but especially Dialogs, Windows, or Toplevels) modally, invoke the Application.Run method on a Toplevel. Use the Application.RequestStop() method to terminate the modal execution.
There is no return value from running modally, so the modal view must have a mechanism to indicate the reason the modal was closed. In the case above, the okpressed value is set to true if the user pressed or selected the Ok button.
Windows
Window is a view used in Overlapped layouts, providing a frame and a title - and can be moved and sized with the keyboard or mouse.
Dialogs
Dialogs are Modal Windows that are centered in the middle of the screen and are intended to be used modally - that is, they run, and they are expected to return a result before resuming execution of the application.
Dialogs expose an API for adding buttons and managing the layout such that buttons are at the bottom of the dialog (e.g. AddButton).
Example:
bool okpressed = false;
var ok = new Button() { Title = "Ok" };
var cancel = new Button() { Title = "Cancel" };
var dialog = new Dialog () { Text = "Are you sure you want to quit?", Title = "Quit", Buttons = { ok, cancel } };
Which will show something like this:
+- Quit -----------------------------------------------+
| Are you sure you want to quit? |
| |
| [ Ok ] [ Cancel ] |
+------------------------------------------------------+
Wizards
Wizards are Dialogs that let users step through a series of steps to complete a task.
╔╡Gandolf - The last step╞════════════════════════════════════╗
║ The wizard is complete! ║
║☐ Enable Final Final Step ║
║ Press the Finish ║
║ button to continue. ║
║ ║
║ Pressing ESC will ║
║ cancel the wizard. ║
║ ║
║ ║
║─────────────────────────────────────────────────────────────║
║⟦ Back ⟧ ⟦► Finish ◄⟧║
╚═════════════════════════════════════════════════════════════╝