Added: Add `SCROLL` extra key to toggle auto scrolling of terminal to bottom on terminal text updates and termux activity return

The toggle will apply to each terminal session separately.

Closes #2535
This commit is contained in:
agnostic-apollo 2022-06-18 06:58:44 +05:00
parent a2df7d791a
commit 5fc2b4cd4a
4 changed files with 30 additions and 3 deletions

View File

@ -96,6 +96,10 @@ public class TermuxTerminalExtraKeys extends TerminalExtraKeys {
} else if ("PASTE".equals(key)) {
if(mTermuxTerminalSessionActivityClient != null)
mTermuxTerminalSessionActivityClient.onPasteTextFromClipboard(null);
} else if ("SCROLL".equals(key)) {
TerminalView terminalView = mTermuxTerminalViewClient.getActivity().getTerminalView();
if (terminalView != null && terminalView.mEmulator != null)
terminalView.mEmulator.toggleAutoScrollDisabled();
} else {
super.onTerminalExtraKeyButtonClick(view, key, ctrlDown, altDown, shiftDown, fnDown);
}

View File

@ -252,6 +252,9 @@ public final class TerminalEmulator {
*/
private int mScrollCounter = 0;
/** If automatic scrolling of terminal is disabled */
private boolean mAutoScrollDisabled;
private byte mUtf8ToFollow, mUtf8Index;
private final byte[] mUtf8InputBuffer = new byte[4];
private int mLastEmittedCodePoint = -1;
@ -2412,6 +2415,15 @@ public final class TerminalEmulator {
mScrollCounter = 0;
}
public boolean isAutoScrollDisabled() {
return mAutoScrollDisabled;
}
public void toggleAutoScrollDisabled() {
mAutoScrollDisabled = !mAutoScrollDisabled;
}
/** Reset terminal state so user can interact with it regardless of present state. */
public void reset() {
setCursorStyle();

View File

@ -409,19 +409,29 @@ public final class TerminalView extends View {
}
public void onScreenUpdated() {
onScreenUpdated(false);
}
public void onScreenUpdated(boolean skipScrolling) {
if (mEmulator == null) return;
int rowsInHistory = mEmulator.getScreen().getActiveTranscriptRows();
if (mTopRow < -rowsInHistory) mTopRow = -rowsInHistory;
boolean skipScrolling = false;
if (isSelectingText()) {
if (isSelectingText() || mEmulator.isAutoScrollDisabled()) {
// Do not scroll when selecting text.
int rowShift = mEmulator.getScrollCounter();
if (-mTopRow + rowShift > rowsInHistory) {
// .. unless we're hitting the end of history transcript, in which
// case we abort text selection and scroll to end.
stopTextSelectionMode();
if (isSelectingText())
stopTextSelectionMode();
if (mEmulator.isAutoScrollDisabled()) {
mTopRow = -rowsInHistory;
skipScrolling = true;
}
} else {
skipScrolling = true;
mTopRow -= rowShift;

View File

@ -90,6 +90,7 @@ public class ExtraKeysConstants {
put("DRAWER", ""); // U+2630 TRIGRAM FOR HEAVEN not well known but easy to understand
put("KEYBOARD", ""); // U+2328 KEYBOARD not well known but easy to understand
put("PASTE", ""); // U+2398
put("SCROLL", ""); // U+21F3
}};
public static final ExtraKeyDisplayMap LESS_KNOWN_CHARACTERS_DISPLAY = new ExtraKeyDisplayMap() {{