[Ttssh2-commit] [8133] URL強調

Back to archive index
scmno****@osdn***** scmno****@osdn*****
2019年 9月 13日 (金) 01:00:00 JST


Revision: 8133
          https://osdn.net/projects/ttssh2/scm/svn/commits/8133
Author:   zmatsuo
Date:     2019-09-13 00:59:59 +0900 (Fri, 13 Sep 2019)
Log Message:
-----------
URL強調

- ある程度動作するようになった(途中)

Modified Paths:
--------------
    branches/unicode_buf/teraterm/teraterm/buffer.c

-------------- next part --------------
Modified: branches/unicode_buf/teraterm/teraterm/buffer.c
===================================================================
--- branches/unicode_buf/teraterm/teraterm/buffer.c	2019-09-12 15:59:48 UTC (rev 8132)
+++ branches/unicode_buf/teraterm/teraterm/buffer.c	2019-09-12 15:59:59 UTC (rev 8133)
@@ -124,6 +124,10 @@
 static int SaveBuffY;
 
 #if UNICODE_INTERNAL_BUFF
+static void BuffDrawLineI(int DrawX, int DrawY, int SY, int IStart, int IEnd);
+#endif
+
+#if UNICODE_INTERNAL_BUFF
 static void BuffSetChar2(buff_char_t *buff, char32_t u32, char property, char half_width)
 {
 	size_t wstr_len;
@@ -1870,10 +1874,14 @@
 /**
  *	(x,y)\x82\xA9\x82\xE7 str\x82Ɠ\xAF\x88ꂩ\x92\xB2\x82ׂ\xE9
  *
+ *	@param		x		\x83}\x83C\x83i\x83X\x82̎\x9E\x81A\x8F\xE3\x82̍s\x82\xAA\x91ΏۂɂȂ\xE9
  *	@param		y		PageStart + CursorY
+ *	@param		LineCntinued	TRUE=\x8Ds\x82̌p\x91\xB1\x82\xF0\x8Dl\x97\xB6\x82\xB7\x82\xE9
+ *	@retval		TRUE	\x83}\x83b\x83`\x82\xB5\x82\xBD
+ *	@retval		FALSE	\x83}\x83b\x83`\x82\xB5\x82Ă\xA2\x82Ȃ\xA2
  */
 #if UNICODE_INTERNAL_BUFF
-static BOOL MatchString(int x, int y, const wchar_t *str)
+static BOOL MatchString(int x, int y, const wchar_t *str, BOOL LineContinued)
 {
 	BOOL result;
 	int match_pos = 0;
@@ -1882,6 +1890,24 @@
 	if (len == 0) {
 		return FALSE;
 	}
+	while(x < 0) {
+		if (LineContinued && (AttrBuff[TmpPtr+0] & AttrLineContinued) == 0) {
+			// \x8Ds\x82\xAA\x8Cp\x91\xB1\x82\xB5\x82Ă\xA2\x82邩\x8Dl\x97\xB6 & \x8Cp\x91\xB1\x82\xB5\x82Ă\xA2\x82Ȃ\xA2
+			x = 0;	// \x8Ds\x93\xAA\x82\xA9\x82\xE7\x82Ƃ\xB7\x82\xE9
+			break;
+		}
+		TmpPtr = PrevLinePtr(TmpPtr);
+		x += NumOfColumns;
+	}
+	while(x > NumOfColumns) {
+		if (LineContinued && (AttrBuff[TmpPtr+NumOfColumns-1] & AttrLineContinued) == 0) {
+			// \x8Ds\x82\xAA\x8Cp\x91\xB1\x82\xB5\x82Ă\xA2\x82邩\x8Dl\x97\xB6 & \x8Cp\x91\xB1\x82\xB5\x82Ă\xA2\x82Ȃ\xA2
+			x = 0;	// \x8Ds\x93\xAA\x82\xA9\x82\xE7\x82Ƃ\xB7\x82\xE9
+			break;
+		}
+		TmpPtr = NextLinePtr(TmpPtr);
+		x -= NumOfColumns;
+	}
 
 	for(;;) {
 		// 1\x95\xB6\x8E\x9A\x93\xAF\x88ꂩ\x92\xB2\x82ׂ\xE9
@@ -1901,8 +1927,16 @@
 		// \x8E\x9F\x82̕\xB6\x8E\x9A
 		x++;
 		if (x == NumOfColumns) {
-			x = 0;
-			TmpPtr = NextLinePtr(TmpPtr);
+			if (LineContinued && (AttrBuff[TmpPtr+NumOfColumns-1] & AttrLineContinued) != 0) {
+				// \x8E\x9F\x82̍s\x82\xD6
+				x = 0;
+				TmpPtr = NextLinePtr(TmpPtr);
+				y++;
+			} else {
+				// \x8Ds\x96\x96
+				result = FALSE;
+				break;
+			}
 		}
 	}
 
@@ -1934,12 +1968,12 @@
 			IStart = sx;
 		}
 		if (y== ey) {
-			IEnd = ex -1;
+			IEnd = ex;
 		}
 
 		x = IStart;
 		while (x <= IEnd) {
-			if (MatchString(x, y, str)) {
+			if (MatchString(x, y, str, TRUE)) {
 				// \x83}\x83b\x83`\x82\xB5\x82\xBD
 				*match_x = x;
 				*match_y = y;
@@ -2290,7 +2324,7 @@
 	}
 }
 
-static BOOL isURLchar(unsigned char u32)
+static BOOL isURLchar(unsigned int u32)
 {
 	// RFC3986(Uniform Resource Identifier (URI): Generic Syntax)\x82ɏ\x80\x8B\x92\x82\xB7\x82\xE9
 	// by sakura editor 1.5.2.1: etc_uty.cpp
@@ -2612,6 +2646,145 @@
 }
 #endif
 
+#if UNICODE_INTERNAL_BUFF
+// cur_x	\x83J\x81[\x83\\x83\x8B\x88ʒu
+// cur_y	\x83J\x81[\x83\\x83\x8B\x88ʒu(!\x83o\x83b\x83t\x83@\x88ʒu)
+static void mark_url_w(int cur_x, int cur_y)
+{
+	static int sw = 0;
+	if (sw == 0)
+		return;
+
+	int sx;
+	int sy;
+	int ex;
+	int ey;
+	LONG TmpPtr;
+
+	// \x8Ds\x93\xAA\x82\xF0\x92T\x82\xB7
+	sx = 0;
+	sy = cur_y;
+	TmpPtr = GetLinePtr(PageStart+sy);
+	while ((AttrBuff[TmpPtr] & AttrLineContinued) != 0) {
+		sy--;
+		TmpPtr = PrevLinePtr(TmpPtr);
+	}
+	// \x8Ds\x96\x96\x82\xF0\x92T\x82\xB7
+	ex = NumOfColumns-1;
+	ey = cur_y;
+	TmpPtr = GetLinePtr(PageStart+ey);
+	while ((AttrBuff[TmpPtr+NumOfColumns-1] & AttrLineContinued) != 0) {
+		ey++;
+		TmpPtr = NextLinePtr(TmpPtr);
+	}
+	const buff_char_t *b = &CodeBuffW[TmpPtr+ex];
+	while (1) {
+		if (b->u32 != ' ') {
+			break;
+		}
+		b--;
+		ex--;
+	}
+
+	// URL\x83A\x83g\x83\x8A\x83r\x83\x85\x81[\x83g\x82𗎂Ƃ\xB7
+	{
+		int x;
+		int y;
+		for (y = sy; y <= ey; y++) {
+			int sx_i = 0;
+			int ex_i = NumOfColumns - 1;
+			if (y == sy) {
+				sx_i = sx;
+			}
+			else if (y == ey) {
+				ex_i = ex;
+			}
+			TmpPtr = GetLinePtr(PageStart + y);
+			for (x = sx_i; x < ex_i; x++) {
+				AttrBuff[TmpPtr + x] &= ~AttrURL;
+			}
+		}
+	}
+
+
+	// \x83v\x83\x8C\x83t\x83B\x83b\x83N\x83X\x82\xF0\x92T\x82\xB7
+	for(;;) {
+		static const struct schemes_t {
+			const wchar_t *str;
+			int len;
+		} schemes[] = {
+			{ L"https://", 8 },
+			{ L"http://", 7},
+			{ L"sftp://", 7},
+			{ L"tftp://", 7},
+			{ L"news://", 7},
+			{ L"ftp://", 6},
+			{ L"mms://", 6},
+		};
+		int i;
+		const wchar_t *prefix;
+		int len;
+		int match_x, match_y;
+
+		if (sx >= ex && sy >= ey) {
+			break;
+		}
+
+		for (i = 0; i < _countof(schemes); i++) {
+			prefix = schemes[i].str;
+			len = schemes[i].len - 1;
+			// \x83}\x83b\x83`\x82\xB7\x82邩?
+			if (BuffGetMatchPosFromString(sx, PageStart+sy, sx, PageStart+sy, prefix, &match_x, &match_y)) {
+				// \x83}\x83b\x83`\x82\xB5\x82\xBD
+				break;
+			}
+		}
+
+		if (i < _countof(schemes)) {
+			// \x83}\x83b\x83`\x82\xB5\x82\xBD
+			int x;
+			int y;
+			int left = len;
+			for (y = match_y; y <= PageStart+ey; y++) {
+				int sx_i = 0;
+				int ex_i = NumOfColumns - 1;	// \x82Ƃɂ\xA9\x82\xAD\x8Ds\x96\x96\x82܂\xC5
+				if (y == PageStart+sy) {
+					sx_i = match_x;
+					//ex_i = ex_i - match_x;
+				}
+				TmpPtr = GetLinePtr(y);
+				for (x = sx_i; x <= ex_i; x++) {
+					const buff_char_t *b = &CodeBuffW[TmpPtr + x];
+					if (isURLchar(b->u32)) {
+						AttrBuff[TmpPtr + x] |= AttrURL;
+					} else {
+						// \x92\x86\x92f, \x8E\x9F\x82͂\xB1\x82\xB1\x82\xA9\x82\xE7\x92T\x82\xB5\x8En\x82߂\xE9
+						sx = x;
+						sy = y - PageStart;
+						break;
+					}
+				}
+				if (x <= ex_i) {
+					// \x92\x86\x92f\x82\xB5\x82\xBD
+					sx = x;
+					break;
+				}
+			}
+			if (y <= PageStart + ey) {
+				// \x92\x86\x92f\x82\xB5\x82\xBD
+				sy = y - PageStart;
+			}
+		}
+
+		sx++;
+		if (sx >= NumOfColumns) {
+			sx = 0;
+			sy++;
+		}
+	}
+}
+#endif
+
 /**
  *	\x83\x86\x83j\x83R\x81[\x83h\x83L\x83\x83\x83\x89\x83N\x83^\x82\xF01\x95\xB6\x8E\x9A\x83o\x83b\x83t\x83@\x82֓\xFC\x97͂\xB7\x82\xE9
  *	@param[in]	u32		unicode character(UTF-32)
@@ -2848,13 +3021,20 @@
 			StrChangeCount = StrChangeCount + 2;
 		}
 
-		/* begin - ishizaki */
+		// URL\x82̌\x9F\x8Fo
+		// DEL\x8E\x9E\x82\xC9URL\x82\xBE\x82\xC1\x82\xBD\x82\xE7URL\x95\xB6\x8E\x9A\x97\xF1\x82\xF0\x8E\xE6\x82\xC1\x82Ă\xAB\x82Č\x9F\x8D\xB8\x82\xB7\x82\xE9
+#if 0
 		{
 			int x = CursorX;
 			BOOL pass = FALSE;
 
+			// TODO 1\x82Œ\xE3\x82\xEB\x82\xE0URL
 			// 1\x82‘O\x82̃L\x83\x83\x83\x89\x83N\x83^\x82\xAAURL?
-			if (x >= 1 && AttrLine[x-1] & AttrURL) {
+			// \x88\xEA\x94ԍ\xB6\x82̎\x9E\x82́A\x91O\x82̍s\x82\xA9\x82\xE7\x8Cp\x91\xB1\x82\xB5\x82Ă\xA2\x82āA\x91O\x82̍s\x82̍ŌオURL\x82\xBE\x82\xC1\x82\xBD\x8E\x9E
+			if ((x == 0 &&
+				 ((AttrLine[0] & AttrLineContinued) != 0) &&
+				 ((AttrBuff[(PageStart + (CursorY-1)) * NumOfColumns + NumOfColumns - 1] & AttrURL) != 0)) ||
+				(x >= 1 && AttrLine[x-1] & AttrURL)) {
 				if (isURLchar(u32)) {
 					// URL\x82\xF0\x90L\x82΂\xB7
 					AttrLine[x] |= AttrURL;
@@ -2870,6 +3050,10 @@
 			if (!pass) {
 				// '/' \x82\xAA\x93\xFC\x97͂\xB3\x82ꂽ\x82璲\x82׎n\x82߂\xE9
 				if (u32 == '/') {
+					if (MatchString(x-2, PageStart+CursorY, L"://", TRUE)) {
+						pass = FALSE;
+					}
+#if 0
 					if ((CodeLineW[x-2].u32 == ':') && (CodeLineW[x-2].CombinationCharCount16 == 0) &&
 						(CodeLineW[x-1].u32 == '/') && (CodeLineW[x-1].CombinationCharCount16 == 0) &&
 						(CodeLineW[x-0].u32 == '/') && (CodeLineW[x-0].CombinationCharCount16 == 0))
@@ -2878,6 +3062,7 @@
 					} else {
 						pass = TRUE;
 					}
+#endif
 				} else {
 					pass = TRUE;
 				}
@@ -2901,27 +3086,64 @@
 				for (i = 0; i < _countof(schemes); i++) {
 					const wchar_t *prefix = schemes[i].str;
 					const int len = schemes[i].len - 1;
-					if (x >= len) {
-						// \x83}\x83b\x83`\x82\xB7\x82邩?
-						int sx = x - len;
-						int sy = PageStart + CursorY;
-						int match_x, match_y;
-						if (BuffGetMatchPosFromString(sx, sy, x, sy, prefix, &match_x, &match_y)) {
-							// \x83}\x83b\x83`\x82\xB5\x82\xBD\x82̂\xC5URL\x91\xAE\x90\xAB\x82\xF0\x95t\x82\xAF\x82\xE9
+					int sx = x - len;
+					int sy = PageStart + CursorY;
+					int ey = sy;
+					if (x < len) {
+						// \x92Z\x82\xA2
+						if ((AttrLine[0] & AttrLineContinued) == 0) {
+							// \x91O\x82̍s\x82ƘA\x8C\x8B\x82\xB5\x82Ă\xA2\x82Ȃ\xA2
+							continue;
+						}
+						// \x91O\x82̍s\x82\xA9\x82猟\x8D\x{142A42}\xAF\x82\xE9
+						sx = NumOfColumns + sx;
+						sy = PageStart + CursorY - 1;
+					}
+					// \x83}\x83b\x83`\x82\xB7\x82邩?
+					int match_x, match_y;
+					if (BuffGetMatchPosFromString(sx, sy, x, ey, prefix, &match_x, &match_y)) {
+						// \x83}\x83b\x83`\x82\xB5\x82\xBD\x82̂\xC5URL\x91\xAE\x90\xAB\x82\xF0\x95t\x82\xAF\x82\xE9
+						if (sy == ey) {
 							int i;
 							for (i = 0; i <= len; i++) {
-								AttrLine[sx+i] |= AttrURL;
+								AttrLine[sx + i] |= AttrURL;
 							}
 							if (StrChangeStart > sx) {
 								StrChangeStart = sx;
 								StrChangeCount += len;
 							}
-							break;
 						}
+						else {
+							LONG TmpPtr = GetLinePtr(sy);
+							int xx = sx;
+							size_t left = len + 1;
+							while (left > 0) {
+								AttrBuff[TmpPtr + xx] |= AttrURL;
+								xx++;
+								if (xx == NumOfColumns) {
+									int draw_x = sx;
+									int draw_y = CursorY - 1;
+									if (IsLineVisible(&draw_x, &draw_y)) {
+										BuffDrawLineI(draw_x, draw_y, PageStart+CursorY-1, sx, NumOfColumns-1);
+									}
+									TmpPtr = NextLinePtr(TmpPtr);
+									xx = 0;
+								}
+								left--;
+							}
+							StrChangeStart = 0;
+							StrChangeCount = xx;
+						}
+						break;
 					}
 				}
 			}
 		}
+#else
+		{
+			mark_url_w(CursorX, CursorY);
+		}
+#endif
 //		markURL(CursorX);
 //		markURL(CursorX+1);
 		/* end - ishizaki */


Ttssh2-commit メーリングリストの案内
Back to archive index