Created
December 31, 2012 13:08
-
-
Save saitoha/4419658 to your computer and use it in GitHub Desktop.
Support xterm's title stacking (iTerm2)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| diff --git a/PTYSession.h b/PTYSession.h | |
| index 1a24cfc..8c9caad 100644 | |
| --- a/PTYSession.h | |
| +++ b/PTYSession.h | |
| @@ -88,6 +88,12 @@ typedef enum { | |
| // The window title that should be used when this session is current. Otherwise defaultName | |
| // should be used. | |
| NSString* windowTitle; | |
| + | |
| + // The window title stack | |
| + NSMutableArray *windowTitleStack; | |
| + | |
| + // The tab title stack | |
| + NSMutableArray *tabTitleStack; | |
| // The original bookmark name. | |
| NSString* bookmarkName; | |
| @@ -399,6 +405,10 @@ typedef enum { | |
| - (NSString*)formattedName:(NSString*)base; | |
| - (NSString *)windowTitle; | |
| - (void)setWindowTitle: (NSString *)theTitle; | |
| +- (void)pushWindowTitle; | |
| +- (void)popWindowTitle; | |
| +- (void)pushTabTitle; | |
| +- (void)popTabTitle; | |
| - (PTYTask *)SHELL; | |
| - (void)setSHELL: (PTYTask *)theSHELL; | |
| - (VT100Terminal *)TERMINAL; | |
| diff --git a/PTYSession.m b/PTYSession.m | |
| index 384f4ff..42b99b7 100644 | |
| --- a/PTYSession.m | |
| +++ b/PTYSession.m | |
| @@ -112,7 +112,9 @@ static NSString *kTmuxFontChanged = @"kTmuxFontChanged"; | |
| savedScrollPosition_ = -1; | |
| updateTimer = nil; | |
| antiIdleTimer = nil; | |
| - addressBookEntry=nil; | |
| + addressBookEntry = nil; | |
| + windowTitleStack = nil; | |
| + tabTitleStack = nil; | |
| #if DEBUG_ALLOC | |
| NSLog(@"%s: 0x%x", __PRETTY_FUNCTION__, self); | |
| @@ -170,6 +172,12 @@ static NSString *kTmuxFontChanged = @"kTmuxFontChanged"; | |
| [COLORFGBG_VALUE release]; | |
| [name release]; | |
| [windowTitle release]; | |
| + if (windowTitleStack) { | |
| + [windowTitleStack release]; | |
| + } | |
| + if (tabTitleStack) { | |
| + [tabTitleStack release]; | |
| + } | |
| [addressBookEntry release]; | |
| [backgroundImagePath release]; | |
| [antiIdleTimer invalidate]; | |
| @@ -2532,6 +2540,54 @@ static NSString *kTmuxFontChanged = @"kTmuxFontChanged"; | |
| } | |
| } | |
| +- (void)pushWindowTitle | |
| +{ | |
| + if (!windowTitleStack) { | |
| + windowTitleStack = [[NSMutableArray alloc] init]; | |
| + } | |
| + NSString *title = windowTitle; | |
| + if (!title) { | |
| + title = @""; | |
| + } | |
| + [windowTitleStack addObject:title]; | |
| +} | |
| + | |
| +- (void)popWindowTitle | |
| +{ | |
| + if (!windowTitleStack) { | |
| + return; | |
| + } | |
| + NSUInteger count = [windowTitleStack count]; | |
| + if (count > 0) { | |
| + [self setWindowTitle:[windowTitleStack objectAtIndex:count - 1]]; | |
| + [windowTitleStack removeObjectAtIndex:count - 1]; | |
| + } | |
| +} | |
| + | |
| +- (void)pushTabTitle | |
| +{ | |
| + if (!tabTitleStack) { | |
| + tabTitleStack = [[NSMutableArray alloc] init]; | |
| + } | |
| + NSString *title = name; | |
| + if (!title) { | |
| + title = @""; | |
| + } | |
| + [tabTitleStack addObject:title]; | |
| +} | |
| + | |
| +- (void)popTabTitle | |
| +{ | |
| + if (!tabTitleStack) { | |
| + return; | |
| + } | |
| + NSUInteger count = [tabTitleStack count]; | |
| + if (count > 0) { | |
| + [self setName:[tabTitleStack objectAtIndex:count - 1]]; | |
| + [tabTitleStack removeObjectAtIndex:count - 1]; | |
| + } | |
| +} | |
| + | |
| - (PTYTask *)SHELL | |
| { | |
| return SHELL; | |
| diff --git a/VT100Screen.m b/VT100Screen.m | |
| index 14a79a5..1f00976 100644 | |
| --- a/VT100Screen.m | |
| +++ b/VT100Screen.m | |
| @@ -2383,6 +2383,37 @@ static BOOL XYIsBeforeXY(int px1, int py1, int px2, int py2) { | |
| [SESSION writeTask:theData]; | |
| break; | |
| } | |
| + case XTERMCC_PUSH_TITLE: { | |
| + switch (token.u.csi.p[1]) { | |
| + case 0: | |
| + [SESSION pushWindowTitle]; | |
| + [SESSION pushTabTitle]; | |
| + break; | |
| + case 1: | |
| + [SESSION pushTabTitle]; | |
| + break; | |
| + case 2: | |
| + [SESSION pushWindowTitle]; | |
| + break; | |
| + break; | |
| + } | |
| + break; | |
| + } | |
| + case XTERMCC_POP_TITLE: { | |
| + switch (token.u.csi.p[1]) { | |
| + case 0: | |
| + [SESSION popWindowTitle]; | |
| + [SESSION popTabTitle]; | |
| + break; | |
| + case 1: | |
| + [SESSION popTabTitle]; | |
| + break; | |
| + case 2: | |
| + [SESSION popWindowTitle]; | |
| + break; | |
| + } | |
| + break; | |
| + } | |
| // Our iTerm specific codes | |
| case ITERM_GROWL: | |
| if (GROWL) { | |
| diff --git a/VT100Terminal.h b/VT100Terminal.h | |
| index e83254d..044e9a5 100644 | |
| --- a/VT100Terminal.h | |
| +++ b/VT100Terminal.h | |
| @@ -127,11 +127,13 @@ | |
| #define XTERMCC_REPORT_SCREEN_SIZE 106 | |
| #define XTERMCC_REPORT_ICON_TITLE 107 | |
| #define XTERMCC_REPORT_WIN_TITLE 108 | |
| -#define XTERMCC_SET_RGB 109 | |
| -#define XTERMCC_PROPRIETARY_ETERM_EXT 110 | |
| -#define XTERMCC_SET_PALETTE 111 | |
| -#define XTERMCC_SET_KVP 112 | |
| -#define XTERMCC_PASTE64 113 | |
| +#define XTERMCC_PUSH_TITLE 109 | |
| +#define XTERMCC_POP_TITLE 110 | |
| +#define XTERMCC_SET_RGB 111 | |
| +#define XTERMCC_PROPRIETARY_ETERM_EXT 112 | |
| +#define XTERMCC_SET_PALETTE 113 | |
| +#define XTERMCC_SET_KVP 114 | |
| +#define XTERMCC_PASTE64 115 | |
| // Some ansi stuff | |
| #define ANSICSI_CHA 3000 // Cursor Horizontal Absolute | |
| diff --git a/VT100Terminal.m b/VT100Terminal.m | |
| index 7532cc3..f5db4b9 100644 | |
| --- a/VT100Terminal.m | |
| +++ b/VT100Terminal.m | |
| @@ -649,6 +649,14 @@ static VT100TCC decode_csi(unsigned char *datap, | |
| case 21: | |
| result.type = XTERMCC_REPORT_WIN_TITLE; | |
| break; | |
| + case 22: | |
| + result.type = XTERMCC_PUSH_TITLE; | |
| + SET_PARAM_DEFAULT(param, 0, 0); | |
| + break; | |
| + case 23: | |
| + result.type = XTERMCC_POP_TITLE; | |
| + SET_PARAM_DEFAULT(param, 0, 0); | |
| + break; | |
| default: | |
| result.type = VT100_NOTSUPPORT; | |
| break; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment