Improve: Session exit message
This commit is contained in:
@ -124,16 +124,7 @@ public class TerminalSession extends TerminalOutput {
|
||||
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]";
|
||||
|
||||
String exitDescription = getExitDescription(exitCode);
|
||||
byte[] bytesToWrite = exitDescription.getBytes(StandardCharsets.UTF_8);
|
||||
mEmulator.append(bytesToWrite, bytesToWrite.length);
|
||||
notifyScreenUpdate();
|
||||
@ -296,6 +287,19 @@ public class TerminalSession extends TerminalOutput {
|
||||
}
|
||||
}
|
||||
|
||||
protected String getExitDescription(int exitCode) {
|
||||
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]";
|
||||
return exitDescription;
|
||||
}
|
||||
|
||||
/** Cleanup resources when the process exits. */
|
||||
void cleanupResources(int exitStatus) {
|
||||
synchronized (this) {
|
||||
|
@ -3,10 +3,12 @@ package io.neoterm.frontend.floating
|
||||
import android.app.AlertDialog
|
||||
import android.content.Context
|
||||
import android.content.DialogInterface
|
||||
import io.neoterm.R
|
||||
import io.neoterm.backend.TerminalSession
|
||||
import io.neoterm.frontend.client.BasicSessionCallback
|
||||
import io.neoterm.frontend.client.BasicViewClient
|
||||
import io.neoterm.frontend.shell.ShellParameter
|
||||
import io.neoterm.frontend.shell.ShellTermSession
|
||||
import io.neoterm.utils.TerminalUtils
|
||||
|
||||
/**
|
||||
@ -55,6 +57,9 @@ class TerminalDialog(val context: Context) {
|
||||
.callback(terminalSessionCallback)
|
||||
.systemShell(false)
|
||||
terminalSession = TerminalUtils.createShellSession(context, parameter)
|
||||
if (terminalSession is ShellTermSession) {
|
||||
(terminalSession as ShellTermSession).exitPrompt = context.getString(R.string.process_exit_prompt_press_back)
|
||||
}
|
||||
termWindowView.attachSession(terminalSession)
|
||||
return this
|
||||
}
|
||||
|
@ -1,6 +1,7 @@
|
||||
package io.neoterm.frontend.shell
|
||||
|
||||
import android.content.Context
|
||||
import io.neoterm.App
|
||||
import io.neoterm.R
|
||||
import io.neoterm.backend.TerminalSession
|
||||
import io.neoterm.frontend.client.TermSessionCallback
|
||||
@ -13,12 +14,32 @@ import java.io.File
|
||||
*/
|
||||
open class ShellTermSession private constructor(shellPath: String, cwd: String, args: Array<String>, env: Array<String>, changeCallback: SessionChangedCallback) : TerminalSession(shellPath, cwd, args, env, changeCallback) {
|
||||
var initialCommand: String? = null
|
||||
var exitPrompt = App.get().getString(R.string.process_exit_prompt)
|
||||
|
||||
override fun initializeEmulator(columns: Int, rows: Int) {
|
||||
super.initializeEmulator(columns, rows)
|
||||
sendInitialCommand()
|
||||
}
|
||||
|
||||
override fun getExitDescription(exitCode: Int): String {
|
||||
val builder = StringBuilder("\r\n[")
|
||||
val context = App.get()
|
||||
builder.append(context.getString(R.string.process_exit_info))
|
||||
if (exitCode > 0) {
|
||||
// Non-zero process exit.
|
||||
builder.append(" (")
|
||||
builder.append(context.getString(R.string.process_exit_code, exitCode))
|
||||
builder.append(")")
|
||||
} else if (exitCode < 0) {
|
||||
// Negated signal.
|
||||
builder.append(" (")
|
||||
builder.append(context.getString(R.string.process_exit_signal, -exitCode))
|
||||
builder.append(")")
|
||||
}
|
||||
builder.append(" - $exitPrompt]")
|
||||
return builder.toString()
|
||||
}
|
||||
|
||||
private fun sendInitialCommand() {
|
||||
val initCommand = initialCommand
|
||||
if (initCommand != null && initCommand.isNotEmpty()) {
|
||||
|
@ -120,4 +120,9 @@
|
||||
<string name="new_color_scheme">新建配色方案</string>
|
||||
<string name="faq">常见问题</string>
|
||||
<string name="new_source">新建</string>
|
||||
<string name="process_exit_info">进程已结束</string>
|
||||
<string name="process_exit_code">状态 %d</string>
|
||||
<string name="process_exit_signal">信号 %d</string>
|
||||
<string name="process_exit_prompt">按回车关闭</string>
|
||||
<string name="process_exit_prompt_press_back">按返回关闭</string>
|
||||
</resources>
|
@ -120,6 +120,11 @@
|
||||
<string name="new_color_scheme">New Color Scheme</string>
|
||||
<string name="faq">FAQ</string>
|
||||
<string name="new_source">New</string>
|
||||
<string name="process_exit_info">Process completed</string>
|
||||
<string name="process_exit_code">code %d</string>
|
||||
<string name="process_exit_signal">signal %d</string>
|
||||
<string name="process_exit_prompt">press Enter</string>
|
||||
<string name="process_exit_prompt_press_back">Press Back</string>
|
||||
|
||||
<string-array name="pref_general_shell_entries" translatable="false">
|
||||
<item>sh</item>
|
||||
|
Reference in New Issue
Block a user