Skip to content

Commit

Permalink
Use new ios_switchSession to ensure consistent behaviour for each
Browse files Browse the repository at this point in the history
session
  • Loading branch information
N-Holzschuch committed Mar 25, 2018
1 parent 632c9df commit 70cc53e
Show file tree
Hide file tree
Showing 5 changed files with 16 additions and 3 deletions.
3 changes: 3 additions & 0 deletions Blink/TermController.m
Original file line number Diff line number Diff line change
Expand Up @@ -192,6 +192,7 @@ - (void)startSession

_session = [[MCPSession alloc] initWithStream:stream andParametes:_sessionParameters];
_session.delegate = self;
[_session setActiveSession];
[_session executeWithArgs:@""];
}

Expand Down Expand Up @@ -310,6 +311,7 @@ - (void)resume

- (void)focus {
[_termView focus];
[_session setActiveSession];
if (![_termView.window isKeyWindow]) {
[_termView.window makeKeyWindow];
}
Expand Down Expand Up @@ -339,6 +341,7 @@ - (void)attachInput:(TermInput *)termInput

if ([_termInput isFirstResponder]) {
[_termView focus];
[_session setActiveSession];
} else {
[_termView blur];
}
Expand Down
10 changes: 8 additions & 2 deletions Sessions/MCPSession.m
Original file line number Diff line number Diff line change
Expand Up @@ -365,7 +365,7 @@ - (int)main:(int)argc argv:(char **)argv args:(char *)args
[self setTitle]; // Temporary, until the apps restore the right state.
[self.stream.control setRawMode:NO];
}
ios_closeSession(_stream.out);
ios_closeSession(_stream.out);
[self out:"Bye!"];

return 0;
Expand Down Expand Up @@ -484,6 +484,7 @@ - (void)_runSystemCommandWithArgs:(NSString *)args
{
self.sessionParameters.childSessionParameters = nil;
[self.delegate indexCommand:args];
fprintf(stderr, "Inside MCPSession, session = %x stream = %x stdout = %x fileno = %x \n", (int) self, (int) _stream, (int)_stream.out, fileno(_stream.out));
_childSession = [[SystemSession alloc] initWithStream:_stream andParametes:self.sessionParameters.childSessionParameters];
self.sessionParameters.childSessionType = @"system";
[_childSession executeAttachedWithArgs:args];
Expand Down Expand Up @@ -565,7 +566,6 @@ - (char *)linenoise:(char *)prompt
return nil;
}

[[NSFileManager defaultManager] changeCurrentDirectoryPath:ios_currentDirectory(_stream.out)];
int count = linenoiseEdit(fileno(_stream.in), _stream.out, buf, MCP_MAX_LINE, prompt, _stream.sz);
if (count == -1) {
return nil;
Expand Down Expand Up @@ -607,4 +607,10 @@ - (BOOL)handleControl:(NSString *)control

return NO;
}

- (void)setActiveSession {
ios_switchSession((__bridge void*)self);
}


@end
1 change: 1 addition & 0 deletions Sessions/Session.h
Original file line number Diff line number Diff line change
Expand Up @@ -81,5 +81,6 @@ typedef struct SessionParams {
- (void)kill;
- (void)suspend;
- (BOOL)handleControl:(NSString *)control;
- (void)setActiveSession;

@end
2 changes: 2 additions & 0 deletions Sessions/Session.m
Original file line number Diff line number Diff line change
Expand Up @@ -184,5 +184,7 @@ - (BOOL)handleControl:(NSString *)control
return NO;
}

- (void)setActiveSession {
}

@end
3 changes: 2 additions & 1 deletion Sessions/SystemSession.m
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ - (int)main:(int)argc argv:(char **)argv args:(char *)args
stdin = _stream.in;
stdout = _stream.out;
stderr = stdout;
fprintf(stderr, "Launching ios_system, ession = %x stream = %x stdout = %x fileno = %x \n", (int) self, (int) _stream, (int)_stream.out, fileno(_stream.out));
int res = ios_system(args);
// get all output back:
stdout = saved_out;
Expand All @@ -44,7 +45,7 @@ - (int)main:(int)argc argv:(char **)argv args:(char *)args
- (BOOL)handleControl:(NSString *)control
{
if ([control isEqualToString:@"c"] || [control isEqualToString:@"d"]) {
ios_kill(_stream.out);
ios_kill();
return YES;
}

Expand Down

0 comments on commit 70cc53e

Please sign in to comment.