[Ttssh2-commit] [3872] Bracketed Paste Mode をサポート。

Back to archive index

svnno****@sourc***** svnno****@sourc*****
2010年 5月 9日 (日) 18:21:21 JST


Revision: 3872
          http://sourceforge.jp/projects/ttssh2/svn/view?view=rev&revision=3872
Author:   doda
Date:     2010-05-09 18:21:21 +0900 (Sun, 09 May 2010)

Log Message:
-----------
Bracketed Paste Mode をサポート。
対応しているホスト側のアプリケーションで、キー入力と貼り付けの区別が付けられるようになる。

.vimrcの例:
if &term == "xterm"
  let &t_ti = &t_ti . "\e[?2004h"
  let &t_te = "\e[?2004l" . &t_te
  set pastetoggle=<Esc>[201~
  function XTermPasteBegin(ret)
    set paste
    return a:ret
  endfunction
  map <special> <expr> <Esc>[200~ XTermPasteBegin("i")
  imap <special> <expr> <Esc>[200~ XTermPasteBegin("")
endif

参考: https://bugzilla.gnome.org/show_bug.cgi?id=605299

Modified Paths:
--------------
    trunk/teraterm/teraterm/clipboar.c
    trunk/teraterm/teraterm/clipboar.h
    trunk/teraterm/teraterm/tekwin.cpp
    trunk/teraterm/teraterm/ttdde.c
    trunk/teraterm/teraterm/vtterm.c
    trunk/teraterm/teraterm/vtterm.h
    trunk/teraterm/teraterm/vtwin.cpp


-------------- next part --------------
Modified: trunk/teraterm/teraterm/clipboar.c
===================================================================
--- trunk/teraterm/teraterm/clipboar.c	2010-04-26 12:06:23 UTC (rev 3871)
+++ trunk/teraterm/teraterm/clipboar.c	2010-05-09 09:21:21 UTC (rev 3872)
@@ -21,11 +21,15 @@
 static HGLOBAL CBCopyHandle = NULL;
 static PCHAR CBCopyPtr = NULL;
 
+#define CB_BRACKET_NONE  0
+#define CB_BRACKET_START 1
+#define CB_BRACKET_END   2
 // for clipboard paste
 static HGLOBAL CBMemHandle = NULL;
 static PCHAR CBMemPtr = NULL;
 static LONG CBMemPtr2 = 0;
 static BOOL CBAddCR = FALSE;
+static BOOL CBBracketed = CB_BRACKET_NONE;
 static BYTE CBByte;
 static BOOL CBRetrySend;
 static BOOL CBRetryEcho;
@@ -83,7 +87,7 @@
 	CBCopyHandle = NULL;
 }
 
-void CBStartPaste(HWND HWin, BOOL AddCR,
+void CBStartPaste(HWND HWin, BOOL AddCR, BOOL Bracketed,
                   int BuffSize, PCHAR DataPtr, int DataSize)
 //
 //  DataPtr and DataSize are used only for DDE
@@ -100,6 +104,9 @@
 	}
 
 	CBAddCR = AddCR;
+	if (Bracketed) {
+		CBBracketed = CB_BRACKET_START;
+	}
 
 	if (BuffSize==0) { // for clipboar
 		if (IsClipboardFormatAvailable(CF_TEXT)) {
@@ -158,6 +165,9 @@
 	int c;
 	BOOL EndFlag;
 	static DWORD lastcr;
+	static char BracketStart[] = "\033[200~";
+	static char BracketEnd[] = "\033[201~";
+	static int BracketPtr = 0;
 	DWORD now;
 
 	if (CBMemHandle==NULL) {
@@ -204,7 +214,14 @@
 		}
 
 		EndFlag = (CBMemPtr[CBMemPtr2]==0);
-		if (! EndFlag) {
+		if (CBBracketed == CB_BRACKET_START) {
+			CBByte = BracketStart[BracketPtr++];
+			if (BracketPtr >= sizeof(BracketStart) - 1) {
+				CBBracketed = CB_BRACKET_END;
+				BracketPtr = 0;
+			}
+		}
+		else if (! EndFlag) {
 			CBByte = CBMemPtr[CBMemPtr2];
 			CBMemPtr2++;
 // Decoding characters which are encoded by MACRO
@@ -224,6 +241,14 @@
 			CBAddCR = FALSE;
 			CBByte = 0x0d;
 		}
+		else if (CBBracketed == CB_BRACKET_END) {
+			EndFlag = FALSE;
+			CBByte = BracketEnd[BracketPtr++];
+			if (BracketPtr >= sizeof(BracketEnd) - 1) {
+				CBBracketed = CB_BRACKET_NONE;
+				BracketPtr = 0;
+			}
+		}
 		else {
 			CBEndPaste();
 			return;

Modified: trunk/teraterm/teraterm/clipboar.h
===================================================================
--- trunk/teraterm/teraterm/clipboar.h	2010-04-26 12:06:23 UTC (rev 3871)
+++ trunk/teraterm/teraterm/clipboar.h	2010-05-09 09:21:21 UTC (rev 3872)
@@ -11,7 +11,7 @@
 /* prototypes */
 PCHAR CBOpen(LONG MemSize);
 void CBClose();
-void CBStartPaste(HWND HWin, BOOL AddCR,
+void CBStartPaste(HWND HWin, BOOL AddCR, BOOL Bracketed,
 		  int BuffSize, PCHAR DataPtr, int DataSize);
 void CBSend();
 void CBEndPaste();

Modified: trunk/teraterm/teraterm/tekwin.cpp
===================================================================
--- trunk/teraterm/teraterm/tekwin.cpp	2010-04-26 12:06:23 UTC (rev 3871)
+++ trunk/teraterm/teraterm/tekwin.cpp	2010-05-09 09:21:21 UTC (rev 3872)
@@ -485,7 +485,7 @@
 
 void CTEKWindow::OnRButtonUp(UINT nFlags, CPoint point)
 {
-	CBStartPaste(tk.HWin,FALSE,0,NULL,0);
+	CBStartPaste(tk.HWin, FALSE, FALSE, 0, NULL, 0);
 }
 
 void CTEKWindow::OnSetFocus(CWnd* pOldWnd)
@@ -737,12 +737,12 @@
 
 void CTEKWindow::OnEditPaste()
 {
-	CBStartPaste(tk.HWin,FALSE,0,NULL,0);
+	CBStartPaste(tk.HWin, FALSE, FALSE, 0, NULL, 0);
 }
 
 void CTEKWindow::OnEditPasteCR()
 {
-	CBStartPaste(tk.HWin,TRUE,0,NULL,0);
+	CBStartPaste(tk.HWin, TRUE, FALSE, 0, NULL, 0);
 }
 
 void CTEKWindow::OnEditClearScreen()

Modified: trunk/teraterm/teraterm/ttdde.c
===================================================================
--- trunk/teraterm/teraterm/ttdde.c	2010-04-26 12:06:23 UTC (rev 3871)
+++ trunk/teraterm/teraterm/ttdde.c	2010-05-09 09:21:21 UTC (rev 3872)
@@ -254,7 +254,7 @@
 
 	DataPtr = DdeAccessData(Data,&DataSize);
 	if (DataPtr==NULL) return DDE_FNOTPROCESSED;
-	CBStartPaste(NULL,FALSE,CBBufSize,DataPtr,DataSize);
+	CBStartPaste(NULL, FALSE, FALSE, CBBufSize, DataPtr, DataSize);
 	DdeUnaccessData(Data);
 	if (TalkStatus==IdTalkCB)
 		return (HDDEDATA)DDE_FACK;

Modified: trunk/teraterm/teraterm/vtterm.c
===================================================================
--- trunk/teraterm/teraterm/vtterm.c	2010-04-26 12:06:23 UTC (rev 3871)
+++ trunk/teraterm/teraterm/vtterm.c	2010-05-09 09:21:21 UTC (rev 3872)
@@ -54,6 +54,7 @@
 static BOOL AutoWrapMode;
 static BOOL FocusReportMode;
 static BOOL AltScr;
+BOOL BracketedPaste;
 int MouseReportMode;
 
 // save/restore cursor
@@ -200,6 +201,9 @@
 
   // Alternate Screen Buffer
   AltScr = FALSE;
+
+  // Bracketed Paste Mode
+  BracketedPaste = FALSE;
 }
 
 void ResetCharSet()
@@ -2172,6 +2176,10 @@
 	      BuffClearScreen();
 	      AltScr = TRUE;
 	    }
+	    break;
+	  case 2004: // Bracketed Paste Mode
+	    BracketedPaste = TRUE;
+	    break;
 	}
     }
 
@@ -2283,6 +2291,9 @@
 	      RestoreCursor();
 	    }
 	    break;
+	  case 2004: // Bracketed Paste Mode
+	    BracketedPaste = FALSE;
+	    break;
 	}
     }
 

