瀏覽代碼

Deleted demo.cs; changed to Example.cs from README

Charlie Kindel 2 年之前
父節點
當前提交
371147d691
共有 5 個文件被更改,包括 123 次插入814 次删除
  1. 76 0
      Example/Example.cs
  2. 0 11
      Example/Properties/launchSettings.json
  3. 5 3
      Example/README.md
  4. 0 758
      Example/demo.cs
  5. 42 42
      README.md

+ 76 - 0
Example/Example.cs

@@ -0,0 +1,76 @@
+// A simple Terminal.Gui example in C# - using C# 9.0 Top-level statements
+// This is the same code found in the Termiminal Gui README.md file.
+
+using Terminal.Gui;
+using NStack;
+
+Application.Init ();
+
+// Creates the top-level window to show
+var win = new Window ("Example App") {
+	X = 0,
+	Y = 1, // Leave one row for the toplevel menu
+
+	// By using Dim.Fill(), this Window will automatically resize without manual intervention
+	Width = Dim.Fill (),
+	Height = Dim.Fill ()
+};
+
+Application.Top.Add (win);
+
+// Creates a menubar, the item "New" has a help menu.
+var menu = new MenuBar (new MenuBarItem [] {
+			new MenuBarItem ("_File", new MenuItem [] {
+				new MenuItem ("_New", "Creates a new file", null),
+				new MenuItem ("_Close", "",null),
+				new MenuItem ("_Quit", "", () => { if (Quit ()) Application.Top.Running = false; })
+			}),
+			new MenuBarItem ("_Edit", new MenuItem [] {
+				new MenuItem ("_Copy", "", null),
+				new MenuItem ("C_ut", "", null),
+				new MenuItem ("_Paste", "", null)
+			})
+		});
+Application.Top.Add (menu);
+
+static bool Quit ()
+{
+	var n = MessageBox.Query (50, 7, "Quit Example", "Are you sure you want to quit this example?", "Yes", "No");
+	return n == 0;
+}
+
+var login = new Label ("Login: ") { X = 3, Y = 2 };
+var password = new Label ("Password: ") {
+	X = Pos.Left (login),
+	Y = Pos.Top (login) + 1
+};
+var loginText = new TextField ("") {
+	X = Pos.Right (password),
+	Y = Pos.Top (login),
+	Width = 40
+};
+var passText = new TextField ("") {
+	Secret = true,
+	X = Pos.Left (loginText),
+	Y = Pos.Top (password),
+	Width = Dim.Width (loginText)
+};
+
+// Add the views to the main window, 
+win.Add (
+	// Using Computed Layout:
+	login, password, loginText, passText,
+
+	// Using Absolute Layout:
+	new CheckBox (3, 6, "Remember me"),
+	new RadioGroup (3, 8, new ustring [] { "_Personal", "_Company" }, 0),
+	new Button (3, 14, "Ok"),
+	new Button (10, 14, "Cancel"),
+	new Label (3, 18, "Press F9 or ESC plus 9 to activate the menubar")
+);
+
+// Run blocks until the user quits the application
+Application.Run ();
+
+// Always bracket Application.Init with .Shutdown.
+Application.Shutdown ();

+ 0 - 11
Example/Properties/launchSettings.json

@@ -1,11 +0,0 @@
-{
-  "profiles": {
-    "Example": {
-      "commandName": "Project"
-    },
-    "Example:-usc": {
-      "commandName": "Project",
-      "commandLineArgs": "-usc"
-    }
-  }
-}

+ 5 - 3
Example/README.md

@@ -1,5 +1,7 @@
-# demo.cs
+# Terminal.Gui C# Example
 
-This is the original Terminal.Gui sample app. Over time we will be simplifying this sample to show just the basics of creating a Terminal.Gui app in C#. 
+This example shows how to use the Terminal.Gui library to create a simple GUI application in C#.
 
