Skip to content

Commit

Permalink
Added: Add support for ~/.termux/termux.float.properties
Browse files Browse the repository at this point in the history
  • Loading branch information
agnostic-apollo committed Sep 2, 2021
1 parent 9f1203f commit bc779d2
Show file tree
Hide file tree
Showing 8 changed files with 66 additions and 20 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import com.termux.shared.logger.Logger;
import com.termux.shared.settings.properties.TermuxPropertyConstants;
import com.termux.shared.settings.properties.TermuxSharedProperties;
import com.termux.shared.termux.TermuxConstants;

import org.json.JSONException;

Expand All @@ -26,7 +27,8 @@ public class TermuxAppSharedProperties extends TermuxSharedProperties {
private static final String LOG_TAG = "TermuxAppSharedProperties";

public TermuxAppSharedProperties(@Nonnull Context context) {
super(context);
super(context, TermuxConstants.TERMUX_APP_NAME, TermuxPropertyConstants.getTermuxPropertiesFile(),
TermuxPropertyConstants.TERMUX_PROPERTIES_LIST, new SharedPropertiesParserClient());
}

/**
Expand Down Expand Up @@ -110,7 +112,8 @@ public ExtraKeysInfo getExtraKeysInfo() {
* Load the {@link TermuxPropertyConstants#KEY_TERMINAL_TRANSCRIPT_ROWS} value from termux properties file on disk.
*/
public static int getTerminalTranscriptRows(Context context) {
return (int) TermuxSharedProperties.getInternalPropertyValue(context, TermuxPropertyConstants.KEY_TERMINAL_TRANSCRIPT_ROWS);
return (int) TermuxSharedProperties.getInternalPropertyValue(context, TermuxPropertyConstants.getTermuxPropertiesFile(),
TermuxPropertyConstants.KEY_TERMINAL_TRANSCRIPT_ROWS, new SharedPropertiesParserClient());
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
import com.termux.shared.termux.TermuxConstants;
import com.termux.app.TermuxService;
import com.termux.shared.settings.properties.TermuxPropertyConstants;
import com.termux.app.terminal.io.BellHandler;
import com.termux.shared.terminal.io.BellHandler;
import com.termux.shared.logger.Logger;
import com.termux.terminal.TerminalColors;
import com.termux.terminal.TerminalSession;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ public void onReload() {
}

/**
* Should be called when {@link com.termux.view.TerminalView#mEmulator}
* Should be called when {@link com.termux.view.TerminalView#mEmulator} is set
*/
@Override
public void onEmulatorSet() {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package com.termux.shared.settings.properties;

import androidx.annotation.NonNull;

import com.google.common.collect.ImmutableBiMap;
import com.termux.shared.termux.TermuxConstants;
import com.termux.shared.logger.Logger;
Expand All @@ -12,7 +14,7 @@
import java.util.Set;

/*
* Version: v0.13.0
* Version: v0.14.0
*
* Changelog
*
Expand Down Expand Up @@ -58,6 +60,9 @@
*
* - 0.13.0 (2021-08-25)
* - Add `*KEY_TERMINAL_MARGIN_HORIZONTAL*` and `*KEY_TERMINAL_MARGIN_VERTICAL*`.
*
* - 0.14.0 (2021-09-02)
* - Add `getTermuxFloatPropertiesFile()`.
*/

/**
Expand Down Expand Up @@ -390,11 +395,28 @@ public final class TermuxPropertyConstants {
* @return Returns the {@link File} object for termux properties.
*/
public static File getTermuxPropertiesFile() {
String[] possiblePropertiesFileLocations = {
return getPropertiesFile(new String[]{
TermuxConstants.TERMUX_PROPERTIES_PRIMARY_FILE_PATH,
TermuxConstants.TERMUX_PROPERTIES_SECONDARY_FILE_PATH
};
});
}

/** Returns the first {@link File} found at
* {@link TermuxConstants#TERMUX_FLOAT_PROPERTIES_PRIMARY_FILE_PATH} or
* {@link TermuxConstants#TERMUX_FLOAT_PROPERTIES_SECONDARY_FILE_PATH}
* from which termux properties can be loaded.
* If the {@link File} found is not a regular file or is not readable then null is returned.
*
* @return Returns the {@link File} object for termux properties.
*/
public static File getTermuxFloatPropertiesFile() {
return getPropertiesFile(new String[]{
TermuxConstants.TERMUX_FLOAT_PROPERTIES_PRIMARY_FILE_PATH,
TermuxConstants.TERMUX_FLOAT_PROPERTIES_SECONDARY_FILE_PATH
});
}

public static File getPropertiesFile(@NonNull String[] possiblePropertiesFileLocations) {
File propertiesFile = new File(possiblePropertiesFileLocations[0]);
int i = 0;
while (!propertiesFile.exists() && i < possiblePropertiesFileLocations.length) {
Expand All @@ -405,7 +427,7 @@ public static File getTermuxPropertiesFile() {
if (propertiesFile.isFile() && propertiesFile.canRead()) {
return propertiesFile;
} else {
Logger.logDebug("No readable termux.properties file found");
Logger.logDebug("No readable properties file found at: " + Arrays.toString(possiblePropertiesFileLocations));
return null;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,28 +3,34 @@
import android.content.Context;
import android.content.res.Configuration;

import androidx.annotation.NonNull;

import com.termux.shared.logger.Logger;
import com.termux.shared.data.DataUtils;

import java.io.File;
import java.util.HashMap;
import java.util.Map;
import java.util.Properties;
import java.util.Set;

import javax.annotation.Nonnull;

public class TermuxSharedProperties {
public abstract class TermuxSharedProperties {

protected final Context mContext;
protected final SharedProperties mSharedProperties;
protected final String mLabel;
protected final File mPropertiesFile;
protected final SharedProperties mSharedProperties;

public static final String LOG_TAG = "TermuxSharedProperties";

public TermuxSharedProperties(@Nonnull Context context) {
public TermuxSharedProperties(@Nonnull Context context, @NonNull String label, File propertiesFile,
@NonNull Set<String> propertiesList, @NonNull SharedPropertiesParser sharedPropertiesParser) {
mContext = context;
mPropertiesFile = TermuxPropertyConstants.getTermuxPropertiesFile();
mSharedProperties = new SharedProperties(context, mPropertiesFile, TermuxPropertyConstants.TERMUX_PROPERTIES_LIST, new SharedPropertiesParserClient());
mLabel = label;
mPropertiesFile = propertiesFile;
mSharedProperties = new SharedProperties(context, mPropertiesFile, propertiesList, sharedPropertiesParser);
loadTermuxPropertiesFromDisk();
}

Expand Down Expand Up @@ -162,16 +168,17 @@ public Object getInternalPropertyValue(String key, boolean cached) {

/**
* Get the internal {@link Object} value for the key passed from the file returned by
* {@link TermuxPropertyConstants#getTermuxPropertiesFile()}. The {@link Properties} object is
* {@code propertiesFile}. The {@link Properties} object is
* read directly from the file and internal value is returned for the property value against the key.
*
* @param context The context for operations.
* @param key The key for which the internal object is required.
* @return Returns the {@link Object} object. This will be {@code null} if key is not found or
* the object stored against the key is {@code null}.
*/
public static Object getInternalPropertyValue(Context context, String key) {
return SharedProperties.getInternalProperty(context, TermuxPropertyConstants.getTermuxPropertiesFile(), key, new SharedPropertiesParserClient());
public static Object getInternalPropertyValue(Context context, File propertiesFile, String key,
@NonNull SharedPropertiesParser sharedPropertiesParser) {
return SharedProperties.getInternalProperty(context, propertiesFile, key, sharedPropertiesParser);
}

/**
Expand Down Expand Up @@ -588,7 +595,7 @@ public void dumpPropertiesToLog() {
Properties properties = getProperties(true);
StringBuilder propertiesDump = new StringBuilder();

propertiesDump.append("Termux Properties:");
propertiesDump.append(mLabel).append(" Termux Properties:");
if (properties != null) {
for (String key : properties.stringPropertyNames()) {
propertiesDump.append("\n").append(key).append(": `").append(properties.get(key)).append("`");
Expand All @@ -604,7 +611,7 @@ public void dumpInternalPropertiesToLog() {
HashMap<String, Object> internalProperties = (HashMap<String, Object>) getInternalProperties();
StringBuilder internalPropertiesDump = new StringBuilder();

internalPropertiesDump.append("Termux Internal Properties:");
internalPropertiesDump.append(mLabel).append(" Internal Properties:");
if (internalProperties != null) {
for (String key : internalProperties.keySet()) {
internalPropertiesDump.append("\n").append(key).append(": `").append(internalProperties.get(key)).append("`");
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.termux.app.terminal.io;
package com.termux.shared.terminal.io;

import android.content.Context;
import android.os.Build;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
import java.util.List;

/*
* Version: v0.27.0
* Version: v0.28.0
*
* Changelog
*
Expand Down Expand Up @@ -187,6 +187,9 @@
* `TERMUX_FLOAT_APP.TERMUX_FLOAT_SERVICE_NAME`.
* - Added following to `TERMUX_FLOAT_APP.TERMUX_FLOAT_SERVICE`:
* `ACTION_STOP_SERVICE`, `ACTION_SHOW`, `ACTION_HIDE`.
*
* - 0.28.0 (2021-09-02)
* - Added `TERMUX_FLOAT_PROPERTIES_PRIMARY_FILE*` and `TERMUX_FLOAT_PROPERTIES_SECONDARY_FILE*`.
*/

/**
Expand Down Expand Up @@ -640,6 +643,17 @@ public final class TermuxConstants {
public static final File TERMUX_PROPERTIES_SECONDARY_FILE = new File(TERMUX_PROPERTIES_SECONDARY_FILE_PATH);


/** Termux Float app termux.properties primary file path */
public static final String TERMUX_FLOAT_PROPERTIES_PRIMARY_FILE_PATH = TERMUX_DATA_HOME_DIR_PATH + "/termux.float.properties"; // Default: "/data/data/com.termux/files/home/.termux/termux.float.properties"
/** Termux Float app termux.properties primary file */
public static final File TERMUX_FLOAT_PROPERTIES_PRIMARY_FILE = new File(TERMUX_FLOAT_PROPERTIES_PRIMARY_FILE_PATH);

/** Termux Float app termux.properties secondary file path */
public static final String TERMUX_FLOAT_PROPERTIES_SECONDARY_FILE_PATH = TERMUX_CONFIG_HOME_DIR_PATH + "/termux.float.properties"; // Default: "/data/data/com.termux/files/home/.config/termux/termux.float.properties"
/** Termux Float app termux.properties secondary file */
public static final File TERMUX_FLOAT_PROPERTIES_SECONDARY_FILE = new File(TERMUX_FLOAT_PROPERTIES_SECONDARY_FILE_PATH);


/** Termux app and Termux:Styling colors.properties file path */
public static final String TERMUX_COLOR_PROPERTIES_FILE_PATH = TERMUX_DATA_HOME_DIR_PATH + "/colors.properties"; // Default: "/data/data/com.termux/files/home/.termux/colors.properties"
/** Termux app and Termux:Styling colors.properties file */
Expand Down
File renamed without changes.

0 comments on commit bc779d2

Please sign in to comment.