Skip to content

Commit

Permalink
Initial attempt
Browse files Browse the repository at this point in the history
  • Loading branch information
gnachman committed Feb 25, 2013
1 parent 35ac7ae commit ec5a9f4
Show file tree
Hide file tree
Showing 18 changed files with 213 additions and 377 deletions.
1 change: 0 additions & 1 deletion NSStringITerm.h
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,6 @@

+ (NSString *)stringWithInt:(int)num;
+ (BOOL)isDoubleWidthCharacter:(int)unicode
encoding:(NSStringEncoding)e
ambiguousIsDoubleWidth:(BOOL)ambiguousIsDoubleWidth;

- (NSMutableString *)stringReplaceSubstringFrom:(NSString *)oldSubstring to:(NSString *)newSubstring;
Expand Down
1 change: 0 additions & 1 deletion NSStringITerm.m
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,6 @@ + (NSString *)stringWithInt:(int)num
}

+ (BOOL)isDoubleWidthCharacter:(int)unicode
encoding:(NSStringEncoding)e
ambiguousIsDoubleWidth:(BOOL)ambiguousIsDoubleWidth
{
if (unicode <= 0xa0 ||
Expand Down
3 changes: 3 additions & 0 deletions PTYSession.m
Original file line number Diff line number Diff line change
Expand Up @@ -2942,6 +2942,7 @@ - (BOOL)doubleWidth
- (void)setDoubleWidth:(BOOL)set
{
doubleWidth = set;
tmuxController_.ambiguousIsDoubleWidth = set;
}

- (BOOL)xtermMouseReporting
Expand Down Expand Up @@ -3692,6 +3693,7 @@ - (void)startTmuxMode
tmuxMode_ = TMUX_GATEWAY;
tmuxGateway_ = [[TmuxGateway alloc] initWithDelegate:self];
tmuxController_ = [[TmuxController alloc] initWithGateway:tmuxGateway_];
tmuxController_.ambiguousIsDoubleWidth = doubleWidth;
NSSize theSize;
Profile *tmuxBookmark = [PTYTab tmuxBookmark];
theSize.width = MAX(1, [[tmuxBookmark objectForKey:KEY_COLUMNS] intValue]);
Expand All @@ -3710,6 +3712,7 @@ - (void)startTmuxMode
if ([[PreferencePanel sharedInstance] autoHideTmuxClientSession]) {
[self hideSession];
}
tmuxLogging_ = YES; // TODOXXXXXXXXXXXXX

[tmuxGateway_ readTask:[TERMINAL streamData]];
[TERMINAL clearStream];
Expand Down
2 changes: 0 additions & 2 deletions PTYTextView.m
Original file line number Diff line number Diff line change
Expand Up @@ -6736,7 +6736,6 @@ - (int)inputMethodEditorLength
fg,
bg,
&len,
0,
[[dataSource session] doubleWidth],
NULL);

Expand Down Expand Up @@ -6782,7 +6781,6 @@ - (BOOL)drawInputMethodEditorTextAt:(int)xStart
fg,
bg,
&len,
0,
[[dataSource session] doubleWidth],
&cursorIndex);
int cursorX = 0;
Expand Down
1 change: 1 addition & 0 deletions TmuxController.h
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ extern NSString *kTmuxControllerAttachedSessionDidChange;
@property (nonatomic, retain) NSMutableDictionary *windowPositions;
@property (nonatomic, copy) NSString *sessionName;
@property (nonatomic, retain) NSArray *sessions;
@property (nonatomic, assign) BOOL ambiguousIsDoubleWidth;

- (id)initWithGateway:(TmuxGateway *)gateway;
- (void)openWindowsInitial;
Expand Down
87 changes: 55 additions & 32 deletions TmuxController.m
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ @implementation TmuxController
@synthesize windowPositions = windowPositions_;
@synthesize sessionName = sessionName_;
@synthesize sessions = sessions_;
@synthesize ambiguousIsDoubleWidth = ambiguousIsDoubleWidth_;

