Skip to content

Commit

Permalink
feat: Don't allow go back until the session is running
Browse files Browse the repository at this point in the history
  • Loading branch information
SyntaxGalaxy committed Oct 10, 2023
1 parent 2f27509 commit 6aee153
Showing 1 changed file with 18 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
import android.view.View;
import android.view.Window;
import android.view.WindowManager;
import androidx.annotation.MainThread;
import com.blankj.utilcode.util.KeyboardUtils;
import com.termux.terminal.TerminalEmulator;
import com.termux.terminal.TerminalSession;
Expand All @@ -38,6 +39,7 @@ public class TerminalActivity extends BaseActivity

private ActivityTerminalBinding binding;
private String cwd;
private TerminalSession session;

@Override
protected void onCreate(Bundle savedInstanceState) {
Expand All @@ -59,14 +61,15 @@ protected void onCreate(Bundle savedInstanceState) {
binding.terminalView.setTextSize(28);
String[] env = {};
String[] argsList = {};
binding.terminalView.attachSession(
session =
new TerminalSession(
"/system/bin/sh",
cwd,
env,
argsList,
TerminalEmulator.DEFAULT_TERMINAL_CURSOR_STYLE,
this));
this);
binding.terminalView.attachSession(session);
binding.terminalView.setTerminalViewClient(this);
}

Expand Down Expand Up @@ -106,6 +109,11 @@ public void copyModeChanged(boolean copyMode) {}

@Override
public boolean onKeyDown(int keyCode, KeyEvent e, TerminalSession session) {
if (!session.isRunning()) {
if (e.getKeyCode() == KeyEvent.KEYCODE_ENTER) {
finish();
}
}
return false;
}

Expand Down Expand Up @@ -180,4 +188,12 @@ public Integer getTerminalCursorStyle() {

@Override
public void onClipboardText(TerminalSession arg0, String arg1) {}

@Override
@MainThread
public void onBackPressed() {
if (!session.isRunning()) {
super.onBackPressed();
}
}
}

0 comments on commit 6aee153

Please sign in to comment.