-See the Sample Code section [README.md](https://github.com/gui-cs/Terminal.Gui) for a list of all samples.
+This is the same code found in the Termina.Gui README.md file.
+
+See [README.md](https://github.com/gui-cs/Terminal.Gui) for a list of all Terminal.Gui samples.

+ 0 - 758
Example/demo.cs

@@ -1,758 +0,0 @@
-using NStack;
-using System;
-using System.Collections.Generic;
-using System.Diagnostics;
-using System.Globalization;
-using System.IO;
-using System.Linq;
-using System.Reflection;
-using Terminal.Gui;
-
-static class Demo {
-	class Box10x : View {
-		int w = 40;
-		int h = 50;
-
-		public bool WantCursorPosition { get; set; } = false;
-
-		public Box10x (int x, int y) : base (new Rect (x, y, 20, 10))
-		{
-		}
-
-		public Size GetContentSize ()
-		{
-			return new Size (w, h);
-		}
-
-		public void SetCursorPosition (Point pos)
-		{
-			throw new NotImplementedException ();
-		}
-
-		public override void Redraw (Rect bounds)
-		{
-			//Point pos = new Point (region.X, region.Y);
-			Driver.SetAttribute (ColorScheme.Focus);
-
-			for (int y = 0; y < h; y++) {
-				Move (0, y);
-				Driver.AddStr (y.ToString ());
-				for (int x = 0; x < w - y.ToString ().Length; x++) {
-					//Driver.AddRune ((Rune)('0' + (x + y) % 10));
-					if (y.ToString ().Length < w)
-						Driver.AddStr (" ");
-				}
-			}
-			//Move (pos.X, pos.Y);
-		}
-	}
-
-	class Filler : View {
-		int w = 40;
-		int h = 50;
-
-		public Filler (Rect rect) : base (rect)
-		{
-			w = rect.Width;
-			h = rect.Height;
-		}
-
-		public Size GetContentSize ()
-		{
-			return new Size (w, h);
-		}
-
-		public override void Redraw (Rect bounds)
-		{
-			Driver.SetAttribute (ColorScheme.Focus);
-			var f = Frame;
-			w = 0;
-			h = 0;
-
-			for (int y = 0; y < f.Width; y++) {
-				Move (0, y);
-				var nw = 0;
-				for (int x = 0; x < f.Height; x++) {
-					Rune r;
-					switch (x % 3) {
-					case 0:
-						var er = y.ToString ().ToCharArray (0, 1) [0];
-						nw += er.ToString ().Length;
-						Driver.AddRune (er);
-						if (y > 9) {
-							er = y.ToString ().ToCharArray (1, 1) [0];
-							nw += er.ToString ().Length;
-							Driver.AddRune (er);
-						}
-						r = '.';
-						break;
-					case 1:
-						r = 'o';
-						break;
-					default:
-						r = 'O';
-						break;
-					}
-					Driver.AddRune (r);
-					nw += Rune.RuneLen (r);
-				}
-				if (nw > w)
-					w = nw;
-				h = y + 1;
-			}
-		}
-	}
-
-	static void ShowTextAlignments ()
-	{
-		var container = new Window ("Show Text Alignments - Press Esc to return") {
-			X = 0,
-			Y = 0,
-			Width = Dim.Fill (),
-			Height = Dim.Fill ()
-		};
-		container.KeyUp += (e) => {
-			if (e.KeyEvent.Key == Key.Esc)
-				container.Running = false;
-		};
-
-		int i = 0;
-		string txt = "Hello world, how are you doing today?";
-		container.Add (
-				new Label ($"{i + 1}-{txt}") { TextAlignment = TextAlignment.Left, Y = 3, Width = Dim.Fill () },
-				new Label ($"{i + 2}-{txt}") { TextAlignment = TextAlignment.Right, Y = 5, Width = Dim.Fill () },
-				new Label ($"{i + 3}-{txt}") { TextAlignment = TextAlignment.Centered, Y = 7, Width = Dim.Fill () },
-				new Label ($"{i + 4}-{txt}") { TextAlignment = TextAlignment.Justified, Y = 9, Width = Dim.Fill () }
-			);
-
-		Application.Run (container);
-	}
-
-	static void ShowEntries (View container)
-	{
-		var scrollView = new ScrollView (new Rect (50, 10, 20, 8)) {
-			ContentSize = new Size (20, 50),
-			//ContentOffset = new Point (0, 0),
-			ShowVerticalScrollIndicator = true,
-			ShowHorizontalScrollIndicator = true
-		};
-#if false
-		scrollView.Add (new Box10x (0, 0));
-#else
-		var filler = new Filler (new Rect (0, 0, 40, 40));
-		scrollView.Add (filler);
-		scrollView.DrawContent += (r) => {
-			scrollView.ContentSize = filler.GetContentSize ();
-		};
-#endif
-
-		// This is just to debug the visuals of the scrollview when small
-		var scrollView2 = new ScrollView (new Rect (72, 10, 3, 3)) {
-			ContentSize = new Size (100, 100),
-			ShowVerticalScrollIndicator = true,
-			ShowHorizontalScrollIndicator = true
-		};
-		scrollView2.Add (new Box10x (0, 0));
-		var progress = new ProgressBar (new Rect (68, 1, 10, 1));
-		bool timer (MainLoop caller)
-		{
-			progress.Pulse ();
-			return true;
-		}
-
-		Application.MainLoop.AddTimeout (TimeSpan.FromMilliseconds (300), timer);
-
-
-		// A little convoluted, this is because I am using this to test the
-		// layout based on referencing elements of another view:
-
-		var login = new Label ("Login: ") { X = 3, Y = 6 };
-		var password = new Label ("Password: ") {
-			X = Pos.Left (login),
-			Y = Pos.Bottom (login) + 1
-		};
-		var loginText = new TextField ("") {
-			X = Pos.Right (password),
-			Y = Pos.Top (login),
-			Width = 40
-		};
-
-		var passText = new TextField ("") {
-			Secret = true,
-			X = Pos.Left (loginText),
-			Y = Pos.Top (password),
-			Width = Dim.Width (loginText)
-		};
-
-		var tf = new Button (3, 19, "Ok");
-		var frameView = new FrameView (new Rect (3, 10, 25, 6), "Options");
-		frameView.Add (new CheckBox (1, 0, "Remember me"));
-		frameView.Add (new RadioGroup (1, 2, new ustring [] { "_Personal", "_Company" }));
-		// Add some content
-		container.Add (
-			login,
-			loginText,
-			password,
-			passText,
-			frameView,
-			new ListView (new Rect (59, 6, 16, 4), new string [] {
-				"First row",
-				"<>",
-				"This is a very long row that should overflow what is shown",
-				"4th",
-				"There is an empty slot on the second row",
-				"Whoa",
-				"This is so cool"
-			}),
-			scrollView,
-			scrollView2,
-			tf,
-			new Button (10, 19, "Cancel"),
-			new TimeField (3, 20, DateTime.Now.TimeOfDay),
-			new TimeField (23, 20, DateTime.Now.TimeOfDay, true),
-			new DateField (3, 22, DateTime.Now),
-			new DateField (23, 22, DateTime.Now, true),
-			progress,
-			new Label (3, 24, "Press F9 (on Unix, ESC+9 is an alias) or Ctrl+T to activate the menubar"),
-			menuKeysStyle,
-			menuAutoMouseNav
-
-		);
-		container.SendSubviewToBack (tf);
-	}
-
-	public static Label ml2;
-
-	static void NewFile ()
-	{
-		var ok = new Button ("Ok", is_default: true);
-		ok.Clicked += () => { Application.RequestStop (); };
-		var cancel = new Button ("Cancel");
-		cancel.Clicked += () => { Application.RequestStop (); };
-		var d = new Dialog ("New File", 50, 20, ok, cancel);
-		ml2 = new Label (1, 1, "Mouse Debug Line");
-		d.Add (ml2);
-		Application.Run (d);
-	}
-
-	//
-	static void Editor ()
-	{
-		Application.Init ();
-		Application.HeightAsBuffer = heightAsBuffer;
-
-		var ntop = Application.Top;
-
-		var text = new TextView () { X = 0, Y = 0, Width = Dim.Fill (), Height = Dim.Fill () };
-
-		string fname = GetFileName ();
-
-		var win = new Window (fname ?? "Untitled") {
-			X = 0,
-			Y = 1,
-			Width = Dim.Fill (),
-			Height = Dim.Fill ()
-		};
-		ntop.Add (win);
-
-		if (fname != null)
-			text.Text = System.IO.File.ReadAllText (fname);
-		win.Add (text);
-
-		void Paste ()
-		{
-			if (text != null) {
-				text.Paste ();
-			}
-		}
-
-		void Cut ()
-		{
-			if (text != null) {
-				text.Cut ();
-			}
-		}
-
-		void Copy ()
-		{
-			if (text != null) {
-				text.Copy ();
-			}
-		}
-
-		var menu = new MenuBar (new MenuBarItem [] {
-			new MenuBarItem ("_File", new MenuItem [] {
-				new MenuItem ("_Close", "", () => { if (Quit ()) { running = MainApp; Application.RequestStop (); } }, null, null, Key.AltMask | Key.Q),
-			}),
-			new MenuBarItem ("_Edit", new MenuItem [] {
-				new MenuItem ("_Copy", "", Copy, null, null, Key.C | Key.CtrlMask),
-				new MenuItem ("C_ut", "", Cut, null, null, Key.X | Key.CtrlMask),
-				new MenuItem ("_Paste", "", Paste, null, null, Key.Y | Key.CtrlMask)
-			}),
-		});
-		ntop.Add (menu);
-
-		Application.Run (ntop);
-	}
-
-	private static string GetFileName ()
-	{
-		string fname = null;
-		foreach (var s in new [] { "/etc/passwd", "c:\\windows\\win.ini" })
-			if (System.IO.File.Exists (s)) {
-				fname = s;
-				break;
-			}
-
-		return fname;
-	}
-
-	static bool Quit ()
-	{
-		var n = MessageBox.Query (50, 7, "Quit Demo", "Are you sure you want to quit this demo?", "Yes", "No");
-		return n == 0;
-	}
-
-	static void Close ()
-	{
-		MessageBox.ErrorQuery (50, 7, "Error", "There is nothing to close", "Ok");
-	}
-
-	// Watch what happens when I try to introduce a newline after the first open brace
-	// it introduces a new brace instead, and does not indent.  Then watch me fight
-	// the editor as more oddities happen.
-
-	public static void Open ()
-	{
-		var d = new OpenDialog ("Open", "Open a file") { AllowsMultipleSelection = true };
-		Application.Run (d);
-
-		if (!d.Canceled)
-			MessageBox.Query (50, 7, "Selected File", d.FilePaths.Count > 0 ? string.Join (", ", d.FilePaths) : d.FilePath, "Ok");
-	}
-
-	public static void ShowHex ()
-	{
-		var ntop = Application.Top;
-		var menu = new MenuBar (new MenuBarItem [] {
-			new MenuBarItem ("_File", new MenuItem [] {
-				new MenuItem ("_Close", "", () => { running = MainApp; Application.RequestStop (); }, null, null, Key.AltMask | Key.Q),
-			}),
-		});
-		ntop.Add (menu);
-
-		string fname = GetFileName ();
-		var win = new Window (fname) {
-			X = 0,
-			Y = 1,
-			Width = Dim.Fill (),
-			Height = Dim.Fill ()
-		};
-		ntop.Add (win);
-
-		var source = System.IO.File.OpenRead (fname);
-		var hex = new HexView (source) {
-			X = 0,
-			Y = 0,
-			Width = Dim.Fill (),
-			Height = Dim.Fill ()
-		};
-		win.Add (hex);
-		Application.Run (ntop);
-	}
-
-	public class MenuItemDetails : MenuItem {
-		ustring title;
-		string help;
-		Action action;
-
-		public MenuItemDetails (ustring title, string help, Action action) : base (title, help, action)
-		{
-			this.title = title;
-			this.help = help;
-			this.action = action;
-		}
-
-		public static MenuItemDetails Instance (MenuItem mi)
-		{
-			return (MenuItemDetails)mi.GetMenuItem ();
-		}
-	}
-
-	public delegate MenuItem MenuItemDelegate (MenuItemDetails menuItem);
-
-	public static void ShowMenuItem (MenuItem mi)
-	{
-		BindingFlags flags = BindingFlags.Public | BindingFlags.Static;
-		MethodInfo minfo = typeof (MenuItemDetails).GetMethod ("Instance", flags);
-		MenuItemDelegate mid = (MenuItemDelegate)Delegate.CreateDelegate (typeof (MenuItemDelegate), minfo);
-		MessageBox.Query (70, 7, mi.Title.ToString (),
-			$"{mi.Title.ToString ()} selected. Is from submenu: {mi.GetMenuBarItem ()}", "Ok");
-	}
-
-	static void MenuKeysStyle_Toggled (bool e)
-	{
-		menu.UseKeysUpDownAsKeysLeftRight = menuKeysStyle.Checked;
-	}
-
-	static void MenuAutoMouseNav_Toggled (bool e)
-	{
-		menu.WantMousePositionReports = menuAutoMouseNav.Checked;
-	}
-
-	static void Copy ()
-	{
-		TextField textField = menu.LastFocused as TextField ?? Application.Top.MostFocused as TextField;
-		if (textField != null && textField.SelectedLength != 0) {
-			textField.Copy ();
-		}
-	}
-
-	static void Cut ()
-	{
-		TextField textField = menu.LastFocused as TextField ?? Application.Top.MostFocused as TextField;
-		if (textField != null && textField.SelectedLength != 0) {
-			textField.Cut ();
-		}
-	}
-
-	static void Paste ()
-	{
-		TextField textField = menu.LastFocused as TextField ?? Application.Top.MostFocused as TextField;
-		textField?.Paste ();
-	}
-
-	static void Help ()
-	{
-		MessageBox.Query (50, 7, "Help", "This is a small help\nBe kind.", "Ok");
-	}
-
-	static void Load ()
-	{
-		MessageBox.Query (50, 7, "Load", "This is a small load\nBe kind.", "Ok");
-	}
-
-	static void Save ()
-	{
-		MessageBox.Query (50, 7, "Save", "This is a small save\nBe kind.", "Ok");
-	}
-
-
-	#region Selection Demo
-
-	static void ListSelectionDemo (bool multiple)
-	{
-		var ok = new Button ("Ok", is_default: true);
-		ok.Clicked += () => { Application.RequestStop (); };
-		var cancel = new Button ("Cancel");
-		cancel.Clicked += () => { Application.RequestStop (); };
-		var d = new Dialog ("Selection Demo", 60, 20, ok, cancel);
-
-		var animals = new List<string> () { "Alpaca", "Llama", "Lion", "Shark", "Goat" };
-		var msg = new Label ("Use space bar or control-t to toggle selection") {
-			X = 1,
-			Y = 1,
-			Width = Dim.Fill () - 1,
-			Height = 1
-		};
-
-		var list = new ListView (animals) {
-			X = 1,
-			Y = 3,
-			Width = Dim.Fill () - 4,
-			Height = Dim.Fill () - 4,
-			AllowsMarking = true,
-			AllowsMultipleSelection = multiple
-		};
-		d.Add (msg, list);
-		Application.Run (d);
-
-		var result = "";
-		for (int i = 0; i < animals.Count; i++) {
-			if (list.Source.IsMarked (i)) {
-				result += animals [i] + " ";
-			}
-		}
-		MessageBox.Query (60, 10, "Selected Animals", result == "" ? "No animals selected" : result, "Ok");
-	}
-
-	static void ComboBoxDemo ()
-	{
-		//TODO: Duplicated code in ListsAndCombos.cs Consider moving to shared assembly
-		var items = new List<ustring> ();
-		foreach (var dir in new [] { "/etc", @$"{Environment.GetEnvironmentVariable ("SystemRoot")}\System32" }) {
-			if (Directory.Exists (dir)) {
-				items = Directory.GetFiles (dir).Union (Directory.GetDirectories (dir))
-					.Select (Path.GetFileName)
-					.Where (x => char.IsLetterOrDigit (x [0]))
-					.OrderBy (x => x).Select (x => ustring.Make (x)).ToList ();
-			}
-		}
-		var list = new ComboBox () { Width = Dim.Fill (), Height = Dim.Fill () };
-		list.SetSource (items);
-		list.OpenSelectedItem += (ListViewItemEventArgs text) => { Application.RequestStop (); };
-
-		var d = new Dialog () { Title = "Select source file", Width = Dim.Percent (50), Height = Dim.Percent (50) };
-		d.Add (list);
-		Application.Run (d);
-
-		MessageBox.Query (60, 10, "Selected file", list.Text.ToString () == "" ? "Nothing selected" : list.Text.ToString (), "Ok");
-	}
-	#endregion
-
-
-	#region KeyDown / KeyPress / KeyUp Demo
-	private static void OnKeyDownPressUpDemo ()
-	{
-		var close = new Button ("Close");
-		close.Clicked += () => { Application.RequestStop (); };
-		var container = new Dialog ("KeyDown & KeyPress & KeyUp demo", 80, 20, close) {
-			Width = Dim.Fill (),
-			Height = Dim.Fill (),
-		};
-
-		var list = new List<string> ();
-		var listView = new ListView (list) {
-			X = 0,
-			Y = 0,
-			Width = Dim.Fill () - 1,
-			Height = Dim.Fill () - 2,
-		};
-		listView.ColorScheme = Colors.TopLevel;
-		container.Add (listView);
-
-		void KeyDownPressUp (KeyEvent keyEvent, string updown)
-		{
-			const int ident = -5;
-			switch (updown) {
-			case "Down":
-			case "Up":
-			case "Press":
-				var msg = $"Key{updown,ident}: ";
-				if ((keyEvent.Key & Key.ShiftMask) != 0)
-					msg += "Shift ";
-				if ((keyEvent.Key & Key.CtrlMask) != 0)
-					msg += "Ctrl ";
-				if ((keyEvent.Key & Key.AltMask) != 0)
-					msg += "Alt ";
-				msg += $"{(((uint)keyEvent.KeyValue & (uint)Key.CharMask) > 26 ? $"{(char)keyEvent.KeyValue}" : $"{keyEvent.Key}")}";
-				//list.Add (msg);
-				list.Add (keyEvent.ToString ());
-
-				break;
-
-			default:
-				if ((keyEvent.Key & Key.ShiftMask) != 0) {
-					list.Add ($"Key{updown,ident}: Shift ");
-				} else if ((keyEvent.Key & Key.CtrlMask) != 0) {
-					list.Add ($"Key{updown,ident}: Ctrl ");
-				} else if ((keyEvent.Key & Key.AltMask) != 0) {
-					list.Add ($"Key{updown,ident}: Alt ");
-				} else {
-					list.Add ($"Key{updown,ident}: {(((uint)keyEvent.KeyValue & (uint)Key.CharMask) > 26 ? $"{(char)keyEvent.KeyValue}" : $"{keyEvent.Key}")}");
-				}
-
-				break;
-			}
-			listView.MoveDown ();
-		}
-
-		container.KeyDown += (e) => KeyDownPressUp (e.KeyEvent, "Down");
-		container.KeyPress += (e) => KeyDownPressUp (e.KeyEvent, "Press");
-		container.KeyUp += (e) => KeyDownPressUp (e.KeyEvent, "Up");
-		Application.Run (container);
-	}
-	#endregion
-
-	public static Action running = MainApp;
-	static void Main (string [] args)
-	{
-		if (args.Length > 0 && args.Contains ("-usc")) {
-			Application.UseSystemConsole = true;
-		}
-
-		Console.OutputEncoding = System.Text.Encoding.Default;
-
-		while (running != null) {
-			running.Invoke ();
-		}
-		Application.Shutdown ();
-	}
-
-	public static Label ml;
-	public static MenuBar menu;
-	public static CheckBox menuKeysStyle;
-	public static CheckBox menuAutoMouseNav;
-	private static bool heightAsBuffer = false;
-	static void MainApp ()
-	{
-		if (Debugger.IsAttached)
-			CultureInfo.DefaultThreadCurrentUICulture = CultureInfo.GetCultureInfo ("en-US");
-
-		Application.Init ();
-		Application.HeightAsBuffer = heightAsBuffer;
-		//ConsoleDriver.Diagnostics = ConsoleDriver.DiagnosticFlags.FramePadding | ConsoleDriver.DiagnosticFlags.FrameRuler;
-
-		var top = Application.Top;
-
-		//Open ();
-#if true
-		int margin = 3;
-		var win = new Window ("Hello") {
-			X = 1,
-			Y = 1,
-
-			Width = Dim.Fill () - margin,
-			Height = Dim.Fill () - margin
-		};
-#else
-		var tframe = top.Frame;
-
-		var win = new Window (new Rect (0, 1, tframe.Width, tframe.Height - 1), "Hello");
-#endif
-		MenuItemDetails [] menuItems = {
-			new MenuItemDetails ("F_ind", "", null),
-			new MenuItemDetails ("_Replace", "", null),
-			new MenuItemDetails ("_Item1", "", null),
-			new MenuItemDetails ("_Also From Sub Menu", "", null)
-		};
-
-		menuItems [0].Action = () => ShowMenuItem (menuItems [0]);
-		menuItems [1].Action = () => ShowMenuItem (menuItems [1]);
-		menuItems [2].Action = () => ShowMenuItem (menuItems [2]);
-		menuItems [3].Action = () => ShowMenuItem (menuItems [3]);
-
-		MenuItem miUseSubMenusSingleFrame = null;
-		var useSubMenusSingleFrame = false;
-		MenuItem miUseKeysUpDownAsKeysLeftRight = null;
-		var useKeysUpDownAsKeysLeftRight = false;
-
-		MenuItem miHeightAsBuffer = null;
-
-		menu = new MenuBar (new MenuBarItem [] {
-			new MenuBarItem ("_File", new MenuItem [] {
-				new MenuItem ("Text _Editor Demo", "", () => { running = Editor; Application.RequestStop (); }, null, null, Key.AltMask | Key.CtrlMask | Key.D),
-				new MenuItem ("_New", "Creates new file", NewFile, null, null, Key.AltMask | Key.CtrlMask| Key.N),
-				new MenuItem ("_Open", "", Open, null, null, Key.AltMask | Key.CtrlMask| Key.O),
-				new MenuItem ("_Hex", "", () => { running = ShowHex; Application.RequestStop (); }, null, null, Key.AltMask | Key.CtrlMask | Key.H),
-				new MenuItem ("_Close", "", Close, null, null, Key.AltMask | Key.Q),
-				new MenuItem ("_Disabled", "", () => { }, () => false),
-				new MenuBarItem ("_SubMenu Disabled", new MenuItem [] {
-					new MenuItem ("_Disabled", "", () => { }, () => false)
-				}),
-				null,
-				new MenuItem ("_Quit", "", () => { if (Quit ()) { running = null; top.Running = false; } }, null, null, Key.CtrlMask | Key.Q)
-			}),
-			new MenuBarItem ("_Edit", new MenuItem [] {
-				new MenuItem ("_Copy", "", Copy, null, null, Key.AltMask | Key.CtrlMask | Key.C),
-				new MenuItem ("C_ut", "", Cut, null, null, Key.AltMask | Key.CtrlMask| Key.X),
-				new MenuItem ("_Paste", "", Paste, null, null, Key.AltMask | Key.CtrlMask| Key.V),
-				new MenuBarItem ("_Find and Replace",
-					new MenuItem [] { menuItems [0], menuItems [1] }),
-				menuItems[3],
-				miUseKeysUpDownAsKeysLeftRight = new MenuItem ("Use_KeysUpDownAsKeysLeftRight", "",
-				() => {
-				menu.UseKeysUpDownAsKeysLeftRight = miUseKeysUpDownAsKeysLeftRight.Checked = useKeysUpDownAsKeysLeftRight = !useKeysUpDownAsKeysLeftRight;
-					miUseSubMenusSingleFrame.Checked = useSubMenusSingleFrame = menu.UseSubMenusSingleFrame;
-					}) {
-					CheckType = MenuItemCheckStyle.Checked, Checked = useKeysUpDownAsKeysLeftRight
-				},
-				miUseSubMenusSingleFrame = new MenuItem ("Use_SubMenusSingleFrame", "",
-				() => {
-				menu.UseSubMenusSingleFrame = miUseSubMenusSingleFrame.Checked = useSubMenusSingleFrame = !useSubMenusSingleFrame;
-					miUseKeysUpDownAsKeysLeftRight.Checked = useKeysUpDownAsKeysLeftRight = menu.UseKeysUpDownAsKeysLeftRight;
-					}) {
-					CheckType = MenuItemCheckStyle.Checked, Checked = useSubMenusSingleFrame
-				},
-				miHeightAsBuffer = new MenuItem ("_Height As Buffer", "", () => {
-					miHeightAsBuffer.Checked = heightAsBuffer = !heightAsBuffer;
-					Application.HeightAsBuffer = heightAsBuffer;
-				}) { CheckType = MenuItemCheckStyle.Checked, Checked = heightAsBuffer }
-			}),
-			new MenuBarItem ("_List Demos", new MenuItem [] {
-				new MenuItem ("Select _Multiple Items", "", () => ListSelectionDemo (true), null, null, Key.AltMask + 0.ToString () [0]),
-				new MenuItem ("Select _Single Item", "", () => ListSelectionDemo (false), null, null, Key.AltMask + 1.ToString () [0]),
-				new MenuItem ("Search Single Item", "", ComboBoxDemo, null, null, Key.AltMask + 2.ToString () [0])
-			}),
-			new MenuBarItem ("A_ssorted", new MenuItem [] {
-				new MenuItem ("_Show text alignments", "", () => ShowTextAlignments (), null, null, Key.AltMask | Key.CtrlMask | Key.G),
-				new MenuItem ("_OnKeyDown/Press/Up", "", () => OnKeyDownPressUpDemo (), null, null, Key.AltMask | Key.CtrlMask | Key.K)
-			}),
-			new MenuBarItem ("_Test Menu and SubMenus", new MenuBarItem [] {
-				new MenuBarItem ("SubMenu1Item_1",  new MenuBarItem [] {
-					new MenuBarItem ("SubMenu2Item_1", new MenuBarItem [] {
-						new MenuBarItem ("SubMenu3Item_1",
-							new MenuItem [] { menuItems [2] })
-					})
-				})
-			}),
-			new MenuBarItem ("_About...", "Demonstrates top-level menu item", () =>  MessageBox.ErrorQuery (50, 7, "About Demo", "This is a demo app for gui.cs", "Ok")),
-		});
-
-		menuKeysStyle = new CheckBox (3, 25, "UseKeysUpDownAsKeysLeftRight", true);
-		menuKeysStyle.Toggled += MenuKeysStyle_Toggled;
-		menuAutoMouseNav = new CheckBox (40, 25, "UseMenuAutoNavigation", true);
-		menuAutoMouseNav.Toggled += MenuAutoMouseNav_Toggled;
-
-		ShowEntries (win);
-
-		int count = 0;
-		ml = new Label (new Rect (3, 17, 47, 1), "Mouse: ");
-		Application.RootMouseEvent += delegate (MouseEvent me) {
-			ml.Text = $"Mouse: ({me.X},{me.Y}) - {me.Flags} {count++}";
-		};
-
-		var test = new Label (3, 18, "Se iniciará el análisis");
-		win.Add (test);
-		win.Add (ml);
-
-		var drag = new Label ("Drag: ") { X = 70, Y = 22 };
-		var dragText = new TextField ("") {
-			X = Pos.Right (drag),
-			Y = Pos.Top (drag),
-			Width = 40
-		};
-
-		var statusBar = new StatusBar (new StatusItem [] {
-			new StatusItem(Key.F1, "~F1~ Help", () => Help()),
-			new StatusItem(Key.F2, "~F2~ Load", Load),
-			new StatusItem(Key.F3, "~F3~ Save", Save),
-			new StatusItem(Key.CtrlMask | Key.Q, "~^Q~ Quit", () => { if (Quit ()) { running = null; top.Running = false; } }),
-			new StatusItem(Key.Null, Application.Driver.GetType().Name, null)
-		});
-
-		win.Add (drag, dragText);
-
-		var bottom = new Label ("This should go on the bottom of the same top-level!");
-		win.Add (bottom);
-		var bottom2 = new Label ("This should go on the bottom of another top-level!");
-		top.Add (bottom2);
-
-		top.LayoutComplete += (e) => {
-			bottom.X = win.X;
-			bottom.Y = Pos.Bottom (win) - Pos.Top (win) - margin;
-			bottom2.X = Pos.Left (win);
-			bottom2.Y = Pos.Bottom (win);
-		};
-
-		win.KeyPress += Win_KeyPress;
-
-		top.Add (win);
-		//top.Add (menu);
-		top.Add (menu, statusBar);
-		Application.Run (top);
-	}
-
-	private static void Win_KeyPress (View.KeyEventEventArgs e)
-	{
-		switch (ShortcutHelper.GetModifiersKey (e.KeyEvent)) {
-		case Key.CtrlMask | Key.T:
-			if (menu.IsMenuOpen)
-				menu.CloseMenu ();
-			else
-				menu.OpenMenu ();
-			e.Handled = true;
-			break;
-		}
-	}
-}

+ 42 - 42
README.md

@@ -35,9 +35,9 @@ descriptors. Most classes are safe for threading.
 
 ## Showcase & Examples
 
+* **[C# Example](https://github.com/gui-cs/Terminal.Gui/tree/master/Example)** - Run `dotnet run` in the `Example` directory to run the C# Example.
 * **[UI Catalog](https://github.com/gui-cs/Terminal.Gui/tree/master/UICatalog)** - The UI Catalog project provides an easy to use and extend sample illustrating the capabilities of **Terminal.Gui**. Run `dotnet run --project UICatalog` to run the UI Catalog.
 * **[Reactive Example](https://github.com/gui-cs/Terminal.Gui/tree/master/ReactiveExample)** - A sample app that shows how to use `System.Reactive` and `ReactiveUI` with `Terminal.Gui`. The app uses the MVVM architecture that may seem familiar to folks coming from WPF, Xamarin Forms, UWP, Avalonia, or Windows Forms. In this app, we implement the data bindings using ReactiveUI `WhenAnyValue` syntax and [Pharmacist](https://github.com/reactiveui/pharmacist) — a tool that converts all events in a NuGet package into observable wrappers.
-* **[Example (aka `demo.cs`)](https://github.com/gui-cs/Terminal.Gui/tree/master/Example)** - Run `dotnet run` in the `Example` directory to run the simple demo.
 * **[Standalone Example](https://github.com/gui-cs/Terminal.Gui/tree/master/StandaloneExample)** - A trivial .NET core sample application can be found in the `StandaloneExample` directory. Run `dotnet run` in directory to test.
 * **[F# Example](https://github.com/gui-cs/Terminal.Gui/tree/master/FSharpExample)** - An example showing how to build a Terminal.Gui app using F#.
 * **[PowerShell's `Out-ConsoleGridView`](https://github.com/PowerShell/GraphicalTools/blob/master/docs/Microsoft.PowerShell.ConsoleGuiTools/Out-ConsoleGridView.md)** - `OCGV` sends the output from a command to  an interactive table. 
@@ -46,34 +46,34 @@ descriptors. Most classes are safe for threading.
 
 See the [`Terminal.Gui/` README](https://github.com/gui-cs/Terminal.Gui/tree/master/Terminal.Gui) for an overview of how the library is structured. The [Conceptual Documentation](https://gui-cs.github.io/Terminal.Gui/articles/index.html) provides insight into core concepts.
 
-## Sample Usage
-(This code uses C# 9.0 [Top-level statements](https://docs.microsoft.com/en-us/dotnet/csharp/whats-new/csharp-9#top-level-statements).) 
+## Sample Usage in C#
+
 ```csharp
+// A simple Terminal.Gui example in C# - using C# 9.0 Top-level statements
+
 using Terminal.Gui;
 using NStack;
 
-Application.Init();
-var top = Application.Top;
+Application.Init ();
 
 // Creates the top-level window to show
-var win = new Window("MyApp")
-{
+var win = new Window ("Example App") {
 	X = 0,
 	Y = 1, // Leave one row for the toplevel menu
 
-	// By using Dim.Fill(), it will automatically resize without manual intervention
-	Width = Dim.Fill(),
-	Height = Dim.Fill()
+	// By using Dim.Fill(), this Window will automatically resize without manual intervention
+	Width = Dim.Fill (),
+	Height = Dim.Fill ()
 };
 
-top.Add(win);
+Application.Top.Add (win);
 
 // Creates a menubar, the item "New" has a help menu.
-var menu = new MenuBar(new MenuBarItem[] {
+var menu = new MenuBar (new MenuBarItem [] {
 			new MenuBarItem ("_File", new MenuItem [] {
-				new MenuItem ("_New", "Creates new file", null),
+				new MenuItem ("_New", "Creates a new file", null),
 				new MenuItem ("_Close", "",null),
-				new MenuItem ("_Quit", "", () => { if (Quit ()) top.Running = false; })
+				new MenuItem ("_Quit", "", () => { if (Quit ()) Application.Top.Running = false; })
 			}),
 			new MenuBarItem ("_Edit", new MenuItem [] {
 				new MenuItem ("_Copy", "", null),
@@ -81,49 +81,49 @@ var menu = new MenuBar(new MenuBarItem[] {
 				new MenuItem ("_Paste", "", null)
 			})
 		});
-top.Add(menu);
+Application.Top.Add (menu);
 
-static bool Quit()
+static bool Quit ()
 {
-	var n = MessageBox.Query(50, 7, "Quit Demo", "Are you sure you want to quit this demo?", "Yes", "No");
+	var n = MessageBox.Query (50, 7, "Quit Example", "Are you sure you want to quit this example?", "Yes", "No");
 	return n == 0;
 }
 
-var login = new Label("Login: ") { X = 3, Y = 2 };
-var password = new Label("Password: ")
-{
-	X = Pos.Left(login),
-	Y = Pos.Top(login) + 1
+var login = new Label ("Login: ") { X = 3, Y = 2 };
+var password = new Label ("Password: ") {
+	X = Pos.Left (login),
+	Y = Pos.Top (login) + 1
 };
-var loginText = new TextField("")
-{
-	X = Pos.Right(password),
-	Y = Pos.Top(login),
+var loginText = new TextField ("") {
+	X = Pos.Right (password),
+	Y = Pos.Top (login),
 	Width = 40
 };
-var passText = new TextField("")
-{
+var passText = new TextField ("") {
 	Secret = true,
-	X = Pos.Left(loginText),
-	Y = Pos.Top(password),
-	Width = Dim.Width(loginText)
+	X = Pos.Left (loginText),
+	Y = Pos.Top (password),
+	Width = Dim.Width (loginText)
 };
 
-// Add some controls, 
-win.Add(
-	// The ones with my favorite layout system, Computed
+// Add the views to the main window, 
+win.Add (
+	// Using Computed Layout:
 	login, password, loginText, passText,
 
-	// The ones laid out like an australopithecus, with Absolute positions:
-	new CheckBox(3, 6, "Remember me"),
-	new RadioGroup(3, 8, new ustring[] { "_Personal", "_Company" }, 0),
-	new Button(3, 14, "Ok"),
-	new Button(10, 14, "Cancel"),
-	new Label(3, 18, "Press F9 or ESC plus 9 to activate the menubar")
+	// Using Absolute Layout:
+	new CheckBox (3, 6, "Remember me"),
+	new RadioGroup (3, 8, new ustring [] { "_Personal", "_Company" }, 0),
+	new Button (3, 14, "Ok"),
+	new Button (10, 14, "Cancel"),
+	new Label (3, 18, "Press F9 or ESC plus 9 to activate the menubar")
 );
 
-Application.Run();
-Application.Shutdown();
+// Run blocks until the user quits the application
+Application.Run ();
+
+// Always bracket Application.Init with .Shutdown.
+Application.Shutdown ();
 ```
 
 The example above shows adding views using both styles of layout supported by **Terminal.Gui**: **Absolute layout** and **[Computed layout](https://gui-cs.github.io/Terminal.Gui/articles/overview.html#layout)**.