- (id)initWithGateway:(TmuxGateway *)gateway
{
Expand Down Expand Up @@ -103,6 +104,7 @@ - (void)openWindowWithIndex:(int)windowIndex
}
[pendingWindowOpens_ addObject:n];
TmuxWindowOpener *windowOpener = [TmuxWindowOpener windowOpener];
windowOpener.ambiguousIsDoubleWidth = ambiguousIsDoubleWidth_;
windowOpener.windowIndex = windowIndex;
windowOpener.name = name;
windowOpener.size = size;
Expand All @@ -127,6 +129,7 @@ - (void)setLayoutInTab:(PTYTab *)tab
toLayout:(NSString *)layout
{
TmuxWindowOpener *windowOpener = [TmuxWindowOpener windowOpener];
windowOpener.ambiguousIsDoubleWidth = ambiguousIsDoubleWidth_;
windowOpener.layout = layout;
windowOpener.maxHistory =
MAX([[gateway_ delegate] tmuxBookmarkSize].height,
Expand Down Expand Up @@ -240,39 +243,44 @@ - (void)initialListWindowsResponse:(NSString *)response
- (void)openWindowsInitial
{
NSSize size = [[gateway_ delegate] tmuxBookmarkSize];
NSString *setSizeCommand = [NSString stringWithFormat:@"control set-client-size %d,%d",
NSString *setSizeCommand = [NSString stringWithFormat:@"control-helper set-client-size %d,%d",
(int)size.width, (int)size.height];
NSString *listWindowsCommand = [NSString stringWithFormat:@"list-windows -F %@", kListWindowsFormat];
NSString *listSessionsCommand = @"list-sessions -F \"#{session_name}\"";
NSString *getAffinitiesCommand = [NSString stringWithFormat:@"control get-value affinities%d", sessionId_];
NSString *getOriginsCommand = [NSString stringWithFormat:@"control get-value origins%d", sessionId_];
NSString *getHiddenWindowsCommand =
[NSString stringWithFormat:@"control get-value hidden%d", sessionId_];
NSString *getAffinitiesCommand = [NSString stringWithFormat:@"show -v -t %d @affinities", sessionId_];
NSString *getOriginsCommand = [NSString stringWithFormat:@"show -v -t %d @origins", sessionId_];
NSString *getHiddenWindowsCommand = [NSString stringWithFormat:@"show -v -t %d @hidden", sessionId_];
NSArray *commands = [NSArray arrayWithObjects:
[gateway_ dictionaryForCommand:setSizeCommand
responseTarget:nil
responseSelector:nil
responseObject:nil],
responseObject:nil
toleratesErrors:NO],
[gateway_ dictionaryForCommand:getHiddenWindowsCommand
responseTarget:self
responseSelector:@selector(getHiddenWindowsResponse:)
responseObject:nil],
responseObject:nil
toleratesErrors:YES],
[gateway_ dictionaryForCommand:getAffinitiesCommand
responseTarget:self
responseSelector:@selector(getAffinitiesResponse:)
responseObject:nil],
responseObject:nil
toleratesErrors:YES],
[gateway_ dictionaryForCommand:getOriginsCommand
responseTarget:self
responseSelector:@selector(getOriginsResponse:)
responseObject:nil],
responseObject:nil
toleratesErrors:YES],
[gateway_ dictionaryForCommand:listSessionsCommand
responseTarget:self
responseSelector:@selector(listSessionsResponse:)
responseObject:nil],
responseObject:nil
toleratesErrors:NO],
[gateway_ dictionaryForCommand:listWindowsCommand
responseTarget:self
responseSelector:@selector(initialListWindowsResponse:)
responseObject:nil],
responseObject:nil
toleratesErrors:NO],
nil];
[gateway_ sendCommandList:commands];
}
Expand Down Expand Up @@ -366,12 +374,22 @@ - (void)setClientSize:(NSSize)size
{
assert(size.width > 0 && size.height > 0);
lastSize_ = size;
NSString *listStr = [NSString stringWithFormat:@"list-windows -F \"#{window_id} #{window_layout}\""];
NSArray *commands = [NSArray arrayWithObjects:
[gateway_ dictionaryForCommand:[NSString stringWithFormat:@"control-helper set-client-size %d,%d",
(int)size.width, (int)size.height]
responseTarget:nil
responseSelector:nil
responseObject:nil
toleratesErrors:NO],
[gateway_ dictionaryForCommand:listStr
responseTarget:self
responseSelector:@selector(listWindowsResponse:)
responseObject:nil
toleratesErrors:NO],
nil];
++numOutstandingWindowResizes_;
[gateway_ sendCommand:[NSString stringWithFormat:@"control set-client-size %d,%d",
(int)size.width, (int)size.height]
responseTarget:self
responseSelector:@selector(clientSizeChangeResponse:)
responseObject:nil];
[gateway_ sendCommandList:commands];
}

