Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

added day night prefix to colour properties #4166

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<Object, Object> 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;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand Down