Skip to content

Commit c19e01f

Browse files
Changed!: Do not wait for the user to press enter for failed terminal session commands if plugin expects the result back
1 parent 9ffcd21 commit c19e01f

File tree

1 file changed

+16
-4
lines changed

1 file changed

+16
-4
lines changed

app/src/main/java/com/termux/app/terminal/TermuxTerminalSessionClient.java

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -138,24 +138,36 @@ public void onSessionFinished(final TerminalSession finishedSession) {
138138
return;
139139
}
140140

141+
int index = service.getIndexOfSession(finishedSession);
142+
143+
// For plugin commands that expect the result back, we should immediately close the session
144+
// and send the result back instead of waiting fo the user to press enter.
145+
// The plugin can handle/show errors itself.
146+
boolean isPluginExecutionCommandWithPendingResult = false;
147+
TermuxSession termuxSession = service.getTermuxSession(index);
148+
if (termuxSession != null) {
149+
isPluginExecutionCommandWithPendingResult = termuxSession.getExecutionCommand().isPluginExecutionCommandWithPendingResult();
150+
if (isPluginExecutionCommandWithPendingResult)
151+
Logger.logVerbose(LOG_TAG, "The \"" + finishedSession.mSessionName + "\" session will be force finished automatically since result in pending.");
152+
}
153+
141154
if (mActivity.isVisible() && finishedSession != mActivity.getCurrentSession()) {
142155
// Show toast for non-current sessions that exit.
143-
int indexOfSession = service.getIndexOfSession(finishedSession);
144156
// Verify that session was not removed before we got told about it finishing:
145-
if (indexOfSession >= 0)
157+
if (index >= 0)
146158
mActivity.showToast(toToastTitle(finishedSession) + " - exited", true);
147159
}
148160

149161
if (mActivity.getPackageManager().hasSystemFeature(PackageManager.FEATURE_LEANBACK)) {
150162
// On Android TV devices we need to use older behaviour because we may
151163
// not be able to have multiple launcher icons.
152-
if (service.getTermuxSessionsSize() > 1) {
164+
if (service.getTermuxSessionsSize() > 1 || isPluginExecutionCommandWithPendingResult) {
153165
removeFinishedSession(finishedSession);
154166
}
155167
} else {
156168
// Once we have a separate launcher icon for the failsafe session, it
157169
// should be safe to auto-close session on exit code '0' or '130'.
158-
if (finishedSession.getExitStatus() == 0 || finishedSession.getExitStatus() == 130) {
170+
if (finishedSession.getExitStatus() == 0 || finishedSession.getExitStatus() == 130 || isPluginExecutionCommandWithPendingResult) {
159171
removeFinishedSession(finishedSession);
160172
}
161173
}

0 commit comments

Comments
 (0)