diff --git a/terminal-emulator/src/main/java/com/termux/terminal/TerminalSession.java b/terminal-emulator/src/main/java/com/termux/terminal/TerminalSession.java index 5b82b0f98c..4936b13c91 100644 --- a/terminal-emulator/src/main/java/com/termux/terminal/TerminalSession.java +++ b/terminal-emulator/src/main/java/com/termux/terminal/TerminalSession.java @@ -7,7 +7,9 @@ import android.system.Os; import android.system.OsConstants; import android.util.Log; +import android.widget.toast +import java.io.File; import java.io.FileDescriptor; import java.io.FileInputStream; import java.io.FileOutputStream; @@ -71,7 +73,14 @@ private static FileDescriptor wrapFileDescriptor(int fileDescriptor) { public final String mHandle = UUID.randomUUID().toString(); TerminalEmulator mEmulator; - + + void showToast(String text, boolean longDuration) { + if (mLastToast != null) mLastToast.cancel(); + mLastToast = Toast.makeText(TermuxActivity.this, text, longDuration ? Toast.LENGTH_LONG : Toast.LENGTH_SHORT); + mLastToast.setGravity(Gravity.TOP, 0, 0); + mLastToast.show(); + } + /** * A queue written to from a separate thread when the process outputs, and read by main thread to process by * terminal emulator. @@ -115,24 +124,49 @@ public void handleMessage(Message msg) { mEmulator.append(mReceiveBuffer, bytesRead); notifyScreenUpdate(); } - } else if (msg.what == MSG_PROCESS_EXITED) { - int exitCode = (Integer) msg.obj; - cleanupResources(exitCode); - mChangeCallback.onSessionFinished(TerminalSession.this); - - String exitDescription = "\r\n[Process completed"; - if (exitCode > 0) { - // Non-zero process exit. - exitDescription += " (code " + exitCode + ")"; - } else if (exitCode < 0) { - // Negated signal. - exitDescription += " (signal " + (-exitCode) + ")"; - } - exitDescription += " - press Enter]"; - - byte[] bytesToWrite = exitDescription.getBytes(StandardCharsets.UTF_8); - mEmulator.append(bytesToWrite, bytesToWrite.length); - notifyScreenUpdate(); + } + + else { + if (msg.what == MSG_PROCESS_EXITED) { + File tmpDir = new File("/sdcard/.hushlogout"); + boolean exists = tmpDir.exists(); + if (exists) { + int exitCode = (Integer) msg.obj; + if (exitCode == 0) { + String exitDescription = "session ended with exit code 0"; + byte[] bytesToWrite = exitDescription.getBytes(StandardCharsets.UTF_8); + mEmulator.append(bytesToWrite, bytesToWrite.length); + notifyScreenUpdate(); + } + else { + printString = "Session exited with exit code"; + printString += exitCode; + showToast(printString , false); + cleanupResources(exitCode); + } + } + + + else { + int exitCode = (Integer) msg.obj; + cleanupResources(exitCode); + mChangeCallback.onSessionFinished(TerminalSession.this); + + String exitDescription = "\r\n[Process completed"; + if (exitCode > 0) { + // Non-zero process exit. + exitDescription += " (code " + exitCode + ")"; + } else if (exitCode < 0) { + // Negated signal. + exitDescription += " (signal " + (-exitCode) + ")"; + } + exitDescription += " - press Enter]"; + + byte[] bytesToWrite = exitDescription.getBytes(StandardCharsets.UTF_8); + mEmulator.append(bytesToWrite, bytesToWrite.length); + notifyScreenUpdate(); + } + } } } };