From 2ff5956901c9732f8c14cbde826ed5d5bdd33e0f Mon Sep 17 00:00:00 2001 From: John Sebastian Peterson Date: Mon, 23 Sep 2024 13:14:50 +0300 Subject: [PATCH 1/2] remove redundant argument --- .../termux/app/terminal/TermuxSessionsListViewController.java | 3 +-- .../src/main/java/com/termux/shared/theme/ThemeUtils.java | 3 ++- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/app/src/main/java/com/termux/app/terminal/TermuxSessionsListViewController.java b/app/src/main/java/com/termux/app/terminal/TermuxSessionsListViewController.java index bf914b977b..615edeace0 100644 --- a/app/src/main/java/com/termux/app/terminal/TermuxSessionsListViewController.java +++ b/app/src/main/java/com/termux/app/terminal/TermuxSessionsListViewController.java @@ -21,7 +21,6 @@ import com.termux.R; import com.termux.app.TermuxActivity; import com.termux.shared.termux.shell.command.runner.terminal.TermuxSession; -import com.termux.shared.theme.NightMode; import com.termux.shared.theme.ThemeUtils; import com.termux.terminal.TerminalSession; @@ -57,7 +56,7 @@ public View getView(int position, View convertView, @NonNull ViewGroup parent) { return sessionRowView; } - boolean shouldEnableDarkTheme = ThemeUtils.shouldEnableDarkTheme(mActivity, NightMode.getAppNightMode().getName()); + boolean shouldEnableDarkTheme = ThemeUtils.shouldEnableDarkTheme(mActivity); if (shouldEnableDarkTheme) { sessionTitleView.setBackground( diff --git a/termux-shared/src/main/java/com/termux/shared/theme/ThemeUtils.java b/termux-shared/src/main/java/com/termux/shared/theme/ThemeUtils.java index 2b652026fb..352f42411e 100644 --- a/termux-shared/src/main/java/com/termux/shared/theme/ThemeUtils.java +++ b/termux-shared/src/main/java/com/termux/shared/theme/ThemeUtils.java @@ -26,7 +26,8 @@ public static boolean isNightModeEnabled(Context context) { /** Will return true if mode is set to {@link NightMode#TRUE}, otherwise will return true if * mode is set to {@link NightMode#SYSTEM} and night mode is enabled by system. */ - public static boolean shouldEnableDarkTheme(Context context, String name) { + public static boolean shouldEnableDarkTheme(Context context) { + String name = NightMode.getAppNightMode().getName(); if (NightMode.TRUE.getName().equals(name)) return true; else if (NightMode.FALSE.getName().equals(name)) From 972789ac473a08b291636a3443dab041f3a3c858 Mon Sep 17 00:00:00 2001 From: John Sebastian Peterson Date: Mon, 23 Sep 2024 12:49:23 +0300 Subject: [PATCH 2/2] added day night prefix to colour properties --- .../TermuxTerminalSessionActivityClient.java | 4 +++- .../termux/terminal/TerminalColorScheme.java | 20 ++++++++++++++++++- 2 files changed, 22 insertions(+), 2 deletions(-) diff --git a/app/src/main/java/com/termux/app/terminal/TermuxTerminalSessionActivityClient.java b/app/src/main/java/com/termux/app/terminal/TermuxTerminalSessionActivityClient.java index cd38163116..e55fcef5f4 100644 --- a/app/src/main/java/com/termux/app/terminal/TermuxTerminalSessionActivityClient.java +++ b/app/src/main/java/com/termux/app/terminal/TermuxTerminalSessionActivityClient.java @@ -26,6 +26,7 @@ import com.termux.app.TermuxService; import com.termux.shared.termux.settings.properties.TermuxPropertyConstants; import com.termux.shared.termux.terminal.io.BellHandler; +import com.termux.shared.theme.ThemeUtils; import com.termux.shared.logger.Logger; import com.termux.terminal.TerminalColors; import com.termux.terminal.TerminalSession; @@ -296,6 +297,7 @@ public void setCurrentSession(TerminalSession session) { if (mActivity.getTerminalView().attachSession(session)) { // notify about switched session if not already displaying the session notifyOfSessionChange(); + checkForFontAndColors(); } // We call the following even when the session is already being displayed since config may @@ -503,7 +505,7 @@ public void checkForFontAndColors() { } } - TerminalColors.COLOR_SCHEME.updateWith(props); + TerminalColors.COLOR_SCHEME.updateWith(props, !ThemeUtils.shouldEnableDarkTheme(mActivity)); TerminalSession session = mActivity.getCurrentSession(); if (session != null && session.getEmulator() != null) { session.getEmulator().mColors.reset(); diff --git a/terminal-emulator/src/main/java/com/termux/terminal/TerminalColorScheme.java b/terminal-emulator/src/main/java/com/termux/terminal/TerminalColorScheme.java index 4088781805..57d75885c0 100644 --- a/terminal-emulator/src/main/java/com/termux/terminal/TerminalColorScheme.java +++ b/terminal-emulator/src/main/java/com/termux/terminal/TerminalColorScheme.java @@ -69,11 +69,29 @@ private void reset() { System.arraycopy(DEFAULT_COLORSCHEME, 0, mDefaultColors, 0, TextStyle.NUM_INDEXED_COLORS); } - public void updateWith(Properties props) { + void logEx(Exception e) { + throw new IllegalArgumentException(e.toString()+e.getMessage()); + } + + public void updateWith(Properties props, boolean isDay) { reset(); boolean cursorPropExists = false; for (Map.Entry entries : props.entrySet()) { String key = (String) entries.getKey(); + +try { + if (key.contains(".")) { + String prefix = key.split("\\.")[0]; + boolean useDay = isDay && prefix.equals("day"); + boolean useNight = !isDay && prefix.equals("night"); + + if (useDay || useNight) + key = key.split("\\.")[1]; + else + continue; + } +} catch (Exception e) { logEx(e); } + String value = (String) entries.getValue(); int colorIndex;