mirror of
https://github.com/fankes/termux-app.git
synced 2025-09-07 03:05:18 +08:00
@@ -245,9 +245,15 @@ public final class TermuxActivity extends Activity implements ServiceConnection
|
|||||||
editText.setOnEditorActionListener(new TextView.OnEditorActionListener() {
|
editText.setOnEditorActionListener(new TextView.OnEditorActionListener() {
|
||||||
@Override
|
@Override
|
||||||
public boolean onEditorAction(TextView v, int actionId, KeyEvent event) {
|
public boolean onEditorAction(TextView v, int actionId, KeyEvent event) {
|
||||||
String s = editText.getText().toString() + "\n";
|
TerminalSession session = getCurrentTermSession();
|
||||||
getCurrentTermSession().write(s);
|
if (session != null) {
|
||||||
|
if (session.isRunning()) {
|
||||||
|
session.write(editText.getText().toString() + "\n");
|
||||||
|
} else {
|
||||||
|
removeFinishedSession(session);
|
||||||
|
}
|
||||||
editText.setText("");
|
editText.setText("");
|
||||||
|
}
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
@@ -846,4 +852,21 @@ public final class TermuxActivity extends Activity implements ServiceConnection
|
|||||||
mLastToast.show();
|
mLastToast.show();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void removeFinishedSession(TerminalSession finishedSession) {
|
||||||
|
// Return pressed with finished session - remove it.
|
||||||
|
TermuxService service = mTermService;
|
||||||
|
|
||||||
|
int index = service.removeTermSession(finishedSession);
|
||||||
|
mListViewAdapter.notifyDataSetChanged();
|
||||||
|
if (mTermService.getSessions().isEmpty()) {
|
||||||
|
// There are no sessions to show, so finish the activity.
|
||||||
|
finish();
|
||||||
|
} else {
|
||||||
|
if (index >= service.getSessions().size()) {
|
||||||
|
index = service.getSessions().size() - 1;
|
||||||
|
}
|
||||||
|
switchToSession(service.getSessions().get(index));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@@ -55,31 +55,12 @@ public final class TermuxKeyListener implements TerminalKeyListener {
|
|||||||
mActivity.getDrawer().setDrawerLockMode(copyMode ? DrawerLayout.LOCK_MODE_LOCKED_CLOSED : DrawerLayout.LOCK_MODE_UNLOCKED);
|
mActivity.getDrawer().setDrawerLockMode(copyMode ? DrawerLayout.LOCK_MODE_LOCKED_CLOSED : DrawerLayout.LOCK_MODE_UNLOCKED);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void returnOnFinishedSession(TerminalSession currentSession) {
|
|
||||||
// Return pressed with finished session - remove it.
|
|
||||||
currentSession.finishIfRunning();
|
|
||||||
|
|
||||||
TermuxService service = mActivity.mTermService;
|
|
||||||
|
|
||||||
int index = service.removeTermSession(currentSession);
|
|
||||||
mActivity.mListViewAdapter.notifyDataSetChanged();
|
|
||||||
if (mActivity.mTermService.getSessions().isEmpty()) {
|
|
||||||
// There are no sessions to show, so finish the activity.
|
|
||||||
mActivity.finish();
|
|
||||||
} else {
|
|
||||||
if (index >= service.getSessions().size()) {
|
|
||||||
index = service.getSessions().size() - 1;
|
|
||||||
}
|
|
||||||
mActivity.switchToSession(service.getSessions().get(index));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean onKeyDown(int keyCode, KeyEvent e, TerminalSession currentSession) {
|
public boolean onKeyDown(int keyCode, KeyEvent e, TerminalSession currentSession) {
|
||||||
if (handleVirtualKeys(keyCode, e, true)) return true;
|
if (handleVirtualKeys(keyCode, e, true)) return true;
|
||||||
|
|
||||||
if (keyCode == KeyEvent.KEYCODE_ENTER && !currentSession.isRunning()) {
|
if (keyCode == KeyEvent.KEYCODE_ENTER && !currentSession.isRunning()) {
|
||||||
returnOnFinishedSession(currentSession);
|
mActivity.removeFinishedSession(currentSession);
|
||||||
return true;
|
return true;
|
||||||
} else if (e.isCtrlPressed() && e.isShiftPressed()) {
|
} else if (e.isCtrlPressed() && e.isShiftPressed()) {
|
||||||
// Get the unmodified code point:
|
// Get the unmodified code point:
|
||||||
@@ -244,7 +225,7 @@ public final class TermuxKeyListener implements TerminalKeyListener {
|
|||||||
return true;
|
return true;
|
||||||
} else if (ctrlDown) {
|
} else if (ctrlDown) {
|
||||||
if (codePoint == 106 /* Ctrl+j or \n */ && !session.isRunning()) {
|
if (codePoint == 106 /* Ctrl+j or \n */ && !session.isRunning()) {
|
||||||
returnOnFinishedSession(session);
|
mActivity.removeFinishedSession(session);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user