Modified: trunk/teraterm/teraterm/vtterm.h
===================================================================
--- trunk/teraterm/teraterm/vtterm.h	2010-04-26 12:06:23 UTC (rev 3871)
+++ trunk/teraterm/teraterm/vtterm.h	2010-05-09 09:21:21 UTC (rev 3872)
@@ -3,7 +3,6 @@
  All rights reserved. */
 
 /* TERATERM.EXE, VT terminal emulation */
-extern int MouseReportMode;
 
 #ifdef __cplusplus
 extern "C" {
@@ -20,6 +19,8 @@
 BOOL MouseReport(int Event, int Button, int Xpos, int Ypos);
 void EndTerm();
 
+extern BOOL BracketedPaste;
+
 #ifdef __cplusplus
 }
 #endif

Modified: trunk/teraterm/teraterm/vtwin.cpp
===================================================================
--- trunk/teraterm/teraterm/vtwin.cpp	2010-04-26 12:06:23 UTC (rev 3871)
+++ trunk/teraterm/teraterm/vtwin.cpp	2010-05-09 09:21:21 UTC (rev 3872)
@@ -780,7 +780,7 @@
 	// added ConfirmPasteMouseRButton (2007.3.17 maya)
 	if (pasteRButton && !ts.ConfirmPasteMouseRButton) {
 		if (CBStartPasteConfirmChange(HVTWin)) {
-			CBStartPaste(HVTWin,FALSE,0,NULL,0);
+			CBStartPaste(HVTWin, FALSE, BracketedPaste, 0, NULL, 0);
 			/* Å‰ºs‚Å‚¾‚¯Ž©“®ƒXƒNƒ[ƒ‹‚·‚éÝ’è‚̏ꍇ
 			   ƒy[ƒXƒgˆ—‚ŃXƒNƒ[ƒ‹‚³‚¹‚é */
 			if (ts.AutoScrollOnlyInBottomLine != 0 && WinOrgY != 0) {
@@ -790,7 +790,7 @@
 	}
 	else if (pasteMButton) {
 		if (CBStartPasteConfirmChange(HVTWin)) {
-			CBStartPaste(HVTWin,FALSE,0,NULL,0);
+			CBStartPaste(HVTWin, FALSE, BracketedPaste, 0, NULL, 0);
 			/* Å‰ºs‚Å‚¾‚¯Ž©“®ƒXƒNƒ[ƒ‹‚·‚éÝ’è‚̏ꍇ
 			   ƒy[ƒXƒgˆ—‚ŃXƒNƒ[ƒ‹‚³‚¹‚é */
 			if (ts.AutoScrollOnlyInBottomLine != 0 && WinOrgY != 0) {
@@ -3913,7 +3913,7 @@
 {
 	// add confirm (2008.2.4 yutaka)
 	if (CBStartPasteConfirmChange(HVTWin)) {
-		CBStartPaste(HVTWin,FALSE,0,NULL,0);
+		CBStartPaste(HVTWin, FALSE, BracketedPaste, 0, NULL, 0);
 		/* Å‰ºs‚Å‚¾‚¯Ž©“®ƒXƒNƒ[ƒ‹‚·‚éÝ’è‚̏ꍇ
 		   ƒy[ƒXƒgˆ—‚ŃXƒNƒ[ƒ‹‚³‚¹‚é */
 		if (ts.AutoScrollOnlyInBottomLine != 0 && WinOrgY != 0) {
@@ -3926,7 +3926,7 @@
 {
 	// add confirm (2008.3.11 maya)
 	if (CBStartPasteConfirmChange(HVTWin)) {
-		CBStartPaste(HVTWin,TRUE,0,NULL,0);
+		CBStartPaste(HVTWin, TRUE, BracketedPaste, 0, NULL, 0);
 		/* Å‰ºs‚Å‚¾‚¯Ž©“®ƒXƒNƒ[ƒ‹‚·‚éÝ’è‚̏ꍇ
 		   ƒy[ƒXƒgˆ—‚ŃXƒNƒ[ƒ‹‚³‚¹‚é */
 		if (ts.AutoScrollOnlyInBottomLine != 0 && WinOrgY != 0) {
@@ -5034,7 +5034,7 @@
 	if (sending) {
 		// ’[––‚Ö•¶Žš—ñ‚𑗂荞‚Þ
 		// DDE’ʐM‚ÉŽg‚¤ŠÖ”‚ɕύXB(2006.2.7 yutaka)
-		CBStartPaste(HVTWin, FALSE, TermWidthMax/*CBBufSize*/, buf, buflen);
+		CBStartPaste(HVTWin, FALSE, BracketedPaste, TermWidthMax/*CBBufSize*/, buf, buflen);
 		// ‘—Mƒf[ƒ^‚ª‚ ‚éê‡‚Í‘—M‚·‚é
 		if (TalkStatus == IdTalkCB) {
 			CBSend();



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