浏览代码

Fixing drivers.

BDisp 3 年之前
父节点
当前提交
640fecba03

+ 8 - 4
Terminal.Gui/ConsoleDrivers/CursesDriver/CursesDriver.cs

@@ -64,16 +64,20 @@ namespace Terminal.Gui {
 				if (runeWidth < 2 && ccol > 0
 					&& Rune.ColumnWidth ((char)contents [crow, ccol - 1, 0]) > 1) {
 
-					Curses.move (crow, ccol - 1);
-					Curses.addch ((int)(uint)' ');
+					var curAtttib = currentAttribute;
+					Curses.attrset (contents [crow, ccol - 1, 1]);
+					Curses.mvaddch (crow, ccol - 1, (int)(uint)' ');
 					contents [crow, ccol - 1, 0] = (int)(uint)' ';
 					Curses.move (crow, ccol);
+					Curses.attrset (curAtttib);
 				} else if (runeWidth < 2 && ccol < Cols - 1 && Rune.ColumnWidth ((char)contents [crow, ccol, 0]) > 1) {
 
-					Curses.move (crow, ccol + 1);
-					Curses.addch ((int)(uint)' ');
+					var curAtttib = currentAttribute;
+					Curses.attrset (contents [crow, ccol + 1, 1]);
+					Curses.mvaddch (crow, ccol + 1, (int)(uint)' ');
 					contents [crow, ccol + 1, 0] = (int)(uint)' ';
 					Curses.move (crow, ccol);
+					Curses.attrset (curAtttib);
 				}
 				Curses.addch ((int)(uint)rune);
 				contents [crow, ccol, 0] = (int)(uint)rune;

+ 15 - 0
Terminal.Gui/ConsoleDrivers/CursesDriver/binding.cs

@@ -177,6 +177,14 @@ namespace Unix.Terminal {
 			return addwstr (new String (c, 1));
 		}
 
+		public static int mvaddch (int y, int x, int ch)
+		{
+			if (ch < 127 || ch > 0xffff)
+				return methods.mvaddch (y, x, ch);
+			char c = (char)ch;
+			return mvaddwstr (y, x, new String (c, 1));
+		}
+
 		static IntPtr stdscr;
 
 		static IntPtr get_ptr (string key)
@@ -293,6 +301,7 @@ namespace Unix.Terminal {
 		static public int curs_set (int visibility) => methods.curs_set (visibility);
 		//static public int addch (int ch) => methods.addch (ch);
 		static public int addwstr (string s) => methods.addwstr (s);
+		static public int mvaddwstr (int y, int x, string s) => methods.mvaddwstr (y, x, s);
 		static public int wmove (IntPtr win, int line, int col) => methods.wmove (win, line, col);
 		static public int waddch (IntPtr win, int ch) => methods.waddch (win, ch);
 		static public int attron (int attrs) => methods.attron (attrs);
@@ -364,7 +373,9 @@ namespace Unix.Terminal {
 		public delegate int move (int line, int col);
 		public delegate int curs_set (int visibility);
 		public delegate int addch (int ch);
+		public delegate int mvaddch (int y, int x, int ch);
 		public delegate int addwstr ([MarshalAs (UnmanagedType.LPWStr)] string s);
+		public delegate int mvaddwstr (int y, int x, [MarshalAs (UnmanagedType.LPWStr)] string s);
 		public delegate int wmove (IntPtr win, int line, int col);
 		public delegate int waddch (IntPtr win, int ch);
 		public delegate int attron (int attrs);
@@ -435,7 +446,9 @@ namespace Unix.Terminal {
 		public readonly Delegates.move move;
 		public readonly Delegates.curs_set curs_set;
 		public readonly Delegates.addch addch;
+		public readonly Delegates.mvaddch mvaddch;
 		public readonly Delegates.addwstr addwstr;
+		public readonly Delegates.mvaddwstr mvaddwstr;
 		public readonly Delegates.wmove wmove;
 		public readonly Delegates.waddch waddch;
 		public readonly Delegates.attron attron;
@@ -508,7 +521,9 @@ namespace Unix.Terminal {
 			move = lib.GetNativeMethodDelegate<Delegates.move> ("move");
 			curs_set = lib.GetNativeMethodDelegate<Delegates.curs_set> ("curs_set");
 			addch = lib.GetNativeMethodDelegate<Delegates.addch> ("addch");
+			mvaddch = lib.GetNativeMethodDelegate<Delegates.mvaddch> ("mvaddch");
 			addwstr = lib.GetNativeMethodDelegate<Delegates.addwstr> ("addwstr");
+			mvaddwstr = lib.GetNativeMethodDelegate<Delegates.mvaddwstr> ("mvaddwstr");
 			wmove = lib.GetNativeMethodDelegate<Delegates.wmove> ("wmove");
 			waddch = lib.GetNativeMethodDelegate<Delegates.waddch> ("waddch");
 			attron = lib.GetNativeMethodDelegate<Delegates.attron> ("attron");

+ 2 - 4
Terminal.Gui/ConsoleDrivers/WindowsDriver.cs

@@ -1485,8 +1485,6 @@ namespace Terminal.Gui {
 					var prevPosition = crow * Cols + ccol + 1;
 					OutputBuffer [prevPosition].Char.UnicodeChar = (char)' ';
 					contents [crow, ccol + 1, 0] = (int)(uint)' ';
-				} else if (rune != ' ') {
-
 				}
 				OutputBuffer [position].Attributes = (ushort)currentAttribute;
 				OutputBuffer [position].Char.UnicodeChar = (char)rune;
@@ -1501,8 +1499,8 @@ namespace Terminal.Gui {
 				if (validClip) {
 					position = crow * Cols + ccol;
 					OutputBuffer [position].Attributes = (ushort)currentAttribute;
-					OutputBuffer [position].Char.UnicodeChar = '\0';
-					contents [crow, ccol, 0] = (int)(uint)'\0';
+					OutputBuffer [position].Char.UnicodeChar = (char)0x00;
+					contents [crow, ccol, 0] = (int)(uint)0x00;
 					contents [crow, ccol, 1] = currentAttribute;
 					contents [crow, ccol, 2] = 0;
 				}

+ 10 - 2
Terminal.Gui/Core/ConsoleDriver.cs

@@ -692,15 +692,23 @@ namespace Terminal.Gui {
 		/// <returns></returns>
 		public static Rune MakePrintable (Rune c)
 		{
-			if (c <= 0x1F || (c >= 0x80 && c <= 0x9F)) {
+			var controlChars = gethexaformat (c, 4);
+			if (controlChars <= 0x1F || (controlChars >= 0X7F && controlChars <= 0x9F)) {
 				// ASCII (C0) control characters.
 				// C1 control characters (https://www.aivosto.com/articles/control-characters.html#c1)
-				return new Rune (c + 0x2400);
+				return new Rune (controlChars + 0x2400);
 			} else {
 				return c;
 			}
 		}
 
+		static uint gethexaformat (uint rune, int length)
+		{
+			var hex = rune.ToString ($"x{length}");
+			var hexstr = hex.Substring (hex.Length - length, length);
+			return (uint)int.Parse (hexstr, System.Globalization.NumberStyles.HexNumber);
+		}
+
 		/// <summary>
 		/// Ensures that the column and line are in a valid range from the size of the driver.
 		/// </summary>