- (BOOL)hasOutstandingWindowResize
Expand Down Expand Up @@ -404,11 +422,13 @@ - (void)windowPane:(int)wp
[gateway_ dictionaryForCommand:resizeStr
responseTarget:nil
responseSelector:nil
responseObject:nil],
responseObject:nil
toleratesErrors:NO],
[gateway_ dictionaryForCommand:listStr
responseTarget:self
responseSelector:@selector(clientSizeChangeResponse:)
responseObject:nil],
responseSelector:@selector(listWindowsResponse:)
responseObject:nil
toleratesErrors:NO],
nil];
++numOutstandingWindowResizes_;
[gateway_ sendCommandList:commands];
Expand Down Expand Up @@ -438,12 +458,14 @@ - (void)newWindowWithAffinity:(int)windowId
[gateway_ sendCommand:@"new-window -PF '#{window_id}'"
responseTarget:self
responseSelector:@selector(newWindowWithAffinityCreated:affinityWindow:)
responseObject:[NSString stringWithInt:windowId]];
responseObject:[NSString stringWithInt:windowId]
toleratesErrors:NO];
} else {
[gateway_ sendCommand:@"new-window -PF '#{window_id}'"
responseTarget:self
responseSelector:@selector(newWindowWithoutAffinityCreated:)
responseObject:nil];
responseObject:nil
toleratesErrors:NO];
}
}

Expand Down Expand Up @@ -503,7 +525,8 @@ - (void)breakOutWindowPane:(int)windowPane toTabAside:(NSString *)sibling
[gateway_ sendCommand:[NSString stringWithFormat:@"break-pane -P -F \"#{window_id}\" -t %%%d", windowPane]
responseTarget:self
responseSelector:@selector(windowPaneBrokeOutWithWindowId:setAffinityTo:)
responseObject:sibling];
responseObject:sibling
toleratesErrors:NO];
}

- (void)windowPaneBrokeOutWithWindowId:(NSString *)windowId
Expand Down Expand Up @@ -542,7 +565,8 @@ - (void)openWindowWithId:(int)windowId
responseSelector:@selector(listedWindowsToOpenOne:forWindowIdAndAffinities:)
responseObject:[NSArray arrayWithObjects:[NSNumber numberWithInt:windowId],
affinities,
nil]];
nil]
toleratesErrors:NO];
}

- (void)openWindowWithId:(int)windowId
Expand Down Expand Up @@ -622,19 +646,21 @@ - (void)listWindowsInSession:(NSString *)sessionName
responseObject:[NSArray arrayWithObjects:object,
NSStringFromSelector(selector),
target,
nil]];
nil]
toleratesErrors:NO];
}

- (void)saveHiddenWindows
{
NSString *hidden = [[hiddenWindows_ allObjects] componentsJoinedByString:@","];
NSString *command = [NSString stringWithFormat:
@"control set-value hidden%d=%@",
@"set -t %d @hidden% \"%@\"",
sessionId_, hidden];
[gateway_ sendCommand:command
responseTarget:nil
responseSelector:nil
responseObject:nil];
responseObject:nil
toleratesErrors:NO];
}

