这是indexloc提供的服务,不要输入任何密码
Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 11 additions & 11 deletions app/src/main/java/com/termux/app/TermuxActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@
import java.util.Arrays;
import java.util.Collections;
import java.util.LinkedHashSet;
import java.util.List;
import java.util.Properties;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
Expand Down Expand Up @@ -392,6 +393,11 @@ public void onSessionFinished(final TerminalSession finishedSession) {
mListViewAdapter.notifyDataSetChanged();
}

@Override
public void onSessionClosingItself(TerminalSession session) {
removeFinishedSession(session);
}

@Override
public void onClipboardText(TerminalSession session, String text) {
if (!mIsVisible) return;
Expand Down Expand Up @@ -855,20 +861,14 @@ void showToast(String text, boolean longDuration) {
}

public void removeFinishedSession(TerminalSession finishedSession) {
// Return pressed with finished session - remove it.
TermuxService service = mTermService;
int index = mTermService.removeTermSession(finishedSession);
List<TerminalSession> remainingSessions = mTermService.getSessions();

int index = service.removeTermSession(finishedSession);
mListViewAdapter.notifyDataSetChanged();
if (mTermService.getSessions().isEmpty()) {
// There are no sessions to show, so finish the activity.
if (remainingSessions.isEmpty())
finish();
} else {
if (index >= service.getSessions().size()) {
index = service.getSessions().size() - 1;
}
switchToSession(service.getSessions().get(index));
}
else
switchToSession(remainingSessions.get(Math.min(index, remainingSessions.size() - 1)));
}

}
6 changes: 6 additions & 0 deletions app/src/main/java/com/termux/app/TermuxService.java
Original file line number Diff line number Diff line change
Expand Up @@ -322,6 +322,12 @@ public void onSessionFinished(final TerminalSession finishedSession) {
mSessionChangeCallback.onSessionFinished(finishedSession);
}

@Override
public void onSessionClosingItself(TerminalSession session) {
if (mSessionChangeCallback != null)
mSessionChangeCallback.onSessionClosingItself(session);
}

@Override
public void onTextChanged(TerminalSession changedSession) {
if (mSessionChangeCallback != null) mSessionChangeCallback.onTextChanged(changedSession);
Expand Down
12 changes: 12 additions & 0 deletions app/src/main/java/com/termux/terminal/TerminalSession.java
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,8 @@ public interface SessionChangedCallback {

void onSessionFinished(TerminalSession finishedSession);

void onSessionClosingItself(TerminalSession session);

void onClipboardText(TerminalSession session, String text);

void onBell(TerminalSession session);
Expand Down Expand Up @@ -120,6 +122,16 @@ public void handleMessage(Message msg) {
cleanupResources(exitCode);
mChangeCallback.onSessionFinished(TerminalSession.this);

if (exitCode == -1 || exitCode == 129) {
// Process terminated with SIGHUP (signal 1), or exited with
// status 128+1 (= shell's last child terminated with SIGHUP).
// Scripts can use this to indicate that they want to close
// the session without waiting for the user to press Return.

mChangeCallback.onSessionClosingItself(TerminalSession.this);
return;
}

String exitDescription = "\r\n[Process completed";
if (exitCode > 0) {
// Non-zero process exit.
Expand Down