Jelajahi Sumber

Merge branch 'develop' into listview_keyboard_search

Charlie Kindel 2 tahun lalu
induk
melakukan
c7862b7242

+ 1 - 1
.github/workflows/api-docs.yml

@@ -13,7 +13,7 @@ jobs:
       uses: actions/checkout@v2
 
     - name: Setup .NET Core
-      uses: actions/[email protected].2
+      uses: actions/[email protected].3
       with:
         dotnet-version: 6.0.100
     

+ 1 - 1
.github/workflows/dotnet-core.yml

@@ -15,7 +15,7 @@ jobs:
     - uses: actions/checkout@v3
 
     - name: Setup .NET Core
-      uses: actions/[email protected].2
+      uses: actions/[email protected].3
       with:
         dotnet-version: 6.0.100
 

+ 3 - 3
.github/workflows/publish.yml

@@ -16,12 +16,12 @@ jobs:
         fetch-depth: 0 #fetch-depth is needed for GitVersion
 
     - name: Install and calculate the new version with GitVersion 
-      uses: gittools/actions/gitversion/[email protected]4
+      uses: gittools/actions/gitversion/[email protected]5
       with:
         versionSpec: 5.x
 
     - name: Determine Version
-      uses: gittools/actions/gitversion/[email protected]4
+      uses: gittools/actions/gitversion/[email protected]5
       id: gitversion # step id used as reference for output values
 
     - name: Display GitVersion outputs
@@ -30,7 +30,7 @@ jobs:
         echo "CommitsSinceVersionSource: ${{ steps.gitversion.outputs.CommitsSinceVersionSource }}"
 
     - name: Setup dotnet
-      uses: actions/[email protected].2
+      uses: actions/[email protected].3
       with:
         dotnet-version: 6.0.100
 

+ 41 - 60
Example/Example.cs

@@ -1,76 +1,57 @@
-// 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.
+// This is a simple example application.  For the full range of functionality
+// see the UICatalog project
 
-using Terminal.Gui;
-using NStack;
-
-Application.Init ();
+// A simple Terminal.Gui example in C# - using C# 9.0 Top-level statements
 
-// Creates the top-level window to show
-var win = new Window ("Example App") {
-	X = 0,
-	Y = 1, // Leave one row for the toplevel menu
+using Terminal.Gui;
 
-	// By using Dim.Fill(), this Window will automatically resize without manual intervention
-	Width = Dim.Fill (),
-	Height = Dim.Fill ()
-};
+// Initialize the console
+Application.Init();
 
-Application.Top.Add (win);
+// Creates the top-level window with border and title
+var win = new Window("Example App (Ctrl+Q to quit)");
 
-// 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);
+// Create input components and labels
 
-static bool Quit ()
+var usernameLabel = new Label("Username:");
+var usernameText = new TextField("")
 {
-	var n = MessageBox.Query (50, 7, "Quit Example", "Are you sure you want to quit this example?", "Yes", "No");
-	return n == 0;
-}
+    // Position text field adjacent to label
+    X = Pos.Right(usernameLabel) + 1,
 
-var login = new Label ("Login: ") { X = 3, Y = 2 };
-var password = new Label ("Password: ") {
-	X = Pos.Left (login),
-	Y = Pos.Top (login) + 1
+    // Fill remaining horizontal space with a margin of 1
+    Width = Dim.Fill(1),
 };
