浏览代码

Merge branch 'master' into crlf_label

Charlie Kindel 5 年之前
父节点
当前提交
37ef431f14
共有 3 个文件被更改,包括 29 次插入13 次删除
  1. 20 8
      Terminal.Gui/ConsoleDrivers/WindowsDriver.cs
  2. 1 1
      Terminal.Gui/Views/ListView.cs
  3. 8 4
      UICatalog/Scenarios/AllViewsTester.cs

+ 20 - 8
Terminal.Gui/ConsoleDrivers/WindowsDriver.cs

@@ -364,7 +364,7 @@ namespace Terminal.Gui {
 		[DllImport ("kernel32.dll", EntryPoint = "ReadConsoleInputW", CharSet = CharSet.Unicode)]
 		public static extern bool ReadConsoleInput (
 			IntPtr hConsoleInput,
-			[Out] InputRecord [] lpBuffer,
+			IntPtr lpBuffer,
 			uint nLength,
 			out uint lpNumberOfEventsRead);
 
@@ -420,6 +420,24 @@ namespace Terminal.Gui {
 				return v;
 			}
 		}
+		
+		public InputRecord [] ReadConsoleInput ()
+		{
+			const int bufferSize = 1;
+			var pRecord = Marshal.AllocHGlobal (Marshal.SizeOf<InputRecord> () * bufferSize);
+			try {
+				ReadConsoleInput (InputHandle, pRecord, bufferSize,
+					out var numberEventsRead);
+
+				return numberEventsRead == 0
+					? null
+					: new [] {Marshal.PtrToStructure<InputRecord> (pRecord)};
+			} catch (Exception) {
+				return null;
+			} finally {
+				Marshal.FreeHGlobal (pRecord);
+			}
+		}
 
 #if false // See: https://github.com/migueldeicaza/gui.cs/issues/357
 		[StructLayout (LayoutKind.Sequential)]
@@ -577,13 +595,7 @@ namespace Terminal.Gui {
 				waitForProbe.Wait ();
 				waitForProbe.Reset ();
 
-				uint numberEventsRead = 0;
-
-				WindowsConsole.ReadConsoleInput (winConsole.InputHandle, records, 1, out numberEventsRead);
-				if (numberEventsRead == 0)
-					result = null;
-				else
-					result = records;
+				result = winConsole.ReadConsoleInput ();
 
 				eventReady.Set ();
 			}

+ 1 - 1
Terminal.Gui/Views/ListView.cs

@@ -568,7 +568,7 @@ namespace Terminal.Gui {
 			for (int i = 0; i < byteLen;) {
 				(var rune, var size) = Utf8.DecodeRune (ustr, i, i - byteLen);
 				var count = Rune.ColumnWidth (rune);
-				if (used + count >= width)
+				if (used + count > width)
 					break;
 				driver.AddRune (rune);
 				used += count;

+ 8 - 4
UICatalog/Scenarios/AllViewsTester.cs

@@ -316,7 +316,7 @@ namespace UICatalog {
 
 		void UpdateTitle (View view)
 		{
-			_hostPane.Title = $"{view.GetType().Name} - {view.X.ToString ()}, {view.Y.ToString ()}, {view.Width.ToString ()}, {view.Height.ToString ()}";
+			_hostPane.Title = $"{view.GetType ().Name} - {view.X.ToString ()}, {view.Y.ToString ()}, {view.Width.ToString ()}, {view.Height.ToString ()}";
 		}
 
 		List<Type> GetAllViewClassesCollection ()
@@ -361,13 +361,17 @@ namespace UICatalog {
 				}
 			}
 
-			if (view == null) return null;
-
 			// If the view supports a Title property, set it so we have something to look at
-			if (view.GetType ().GetProperty ("Title") != null) {
+			if (view != null && view.GetType ().GetProperty ("Title") != null) {
 				view?.GetType ().GetProperty ("Title")?.GetSetMethod ()?.Invoke (view, new [] { ustring.Make ("Test Title") });
 			}
 
+			// If the view supports a Source property, set it so we have something to look at
+			if (view != null && view.GetType ().GetProperty ("Source") != null) {
+				var source = new ListWrapper (new List<ustring> () { ustring.Make ("List Item #1"), ustring.Make ("List Item #2"), ustring.Make ("List Item #3")});
+				view?.GetType ().GetProperty ("Source")?.GetSetMethod ()?.Invoke (view, new [] { source });
+			}
+
 			// Set Settings
 			_computedCheckBox.Checked = view.LayoutStyle == LayoutStyle.Computed;