- (void)saveWindowOrigins
Expand Down Expand Up @@ -671,7 +697,7 @@ - (void)saveWindowOrigins
}
}
NSString *enc = [maps componentsJoinedByString:@" "];
NSString *command = [NSString stringWithFormat:@"control set-value \"origins%d=%@\"",
NSString *command = [NSString stringWithFormat:@"set -t %d @origins \"%@\"",
sessionId_, [enc stringByEscapingQuotes]];
if (!lastOrigins_ || ![command isEqualToString:lastOrigins_]) {
[lastOrigins_ release];
Expand Down Expand Up @@ -716,7 +742,7 @@ - (void)saveAffinities
}
}
NSString *arg = [affinities componentsJoinedByString:@" "];
NSString *command = [NSString stringWithFormat:@"control set-value \"affinities%d=%@\"",
NSString *command = [NSString stringWithFormat:@"set -t %d @affinities \"%@\"",
sessionId_, [arg stringByEscapingQuotes]];
if ([command isEqualToString:lastSaveAffinityCommand_]) {
return;
Expand Down Expand Up @@ -787,9 +813,6 @@ - (void)didListWindows:(NSString *)response userData:(NSArray *)userData

- (void)getHiddenWindowsResponse:(NSString *)response
{
if (response.length == 0) {
return;
}
NSArray *windowIds = [response componentsSeparatedByString:@","];
[hiddenWindows_ removeAllObjects];
NSLog(@"getHiddneWindowsResponse: Add these window IDS to hidden: %@", windowIds);
Expand Down Expand Up @@ -886,7 +909,7 @@ - (void)listedWindowsToOpenOne:(NSString *)response forWindowIdAndAffinities:(NS
// When an iTerm2 window is resized, a control -s client-size w,h
// command is sent. It responds with new layouts for all the windows in the
// client's session. Update the layouts for the affected tabs.
- (void)clientSizeChangeResponse:(NSString *)response
- (void)listWindowsResponse:(NSString *)response
{
--numOutstandingWindowResizes_;
if (numOutstandingWindowResizes_ > 0) {
Expand Down
15 changes: 12 additions & 3 deletions TmuxGateway.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@

@class TmuxController;

extern NSString * const kTmuxGatewayErrorDomain;

@protocol TmuxGatewayDelegate

- (TmuxController *)tmuxController;
Expand Down Expand Up @@ -63,8 +65,14 @@ typedef enum {

// Returns any unconsumed data if tmux mode is exited.
- (NSData *)readTask:(NSData *)data;
- (void)sendCommand:(NSString *)command responseTarget:(id)target responseSelector:(SEL)selector;
- (void)sendCommand:(NSString *)command responseTarget:(id)target responseSelector:(SEL)selector responseObject:(id)obj;
- (void)sendCommand:(NSString *)command
responseTarget:(id)target
responseSelector:(SEL)selector;
- (void)sendCommand:(NSString *)command
responseTarget:(id)target
responseSelector:(SEL)selector
responseObject:(id)obj
toleratesErrors:(BOOL)toleratesErrors;
- (void)sendCommandList:(NSArray *)commandDicts;
// Set initial to YES when notifications should be accepted after the last
// command gets a response.
Expand All @@ -75,7 +83,8 @@ typedef enum {
- (NSDictionary *)dictionaryForCommand:(NSString *)command
responseTarget:(id)target
responseSelector:(SEL)selector
responseObject:(id)obj;
responseObject:(id)obj
toleratesErrors:(BOOL)toleratesErrors;

- (void)sendKeys:(NSData *)data toWindowPane:(int)windowPane;
- (void)detach;
Expand Down
Loading

0 comments on commit ec5a9f4

Please sign in to comment.