Skip to content

Commit

Permalink
MCP tweaks
Browse files Browse the repository at this point in the history
- Skip calls with empty command.
- Set AutoCR on ios_system commands.
- Improvements to close cmdStream sessions
  • Loading branch information
Carlos Cabanero committed Mar 29, 2024
1 parent a83ba49 commit 82ca6e7
Showing 1 changed file with 12 additions and 8 deletions.
20 changes: 12 additions & 8 deletions Sessions/MCPSession.m
Original file line number Diff line number Diff line change
Expand Up @@ -194,15 +194,12 @@ - (BOOL)_runCommand:(NSString *)cmdline skipHistoryRecord: (BOOL) skipHistoryRec
[self _runSSHWithArgs:cmdline];
} else if ([cmd isEqualToString:@"ssh-copy-id"]) {
[self _runSSHCopyIDWithArgs:cmdline];
} else {
} else if (![cmd isEqualToString:@""]) {
// Manually set raw mode for some commands, as we cannot receive control any other way.
[_device closeReadline];
if ([cmd isEqualToString:@"less"] || [cmd isEqualToString:@"vim"]) {
self.device.rawMode = true;
if ([cmd isEqualToString:@"less"]) {
// Less needs a different carriage return.
// This is part of the control by apps that we need to define manually.
self.device.autoCR = TRUE;
}
self.device.autoCR = TRUE;
}
[self setActiveSession];
_currentCmd = cmdline;
Expand All @@ -219,7 +216,8 @@ - (BOOL)_runCommand:(NSString *)cmdline skipHistoryRecord: (BOOL) skipHistoryRec
_currentCmd = nil;
ios_waitpid(_pid);
ios_releaseThreadId(_pid);

self.device.autoCR = FALSE;

fclose(tty);
tty = nil;
[_cmdStream close];
Expand Down Expand Up @@ -340,7 +338,7 @@ - (void)kill
return;
} else if (_childSession) {
[_childSession kill];
} else {
} else if (_cmdStream) {
[self setActiveSession];
ios_kill();
}
Expand Down Expand Up @@ -374,6 +372,11 @@ - (void)handleControl:(NSString *)control
if ([control isEqualToString:ctrlD]) {
// We give a chance to the session to capture the new stdin, as it may have changed.
[self setActiveSession];
if (_cmdStream != NULL) {
[_cmdStream close];
_cmdStream = NULL;
_cmdStream = [_device.stream duplicate];
}
ios_setStreams(_cmdStream.in, _cmdStream.out, _cmdStream.out);
return;
}
Expand All @@ -390,6 +393,7 @@ - (void)handleControl:(NSString *)control
[_tokioSignals signalCtrlC];
_tokioSignals = nil;
} else {
[self setActiveSession];
ios_kill();
}
}
Expand Down

0 comments on commit 82ca6e7

Please sign in to comment.