-var loginText = new TextField ("") {
-	X = Pos.Right (password),
-	Y = Pos.Top (login),
-	Width = 40
+
+var passwordLabel = new Label(0,2,"Password:");
+var passwordText = new TextField("")
+{
+    Secret = true,
+    // align with the text box above
+    X = Pos.Left(usernameText),
+    Y = 2,
+    Width = Dim.Fill(1),
 };
-var passText = new TextField ("") {
-	Secret = true,
-	X = Pos.Left (loginText),
-	Y = Pos.Top (password),
-	Width = Dim.Width (loginText)
+
+// Create login button
+var btnLogin = new Button("Login")
+{
+    Y = 4,
+    // center the login button horizontally
+    X = Pos.Center(),
+    IsDefault = true,
 };
 
-// Add the views to the main window, 
-win.Add (
-	// Using Computed Layout:
-	login, password, loginText, passText,
+// When login button is clicked display a message popup
+btnLogin.Clicked += () => MessageBox.Query("Logging In", "Login Successful", "Ok");
 
-	// 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")
+// Add all the views to the window
+win.Add(
+    usernameLabel, usernameText, passwordLabel, passwordText,btnLogin
 );
 
-// Run blocks until the user quits the application
-Application.Run ();
+// Show the application
+Application.Run(win);
 
-// Always bracket Application.Init with .Shutdown.
-Application.Shutdown ();
+// After the application exits, release and reset console for clean shutdown
+Application.Shutdown();

+ 2 - 0
Example/README.md

@@ -4,6 +4,8 @@ This example shows how to use the Terminal.Gui library to create a simple GUI ap
 
 This is the same code found in the Terminal.Gui README.md file.
 
+To explore the full range of functionality in Terminal.Gui, see the [UICatalog](../UICatalog) project
+
 See [README.md](https://github.com/gui-cs/Terminal.Gui) for a list of all Terminal.Gui samples.
 
 Note, the old `demo.cs` example has been deleted because it was not a very good example. It can still be found in the [git history](https://github.com/gui-cs/Terminal.Gui/tree/v1.8.2).

+ 45 - 74
README.md

@@ -61,99 +61,70 @@ See the [`Terminal.Gui/` README](https://github.com/gui-cs/Terminal.Gui/tree/mas
 
 ## Sample Usage in C#
 
+The following example shows a basic Terminal.Gui application written in C#:
+
 ```csharp
 // A simple Terminal.Gui example in C# - using C# 9.0 Top-level statements
 
 using Terminal.Gui;
-using NStack;
 
-Application.Init ();
+// Initialize the console
+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
+// Creates the top-level window with border and title
+var win = new Window("Example App (Ctrl+Q to quit)");
 
-	// By using Dim.Fill(), this Window will automatically resize without manual intervention
-	Width = Dim.Fill (),
-	Height = Dim.Fill ()
-};
+// Create input components and labels
 
-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 usernameLabel = new Label("Username:");
+var usernameText = new TextField("")
 {
-	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
+    // Position text field adjacent to label
+    X = Pos.Right(usernameLabel) + 1,
+
+    // Fill remaining horizontal space with a margin of 1
+    Width = Dim.Fill(1),
 };
-var loginText = new TextField ("") {
-	X = Pos.Right (password),
-	Y = Pos.Top (login),
-	Width = 40
+
+var passwordLabel = new Label(0,2,"Password:");
+var passwordText = new TextField("")
+{
+    Secret = true,
+    // align with the text box above
+    X = Pos.Left(usernameText),
+    Y = 2,
+    Width = Dim.Fill(1),
 };
-var passText = new TextField ("") {
-	Secret = true,
-	X = Pos.Left (loginText),
-	Y = Pos.Top (password),
-	Width = Dim.Width (loginText)
+
+// Create login button
+var btnLogin = new Button("Login")
+{
+    Y = 4,
+    // center the login button horizontally
+    X = Pos.Center(),
+    IsDefault = true,
 };
 
-// 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")
+// When login button is clicked display a message popup
+btnLogin.Clicked += () => MessageBox.Query("Logging In", "Login Successful", "Ok");
+
+// Add all the views to the window
+win.Add(
+    usernameLabel, usernameText, passwordLabel, passwordText,btnLogin
 );
 
-// Run blocks until the user quits the application
-Application.Run ();
+// Show the application
+Application.Run(win);
 
-// Always bracket Application.Init with .Shutdown.
-Application.Shutdown ();
+// After the application exits, release and reset console for clean 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)**.
-
-Alternatively, you can encapsulate the app behavior in a new `Window`-derived class, say `App.cs` containing the code above, and simplify your `Main` method to:
+When run the application looks as follows:
 
-```csharp
-using Terminal.Gui;
+![Simple Usage app](./docfx/images/Example.png)
 
-class Demo {
-	static void Main ()
-	{
-		Application.Run<App> ();
-		Application.Shutdown ();
-	}
-}
-```
+_Sample application running_
 
 ## Installing
 
@@ -184,4 +155,4 @@ Debates on architecture and design can be found in Issues tagged with [design](h
 
 ## History
 
-See [gui-cs](https://github.com/gui-cs/) for how this project came to be.
+See [gui-cs](https://github.com/gui-cs/) for how this project came to be.

+ 5 - 4
Terminal.Gui/Views/TreeView.cs

@@ -232,10 +232,11 @@ namespace Terminal.Gui {
 				return MultiSelect ? desiredCursorVisibility : CursorVisibility.Invisible;
 			}
 			set {
-				desiredCursorVisibility = value;
-
-				if (desiredCursorVisibility != value && HasFocus) {
-					Application.Driver.SetCursorVisibility (DesiredCursorVisibility);
+				if (desiredCursorVisibility != value) {
+					desiredCursorVisibility = value;
+					if (HasFocus) {
+						Application.Driver.SetCursorVisibility (DesiredCursorVisibility);
+					}
 				}
 			}
 		}

+ 48 - 24
UnitTests/TreeViewTests.cs

@@ -839,26 +839,26 @@ namespace Terminal.Gui.Views {
 			Assert.Equal (0, tv.GetObjectRow (n2));
 		}
 		[Fact, AutoInitShutdown]
-		public void TestTreeViewColor()
+		public void TestTreeViewColor ()
 		{
-			var tv = new TreeView{Width = 20,Height = 10};
+			var tv = new TreeView { Width = 20, Height = 10 };
 
-			var n1 = new TreeNode("normal");
-			var n1_1 = new TreeNode("pink");
-			var n1_2 = new TreeNode("normal");
-			n1.Children.Add(n1_1);
-			n1.Children.Add(n1_2);
+			var n1 = new TreeNode ("normal");
+			var n1_1 = new TreeNode ("pink");
+			var n1_2 = new TreeNode ("normal");
+			n1.Children.Add (n1_1);
+			n1.Children.Add (n1_2);
 
-			var n2 = new TreeNode("pink");
-			tv.AddObject(n1);
-			tv.AddObject(n2);
-			tv.Expand(n1);
+			var n2 = new TreeNode ("pink");
+			tv.AddObject (n1);
+			tv.AddObject (n2);
+			tv.Expand (n1);
 
-			var pink = new Attribute(Color.Magenta,Color.Black);
-			var hotpink = new Attribute(Color.BrightMagenta,Color.Black);
+			var pink = new Attribute (Color.Magenta, Color.Black);
+			var hotpink = new Attribute (Color.BrightMagenta, Color.Black);
 
-			tv.ColorScheme = new ColorScheme();
-			tv.Redraw(tv.Bounds);
+			tv.ColorScheme = new ColorScheme ();
+			tv.Redraw (tv.Bounds);
 
 			// Normal drawing of the tree view
 			TestHelpers.AssertDriverContentsAre(
@@ -866,7 +866,7 @@ namespace Terminal.Gui.Views {
 │ ├─pink
 │ └─normal
 └─pink
-",output);
+", output);
 			// Should all be the same color
 			TestHelpers.AssertDriverColorsAre(
 @"00000000
@@ -874,30 +874,29 @@ namespace Terminal.Gui.Views {
 0000000000
 000000
 ",
-				new []{tv.ColorScheme.Normal,pink});
+				new [] { tv.ColorScheme.Normal, pink });
 
 			// create a new color scheme
-			var pinkScheme = new ColorScheme
-			{
+			var pinkScheme = new ColorScheme {
 				Normal = pink,
 				Focus = hotpink
 			};
 
 			// and a delegate that uses the pink color scheme 
 			// for nodes "pink"
-			tv.ColorGetter = (n)=> n.Text.Equals("pink") ? pinkScheme : null;
+			tv.ColorGetter = (n) => n.Text.Equals ("pink") ? pinkScheme : null;
 
 			// redraw now that the custom color
 			// delegate is registered
-			tv.Redraw(tv.Bounds);
-	
+			tv.Redraw (tv.Bounds);
+
 			// Same text
 			TestHelpers.AssertDriverContentsAre(
 @"├-normal
 │ ├─pink
 │ └─normal
 └─pink
-",output);
+", output);
 			// but now the item (only not lines) appear
 			// in pink when they are the word "pink"
 			TestHelpers.AssertDriverColorsAre(
@@ -906,7 +905,32 @@ namespace Terminal.Gui.Views {
 0000000000
 001111
 ",
-				new []{tv.ColorScheme.Normal,pink});
+				new [] { tv.ColorScheme.Normal, pink });
+		}
+
+		[Fact, AutoInitShutdown]
+		public void DesiredCursorVisibility_MultiSelect ()
+		{
+			var tv = new TreeView { Width = 20, Height = 10 };
+
+			var n1 = new TreeNode ("normal");
+			var n2 = new TreeNode ("pink");
+			tv.AddObject (n1);
+			tv.AddObject (n2);
+
+			Application.Top.Add (tv);
+			Application.Begin (Application.Top);
+
+			Assert.True (tv.MultiSelect);
+			Assert.True (tv.HasFocus);
+			Assert.Equal (CursorVisibility.Invisible, tv.DesiredCursorVisibility);
+
+			tv.SelectAll ();
+			tv.DesiredCursorVisibility = CursorVisibility.Default;
+			Application.Refresh ();
+			Application.Driver.GetCursorVisibility (out CursorVisibility visibility);
+			Assert.Equal (CursorVisibility.Default, tv.DesiredCursorVisibility);
+			Assert.Equal (CursorVisibility.Default, visibility);
 		}
 
 		/// <summary>

+ 1 - 1
UnitTests/UnitTests.csproj

@@ -26,7 +26,7 @@
       <PrivateAssets>all</PrivateAssets>
       <IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
     </PackageReference>
-    <PackageReference Include="coverlet.collector" Version="3.1.2">
+    <PackageReference Include="coverlet.collector" Version="3.2.0">
       <PrivateAssets>all</PrivateAssets>
       <IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
     </PackageReference>

TEMPAT SAMPAH
docfx/images/Example.png