Allow users to enable terminal cursor blinking with termux.properties

This `terminal-cursor-blink-rate` key can be used to enable terminal cursor blinking. The user can set an int value between `100` and `2000` which will be used as blink rate in millisecond. The default value is `0`, which disables cursor blinking. So adding an entry like `terminal-cursor-blink-rate=600` to `~/termux.properties` file will make the cursor attempt to blink every 600ms. Running `termux-reload-settings` command will also update the cursor blinking rate instantaneously if changed.

A background thread is used to control the blinking by toggling the cursor visibility and then invalidating the view every x milliseconds set. This will have a performance impact, so use wisely and at your own risk.

If the cursor itself is disabled, which is controlled by whether DECSET_BIT_CURSOR_ENABLED (DECSET 25, DECTCEM), then blinking will be automatically disabled. You can enable the cursor with `tput cnorm` or `echo -e '\e[?25h'` and disable it with `tput civis` or `echo -e '\e[?25l'`.

Note that you can also change the cursor color by adding `cursor` property to `~/colors.properties` file, like `cursor=#FFFFFF` for a white cursor.

The `TermuxPropertyConstants` class has been updated to `v0.9.0`. Check its Changelog sections for info on changes.

Closes #153
This commit is contained in:
agnostic-apollo
2021-05-15 16:35:54 +05:00
parent 11f5c0afd1
commit 31298b8857
11 changed files with 254 additions and 24 deletions

View File

@@ -257,6 +257,9 @@ public final class TermuxActivity extends Activity implements ServiceConnection
if (mIsInvalidState) return;
mTermuxTerminalViewClient.setSoftKeyboardState(true, false);
// Start terminal cursor blinking if enabled
mTermuxTerminalViewClient.setTerminalCursorBlinkerState(true);
}
/**
@@ -330,6 +333,9 @@ public final class TermuxActivity extends Activity implements ServiceConnection
// {@link #onStart} if needed.
mTermuxTerminalSessionClient.setCurrentStoredSession();
// Stop terminal cursor blinking if enabled
mTermuxTerminalViewClient.setTerminalCursorBlinkerState(false);
unregisterTermuxActivityBroadcastReceiever();
getDrawer().closeDrawers();
}
@@ -799,6 +805,9 @@ public final class TermuxActivity extends Activity implements ServiceConnection
mTermuxTerminalViewClient.setSoftKeyboardState(false, true);
mTermuxTerminalViewClient.setTerminalCursorBlinkerState(true);
// To change the activity and drawer theme, activity needs to be recreated.
// But this will destroy the activity, and will call the onCreate() again.
// We need to investigate if enabling this is wise, since all stored variables and

View File

@@ -137,6 +137,19 @@ public class TermuxTerminalSessionClient extends TermuxTerminalSessionClientBase
updateBackgroundColor();
}
@Override
public void onTerminalCursorStateChange(boolean enabled) {
// Do not start cursor blinking thread if activity is not visible
if (enabled && !mActivity.isVisible()) {
Logger.logVerbose(LOG_TAG, "Ignoring call to start cursor blinking since activity is not visible");
return;
}
// If cursor is to enabled now, then start cursor blinking if blinking is enabled
// otherwise stop cursor blinking
mActivity.getTerminalView().setTerminalCursorBlinkerState(enabled, false);
}
/** Try switching to session. */

View File

@@ -427,6 +427,18 @@ public class TermuxTerminalViewClient extends TermuxTerminalViewClientBase {
public void setTerminalCursorBlinkerState(boolean start) {
if (start) {
// Set/Update the cursor blinking rate
mActivity.getTerminalView().setTerminalCursorBlinkerRate(mActivity.getProperties().getTerminalCursorBlinkRate());
}
// Set the new state of cursor blinker
mActivity.getTerminalView().setTerminalCursorBlinkerState(start, true);
}
public void shareSessionTranscript() {
TerminalSession session = mActivity.getCurrentSession();
if (session == null) return;