Skip to content

Instantly share code, notes, and snippets.

@saitoha
Created August 11, 2012 18:15
Show Gist options
  • Select an option

  • Save saitoha/3326112 to your computer and use it in GitHub Desktop.

Select an option

Save saitoha/3326112 to your computer and use it in GitHub Desktop.
OSC 52 set access for iTerm2
diff --git a/VT100Screen.h b/VT100Screen.h
index 4f46cdc..8a70e79 100644
--- a/VT100Screen.h
+++ b/VT100Screen.h
@@ -177,6 +177,7 @@ void StringToScreenChars(NSString *s,
- (BOOL) blinkingCursor;
- (void) setBlinkingCursor: (BOOL) flag;
+- (void)processOSC52: (NSString*) commandString;
- (void)showCursor:(BOOL)show;
- (void)setPlayBellFlag:(BOOL)flag;
- (void)setShowBellFlag:(BOOL)flag;
diff --git a/VT100Screen.m b/VT100Screen.m
index 5478215..c74a657 100644
--- a/VT100Screen.m
+++ b/VT100Screen.m
@@ -57,6 +57,9 @@
#import "RegexKitLite.h"
#import "TmuxStateParser.h"
+// for OSC52 base64 decoding
+#import <apr-1/apr_base64.h>
+
#define MAX_SCROLLBACK_LINES 1000000
#define MAX_SCROLL_AT_ONCE 1024
#define DIRTY_MAGIC 0x76 // Used to ensure we don't go off end of dirty array
@@ -1395,6 +1398,51 @@ static char* FormatCont(int c)
blinkingCursor = flag;
}
+- (void)processOSC52: (NSString*) commandString
+{
+ //
+ // - set access
+ // ESC ] 5 2 ; Pc ; <base64 encoded string> ST
+ //
+ // - get access
+ // ESC ] 5 2 ; Pc ; ? ST
+ //
+ // Pc consists from:
+ // 'p', 's', 'c', '0', '1', '2', '3', '4', '5', '6', '7'
+ //
+ // Note: Pc is ignored now.
+ //
+
+ char *buffer = (char*)[commandString cStringUsingEncoding:NSASCIIStringEncoding];
+
+ // ignore first parameter now
+ while (strchr("psc01234567", *buffer)) {
+ ++buffer;
+ }
+ if (*buffer != ';') {
+ return; // fail to parse
+ }
+ ++buffer;
+ if (*buffer == '?') { // OSC 52 get access
+ // TODO: Now get access is not implemented.
+ } else { // OSC 52 set access
+
+ // decode base64 string.
+ int destLength = apr_base64_decode_len(buffer);
+ char *decodedBuffer = malloc(destLength);
+ apr_base64_decode(decodedBuffer, buffer);
+ NSString *resultString = [[[NSString alloc] initWithBytesNoCopy: decodedBuffer
+ length: destLength
+ encoding: [TERMINAL encoding]
+ freeWhenDone: YES]
+ autorelease];
+ // set the result to paste board.
+ NSPasteboard* thePasteboard = [NSPasteboard generalPasteboard];
+ [thePasteboard declareTypes:[NSArray arrayWithObject:NSStringPboardType] owner:nil];
+ [thePasteboard setString:resultString forType:NSStringPboardType];
+ }
+}
+
// Should the profile name be inculded in the window/tab title? Requires both
// a per-profile option to be on as well as the global option.
- (BOOL)_syncTitle
@@ -1735,6 +1783,9 @@ static char* FormatCont(int c)
[SESSION setWindowTitle: newTitle];
[SESSION setName: newTitle];
break;
+ case XTERMCC_PASTE64:
+ [self processOSC52: [[token.u.string copy] autorelease]];
+ break;
case XTERMCC_ICON_TITLE:
newTitle = [[token.u.string copy] autorelease];
if ([self _syncTitle]) {
diff --git a/VT100Terminal.h b/VT100Terminal.h
index 2c59900..578be53 100644
--- a/VT100Terminal.h
+++ b/VT100Terminal.h
@@ -129,6 +129,7 @@
#define XTERMCC_PROPRIETARY_ETERM_EXT 110
#define XTERMCC_SET_PALETTE 111
#define XTERMCC_SET_KVP 112
+#define XTERMCC_PASTE64 113
// Some ansi stuff
#define ANSICSI_CHA 3000 // Cursor Horizontal Absolute
diff --git a/VT100Terminal.m b/VT100Terminal.m
index 7954acc..a421327 100644
--- a/VT100Terminal.m
+++ b/VT100Terminal.m
@@ -882,6 +882,10 @@ static VT100TCC decode_xterm(unsigned char *datap,
// <Esc>]50;key=value^G
result.type = XTERMCC_SET_KVP;
break;
+ case 52:
+ // base64 copy/paste (OPT_PASTE64)
+ result.type = XTERMCC_PASTE64;
+ break;
default:
result.type = VT100_NOTSUPPORT;
break;
diff --git a/iTerm.xcodeproj/project.pbxproj b/iTerm.xcodeproj/project.pbxproj
index 6a16546..1535ade 100644
--- a/iTerm.xcodeproj/project.pbxproj
+++ b/iTerm.xcodeproj/project.pbxproj
@@ -1976,7 +1976,10 @@
);
LINK_WITH_STANDARD_LIBRARIES = YES;
MACOSX_DEPLOYMENT_TARGET = 10.5;
- OTHER_LDFLAGS = "-licucore";
+ OTHER_LDFLAGS = (
+ "-laprutil-1",
+ "-licucore",
+ );
PRODUCT_NAME = iTerm;
SDKROOT = macosx10.7;
SECTORDER_FLAGS = "";
@@ -2025,7 +2028,10 @@
);
MACOSX_DEPLOYMENT_TARGET = 10.5;
OTHER_CODE_SIGN_FLAGS = "";
- OTHER_LDFLAGS = "-licucore";
+ OTHER_LDFLAGS = (
+ "-laprutil-1",
+ "-licucore",
+ );
PRODUCT_NAME = iTerm;
SDKROOT = macosx10.6;
VALID_ARCHS = "ppc i386 x86_64";
@@ -2070,7 +2076,10 @@
"\"$(SRCROOT)/Growl.framework\"",
);
MACOSX_DEPLOYMENT_TARGET = 10.5;
- OTHER_LDFLAGS = "-licucore";
+ OTHER_LDFLAGS = (
+ "-laprutil-1",
+ "-licucore",
+ );
OTHER_REZFLAGS = "";
PRODUCT_NAME = iTerm;
REZ_EXECUTABLE = YES;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment