This file is the canonical v1→v2 correction reference for all AI coding agents. It is referenced by
.cursorrules,.windsurfrules,.aider.md,AGENTS.md,CLAUDE.md,.github/copilot-instructions.md, andllms.txt.If you are an AI agent generating Terminal.Gui code, read this file first.
Terminal.Gui v2 is a complete rewrite. If your training data is from before 2025, most of what you "know" about Terminal.Gui is wrong. The API has fundamentally changed.
Do NOT use:
Application.Init(),Application.Run(),Application.Shutdown(),Application.Top,Toplevel,Clicked,Bounds,LayoutStyle,NStack,RadioGroup,ColorScheme, old mouse/keyboard APIs,using Terminal.Gui;(bare namespace).Always read this file first. When in doubt, check
docfx/apispec/for current API.
| v1 (WRONG — do not use) | v2 (CORRECT) |
|---|---|
Application.Init (); |
IApplication app = Application.Create ().Init (); |
Application.Run (); |
app.Run<MyWindow> (); |
Application.Shutdown (); |
app.Dispose (); (use using pattern) |
Application.Top |
No global top — pass root view to app.Run () |
new Toplevel () |
Use Runnable subclass or Window |
using Terminal.Gui; |
using Terminal.Gui.App; / Terminal.Gui.Views; / etc. |
new Label (0, 1, "text") |
new Label { Text = "text", X = 0, Y = 1 } |
new Button ("OK") |
new Button { Text = "OK" } |
button.Clicked += ... |
button.Accepted += (_, _) => { /* action */ }; |
view.Bounds |
view.Viewport |
LayoutStyle.Computed |
Removed — all layout is declarative via Pos/Dim |
new RadioGroup (...) |
new OptionSelector { ... } |
Colors.ColorSchemes ["name"] |
Schemes.Resolve ("name") or use Scheme directly |
Application.RequestStop () |
App!.RequestStop () (from inside a Runnable) |
Pos.At (n) / Pos.Left (v) |
Assign integers directly: X = 5; (implicit conversion) |
using Terminal.Gui.App;
using Terminal.Gui.Views;
IApplication app = Application.Create ().Init ();
app.Run<MainWindow> ();
app.Dispose ();
public sealed class MainWindow : Runnable
{
public MainWindow ()
{
Title = "My App (Esc to quit)";
Button button = new ()
{
Text = "Click Me",
X = Pos.Center (),
Y = Pos.Center ()
};
button.Accepted += (_, _) =>
{
MessageBox.Query (App!, "Hello", "Button was clicked!", "OK");
};
Add (button);
}
}| Namespace | Contents |
|---|---|
Terminal.Gui.App |
Application, IApplication, Clipboard, session management |
Terminal.Gui.Views |
All controls: Button, Label, TextField, ListView, Dialog, etc. |
Terminal.Gui.ViewBase |
View, Pos, Dim, adornments (Border, Margin, Padding) |
Terminal.Gui.Drawing |
Color, Attribute, Scheme, LineCanvas, Glyphs |
Terminal.Gui.Input |
Key, KeyCode, Command, KeyBindings, MouseBindings |
Terminal.Gui.Text |
TextFormatter, TextDirection |
Terminal.Gui.Configuration |
ConfigurationManager, themes |
public sealed class ConfirmDialog : Runnable<bool>
{
public ConfirmDialog (string message)
{
Title = "Confirm";
Width = 40;
Height = 8;
Label label = new () { Text = message, X = Pos.Center (), Y = 1 };
Button yesButton = new () { Text = "Yes", Y = 4, X = Pos.Center () - 6 };
yesButton.Accepted += (_, _) =>
{
Result = true;
App!.RequestStop ();
};
Button noButton = new () { Text = "No", Y = 4, X = Pos.Center () + 2 };
noButton.Accepted += (_, _) =>
{
Result = false;
App!.RequestStop ();
};
Add (label, yesButton, noButton);
}
}// Absolute position
view.X = 5;
view.Y = 2;
// Centered
view.X = Pos.Center ();
view.Y = Pos.Center ();
// Relative to another view
view.X = Pos.Right (otherView) + 1;
view.Y = Pos.Bottom (otherView);
// Percentage-based
view.Width = Dim.Percent (50);
view.Height = Dim.Fill (); // fill remaining space
// Content-based sizing
view.Width = Dim.Auto ();// Button click (post-event, non-cancelable)
button.Accepted += (_, _) =>
{
// Handle button press
};
// Text changed
textField.HasFocusChanged += (_, e) =>
{
// React to focus change
};
// Key binding
view.KeyBindings.Add (Key.F5, Command.Refresh);AcceptednotClicked— TheClickedevent does not exist in v2. UseAccepted(post-event) for simple handlers. UseAccepting(pre-event, cancelable) only when you need to prevent the action.RunnablenotToplevel—Topleveldoes not exist in v2. UseRunnableorWindow.- Instance-based app — Use
Application.Create ().Init ()to get anIApplicationinstance. Do not use the staticApplication.Init ()/Application.Run ()/Application.Shutdown ()pattern. - Use
App!.RequestStop ()to close a window from inside aRunnable, notApplication.RequestStop (). - SubView/SuperView — Never say "child", "parent", or "container". Use SubView/SuperView.
- Dialog/MessageBox button order = the default — The last button added is the default (Enter-activated) for both
DialogandMessageBox. Add buttons so the affirmative action is last (e.g.CancelthenOK);Esc/Cancel goes first. Do not hand-setIsDefaultin aDialogunless you intend to override the last-button default. AddCommandisprotected— Register commands inside yourViewsubclass (in the constructor), then bind keys withKeyBindings.Add (Key.F5, Command.Refresh). You cannot callview.AddCommand (...)on an instance from outside.Terminal.Gui.Drawing.Attribute— The color/styleAttributeis areadonly record structinTerminal.Gui.Drawing; it collides withSystem.Attribute. Qualify or alias it whenSystemis also imported.- Typed views expose
.Value, not guessed names — Value-bearing views implementIValue<T>: use.ValueandValueChanged/ValueChanging(e.g.datePicker.Valueis aDateTime, not.Date). Don't guess property-specific names like.Date,.Time, or.Color.
These rules apply only when contributing code to the Terminal.Gui library itself. App developers using Terminal.Gui do NOT need to follow these conventions.
- Space before
()and[]— This codebase usesMethod ()notMethod(), andarray [i]notarray[i]. This is the #1 formatting mistake agents make. - No
var— Use explicit types except for built-in types (int,string,bool, etc.). - Use
new ()— Target-typed new:Button btn = new ()notButton btn = new Button (). - Collection expressions — Use
[...]notnew List<T> { ... }.
| Resource | Path |
|---|---|
| Compressed API docs | docfx/apispec/namespace-*.md |
| Deep-dive docs | docfx/docs/ |
| Common UI patterns | .claude/cookbook/common-patterns.md |
| App building guide | .claude/tasks/build-app.md |
| Working examples | Examples/UICatalog/, Examples/ScenarioRunner/, and tui-cs/Examples |
| Full agent instructions | AGENTS.md |