Skip to content

Commit 13cd444

Browse files
john-petersonSimplyTheBest
authored andcommitted
🔥 merge pull request termux#4166
1 parent 6b9310c commit 13cd444

File tree

4 files changed

+29
-5
lines changed

4 files changed

+29
-5
lines changed

app/src/main/java/com/termux/app/terminal/TermuxSessionsListViewController.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@
1919
import com.termux.R;
2020
import com.termux.app.TermuxActivity;
2121
import com.termux.shared.termux.shell.command.runner.terminal.TermuxSession;
22-
import com.termux.shared.theme.NightMode;
2322
import com.termux.shared.theme.ThemeUtils;
2423
import com.termux.terminal.TerminalSession;
2524
import java.util.List;
@@ -52,7 +51,7 @@ public View getView(int position, View convertView, @NonNull ViewGroup parent) {
5251
sessionTitleView.setText("null session");
5352
return sessionRowView;
5453
}
55-
boolean shouldEnableDarkTheme = ThemeUtils.shouldEnableDarkTheme(mActivity, NightMode.getAppNightMode().getName());
54+
boolean shouldEnableDarkTheme = ThemeUtils.shouldEnableDarkTheme(mActivity);
5655
String name = sessionAtRow.mSessionName;
5756
String sessionTitle = sessionAtRow.getTitle();
5857
String numberPart = "[" + (position + 1) + "] ";

app/src/main/java/com/termux/app/terminal/TermuxTerminalSessionActivityClient.java

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
import com.termux.app.TermuxService;
2626
import com.termux.shared.termux.settings.properties.TermuxPropertyConstants;
2727
import com.termux.shared.termux.terminal.io.BellHandler;
28+
import com.termux.shared.theme.ThemeUtils;
2829
import com.termux.shared.logger.Logger;
2930
import com.termux.terminal.TerminalColors;
3031
import com.termux.terminal.TerminalSession;
@@ -293,6 +294,7 @@ public void setCurrentSession(TerminalSession session) {
293294
if (mActivity.getTerminalView().attachSession(session)) {
294295
// notify about switched session if not already displaying the session
295296
notifyOfSessionChange();
297+
checkForFontAndColors();
296298
}
297299
// We call the following even when the session is already being displayed since config may
298300
// be stale, like current session not selected or scrolled to.
@@ -497,7 +499,8 @@ public void checkForFontAndColors() {
497499
props.load(in);
498500
}
499501
}
500-
TerminalColors.COLOR_SCHEME.updateWith(props);
502+
503+
TerminalColors.COLOR_SCHEME.updateWith(props, !ThemeUtils.shouldEnableDarkTheme(mActivity));
501504
TerminalSession session = mActivity.getCurrentSession();
502505
if (session != null && session.getEmulator() != null) {
503506
session.getEmulator().mColors.reset();

terminal-emulator/src/main/java/com/termux/terminal/TerminalColorScheme.java

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,11 +47,32 @@ private void reset() {
4747
System.arraycopy(DEFAULT_COLORSCHEME, 0, mDefaultColors, 0, TextStyle.NUM_INDEXED_COLORS);
4848
}
4949

50-
public void updateWith(Properties props) {
50+
void logEx(Exception e) {
51+
throw new IllegalArgumentException(e.toString()+e.getMessage());
52+
}
53+
54+
public void updateWith(Properties props, boolean isDay) {
5155
reset();
5256
boolean cursorPropExists = false;
5357
for (Map.Entry<Object, Object> entries : props.entrySet()) {
5458
String key = (String) entries.getKey();
59+
60+
try {
61+
if (key.contains(".")) {
62+
String[] parts = key.split("\\.");
63+
String prefix = parts[0];
64+
boolean useDay = isDay && prefix.equals("day");
65+
boolean useNight = !isDay && prefix.equals("night");
66+
67+
if (useDay || useNight)
68+
key = parts[1];
69+
else
70+
continue;
71+
}
72+
} catch (Exception e) {
73+
logEx(e);
74+
}
75+
5576
String value = (String) entries.getValue();
5677
int colorIndex;
5778
if (key.equals("foreground")) {

termux-shared/src/main/java/com/termux/shared/theme/ThemeUtils.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,8 @@ public static boolean isNightModeEnabled(Context context) {
3030
* Will return true if mode is set to {@link NightMode#TRUE}, otherwise will return true if
3131
* mode is set to {@link NightMode#SYSTEM} and night mode is enabled by system.
3232
*/
33-
public static boolean shouldEnableDarkTheme(Context context, String name) {
33+
public static boolean shouldEnableDarkTheme(Context context) {
34+
String name = NightMode.getAppNightMode().getName();
3435
if (NightMode.TRUE.getName().equals(name))
3536
return true;
3637
else if (NightMode.FALSE.getName().equals(name))

0 commit comments

Comments
 (0)