mirror of
https://github.com/fankes/termux-app.git
synced 2025-09-07 03:05:18 +08:00
Renamed TextDataUtils to DataUtils
This commit is contained in:
@@ -18,7 +18,7 @@ import com.termux.app.utils.FileUtils;
|
||||
import com.termux.app.utils.Logger;
|
||||
import com.termux.app.utils.NotificationUtils;
|
||||
import com.termux.app.utils.PluginUtils;
|
||||
import com.termux.app.utils.TextDataUtils;
|
||||
import com.termux.app.utils.DataUtils;
|
||||
import com.termux.app.models.ExecutionCommand;
|
||||
|
||||
/**
|
||||
@@ -319,7 +319,7 @@ public class RunCommandService extends Service {
|
||||
executionCommand.workingDirectory = intent.getStringExtra(RUN_COMMAND_SERVICE.EXTRA_WORKDIR);
|
||||
executionCommand.inBackground = intent.getBooleanExtra(RUN_COMMAND_SERVICE.EXTRA_BACKGROUND, false);
|
||||
executionCommand.sessionAction = intent.getStringExtra(RUN_COMMAND_SERVICE.EXTRA_SESSION_ACTION);
|
||||
executionCommand.commandLabel = TextDataUtils.getDefaultIfNull(intent.getStringExtra(RUN_COMMAND_SERVICE.EXTRA_COMMAND_LABEL), "RUN_COMMAND Execution Intent Command");
|
||||
executionCommand.commandLabel = DataUtils.getDefaultIfNull(intent.getStringExtra(RUN_COMMAND_SERVICE.EXTRA_COMMAND_LABEL), "RUN_COMMAND Execution Intent Command");
|
||||
executionCommand.commandDescription = intent.getStringExtra(RUN_COMMAND_SERVICE.EXTRA_COMMAND_DESCRIPTION);
|
||||
executionCommand.commandHelp = intent.getStringExtra(RUN_COMMAND_SERVICE.EXTRA_COMMAND_HELP);
|
||||
executionCommand.isPluginExecutionCommand = true;
|
||||
|
@@ -30,7 +30,7 @@ import com.termux.app.utils.Logger;
|
||||
import com.termux.app.utils.NotificationUtils;
|
||||
import com.termux.app.utils.PermissionUtils;
|
||||
import com.termux.app.utils.ShellUtils;
|
||||
import com.termux.app.utils.TextDataUtils;
|
||||
import com.termux.app.utils.DataUtils;
|
||||
import com.termux.app.models.ExecutionCommand;
|
||||
import com.termux.app.models.ExecutionCommand.ExecutionState;
|
||||
import com.termux.app.terminal.TermuxTask;
|
||||
@@ -323,7 +323,7 @@ public final class TermuxService extends Service {
|
||||
executionCommand.inBackground = intent.getBooleanExtra(TERMUX_SERVICE.EXTRA_BACKGROUND, false);
|
||||
executionCommand.isFailsafe = intent.getBooleanExtra(TERMUX_ACTIVITY.ACTION_FAILSAFE_SESSION, false);
|
||||
executionCommand.sessionAction = intent.getStringExtra(TERMUX_SERVICE.EXTRA_SESSION_ACTION);
|
||||
executionCommand.commandLabel = TextDataUtils.getDefaultIfNull(intent.getStringExtra(TERMUX_SERVICE.EXTRA_COMMAND_LABEL), "Execution Intent Command");
|
||||
executionCommand.commandLabel = DataUtils.getDefaultIfNull(intent.getStringExtra(TERMUX_SERVICE.EXTRA_COMMAND_LABEL), "Execution Intent Command");
|
||||
executionCommand.commandDescription = intent.getStringExtra(TERMUX_SERVICE.EXTRA_COMMAND_DESCRIPTION);
|
||||
executionCommand.commandHelp = intent.getStringExtra(TERMUX_SERVICE.EXTRA_COMMAND_HELP);
|
||||
executionCommand.pluginAPIHelp = intent.getStringExtra(TERMUX_SERVICE.EXTRA_PLUGIN_API_HELP);
|
||||
@@ -412,7 +412,7 @@ public final class TermuxService extends Service {
|
||||
TermuxSession newTermuxSession = createTermuxSession(executionCommand, sessionName);
|
||||
if (newTermuxSession == null) return;
|
||||
|
||||
handleSessionAction(TextDataUtils.getIntFromString(executionCommand.sessionAction,
|
||||
handleSessionAction(DataUtils.getIntFromString(executionCommand.sessionAction,
|
||||
TERMUX_SERVICE.VALUE_EXTRA_SESSION_ACTION_SWITCH_TO_NEW_SESSION_AND_OPEN_ACTIVITY),
|
||||
newTermuxSession.getTerminalSession());
|
||||
}
|
||||
|
@@ -9,7 +9,7 @@ import androidx.annotation.NonNull;
|
||||
import com.termux.app.TermuxConstants.TERMUX_APP.TERMUX_SERVICE;
|
||||
import com.termux.app.utils.Logger;
|
||||
import com.termux.app.utils.MarkdownUtils;
|
||||
import com.termux.app.utils.TextDataUtils;
|
||||
import com.termux.app.utils.DataUtils;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
@@ -296,7 +296,7 @@ public class ExecutionCommand {
|
||||
markdownString.append("\n").append(MarkdownUtils.getSingleLineMarkdownStringEntry("Exit Code", executionCommand.exitCode, "-"));
|
||||
|
||||
markdownString.append("\n\n").append(MarkdownUtils.getSingleLineMarkdownStringEntry("Err Code", executionCommand.errCode, "-"));
|
||||
markdownString.append("\n").append("**Errmsg:**\n").append(TextDataUtils.getDefaultIfNull(executionCommand.errmsg, "-"));
|
||||
markdownString.append("\n").append("**Errmsg:**\n").append(DataUtils.getDefaultIfNull(executionCommand.errmsg, "-"));
|
||||
markdownString.append("\n\n").append(executionCommand.geStackTracesMarkdownString());
|
||||
|
||||
if(executionCommand.commandDescription != null || executionCommand.commandHelp != null) {
|
||||
@@ -391,11 +391,11 @@ public class ExecutionCommand {
|
||||
}
|
||||
|
||||
public String getStdoutLogString() {
|
||||
return getMultiLineLogStringEntry("Stdout", TextDataUtils.getTruncatedCommandOutput(stdout, TextDataUtils.LOGGER_ENTRY_SIZE_LIMIT_IN_BYTES / 5, false, false, true), "-");
|
||||
return getMultiLineLogStringEntry("Stdout", DataUtils.getTruncatedCommandOutput(stdout, DataUtils.LOGGER_ENTRY_SIZE_LIMIT_IN_BYTES / 5, false, false, true), "-");
|
||||
}
|
||||
|
||||
public String getStderrLogString() {
|
||||
return getMultiLineLogStringEntry("Stderr", TextDataUtils.getTruncatedCommandOutput(stderr, TextDataUtils.LOGGER_ENTRY_SIZE_LIMIT_IN_BYTES / 5, false, false, true), "-");
|
||||
return getMultiLineLogStringEntry("Stderr", DataUtils.getTruncatedCommandOutput(stderr, DataUtils.LOGGER_ENTRY_SIZE_LIMIT_IN_BYTES / 5, false, false, true), "-");
|
||||
}
|
||||
|
||||
public String getExitCodeLogString() {
|
||||
@@ -476,7 +476,7 @@ public class ExecutionCommand {
|
||||
argumentsString.append("\n```\n");
|
||||
for (int i = 0; i != argumentsArray.length; i++) {
|
||||
argumentsString.append(getSingleLineLogStringEntry("Arg " + (i + 1),
|
||||
TextDataUtils.getTruncatedCommandOutput(argumentsArray[i], TextDataUtils.LOGGER_ENTRY_SIZE_LIMIT_IN_BYTES / 5, true, false, true),
|
||||
DataUtils.getTruncatedCommandOutput(argumentsArray[i], DataUtils.LOGGER_ENTRY_SIZE_LIMIT_IN_BYTES / 5, true, false, true),
|
||||
"-")).append("`\n");
|
||||
}
|
||||
argumentsString.append("```");
|
||||
|
@@ -7,7 +7,7 @@ import android.util.TypedValue;
|
||||
import com.termux.app.TermuxConstants;
|
||||
import com.termux.app.utils.Logger;
|
||||
import com.termux.app.utils.TermuxUtils;
|
||||
import com.termux.app.utils.TextDataUtils;
|
||||
import com.termux.app.utils.DataUtils;
|
||||
import com.termux.app.settings.preferences.TermuxPreferenceConstants.TERMUX_APP;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
@@ -26,7 +26,7 @@ public class TermuxAppSharedPreferences {
|
||||
|
||||
public TermuxAppSharedPreferences(@Nonnull Context context) {
|
||||
// We use the default context if failed to get termux package context
|
||||
mContext = TextDataUtils.getDefaultIfNull(TermuxUtils.getTermuxPackageContext(context), context);
|
||||
mContext = DataUtils.getDefaultIfNull(TermuxUtils.getTermuxPackageContext(context), context);
|
||||
mSharedPreferences = getPrivateSharedPreferences(mContext);
|
||||
|
||||
setFontVariables(context);
|
||||
@@ -93,7 +93,7 @@ public class TermuxAppSharedPreferences {
|
||||
|
||||
public int getFontSize() {
|
||||
int fontSize = SharedPreferenceUtils.getIntStoredAsString(mSharedPreferences, TERMUX_APP.KEY_FONTSIZE, DEFAULT_FONTSIZE);
|
||||
return TextDataUtils.clamp(fontSize, MIN_FONTSIZE, MAX_FONTSIZE);
|
||||
return DataUtils.clamp(fontSize, MIN_FONTSIZE, MAX_FONTSIZE);
|
||||
}
|
||||
|
||||
public void setFontSize(int value) {
|
||||
|
@@ -6,7 +6,7 @@ import android.content.res.Configuration;
|
||||
import com.termux.app.terminal.io.extrakeys.ExtraKeysInfo;
|
||||
import com.termux.app.terminal.io.KeyboardShortcut;
|
||||
import com.termux.app.utils.Logger;
|
||||
import com.termux.app.utils.TextDataUtils;
|
||||
import com.termux.app.utils.DataUtils;
|
||||
|
||||
import org.json.JSONException;
|
||||
|
||||
@@ -339,7 +339,7 @@ public class TermuxSharedProperties implements SharedPropertiesParser {
|
||||
* @return Returns the internal value for value.
|
||||
*/
|
||||
public static float getTerminalToolbarHeightScaleFactorInternalPropertyValueFromValue(String value) {
|
||||
return rangeTerminalToolbarHeightScaleFactorValue(TextDataUtils.getFloatFromString(value, TermuxPropertyConstants.DEFAULT_IVALUE_TERMINAL_TOOLBAR_HEIGHT_SCALE_FACTOR));
|
||||
return rangeTerminalToolbarHeightScaleFactorValue(DataUtils.getFloatFromString(value, TermuxPropertyConstants.DEFAULT_IVALUE_TERMINAL_TOOLBAR_HEIGHT_SCALE_FACTOR));
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -352,7 +352,7 @@ public class TermuxSharedProperties implements SharedPropertiesParser {
|
||||
* @return Returns the clamped value.
|
||||
*/
|
||||
public static float rangeTerminalToolbarHeightScaleFactorValue(float value) {
|
||||
return TextDataUtils.rangedOrDefault(value,
|
||||
return DataUtils.rangedOrDefault(value,
|
||||
TermuxPropertyConstants.DEFAULT_IVALUE_TERMINAL_TOOLBAR_HEIGHT_SCALE_FACTOR,
|
||||
TermuxPropertyConstants.IVALUE_TERMINAL_TOOLBAR_HEIGHT_SCALE_FACTOR_MIN,
|
||||
TermuxPropertyConstants.IVALUE_TERMINAL_TOOLBAR_HEIGHT_SCALE_FACTOR_MAX);
|
||||
|
@@ -23,7 +23,7 @@ import com.termux.app.TermuxActivity;
|
||||
import com.termux.app.terminal.io.KeyboardShortcut;
|
||||
import com.termux.app.terminal.io.extrakeys.ExtraKeysView;
|
||||
import com.termux.app.settings.properties.TermuxPropertyConstants;
|
||||
import com.termux.app.utils.TextDataUtils;
|
||||
import com.termux.app.utils.DataUtils;
|
||||
import com.termux.app.utils.Logger;
|
||||
import com.termux.terminal.KeyHandler;
|
||||
import com.termux.terminal.TerminalEmulator;
|
||||
@@ -342,7 +342,7 @@ public class TermuxViewClient implements TerminalViewClient {
|
||||
// See https://github.com/termux/termux-app/issues/1166.
|
||||
Intent intent = new Intent(Intent.ACTION_SEND);
|
||||
intent.setType("text/plain");
|
||||
transcriptText = TextDataUtils.getTruncatedCommandOutput(transcriptText, TextDataUtils.TRANSACTION_SIZE_LIMIT_IN_BYTES, false, true, false).trim();
|
||||
transcriptText = DataUtils.getTruncatedCommandOutput(transcriptText, DataUtils.TRANSACTION_SIZE_LIMIT_IN_BYTES, false, true, false).trim();
|
||||
intent.putExtra(Intent.EXTRA_TEXT, transcriptText);
|
||||
intent.putExtra(Intent.EXTRA_SUBJECT, mActivity.getString(R.string.title_share_transcript));
|
||||
mActivity.startActivity(Intent.createChooser(intent, mActivity.getString(R.string.title_share_transcript_with)));
|
||||
@@ -357,7 +357,7 @@ public class TermuxViewClient implements TerminalViewClient {
|
||||
|
||||
String text = session.getEmulator().getScreen().getTranscriptTextWithFullLinesJoined();
|
||||
|
||||
LinkedHashSet<CharSequence> urlSet = TextDataUtils.extractUrls(text);
|
||||
LinkedHashSet<CharSequence> urlSet = DataUtils.extractUrls(text);
|
||||
if (urlSet.isEmpty()) {
|
||||
new AlertDialog.Builder(mActivity).setMessage(R.string.title_select_url_none_found).show();
|
||||
return;
|
||||
|
@@ -6,7 +6,7 @@ import java.util.LinkedHashSet;
|
||||
import java.util.regex.Matcher;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
public class TextDataUtils {
|
||||
public class DataUtils {
|
||||
|
||||
public static final int TRANSACTION_SIZE_LIMIT_IN_BYTES = 100 * 1024; // 100KB
|
||||
public static final int LOGGER_ENTRY_SIZE_LIMIT_IN_BYTES = 4 * 1024; // 4KB
|
@@ -51,7 +51,7 @@ public class PluginUtils {
|
||||
public static void processPluginExecutionCommandResult(final Context context, String logTag, final ExecutionCommand executionCommand) {
|
||||
if (executionCommand == null) return;
|
||||
|
||||
logTag = TextDataUtils.getDefaultIfNull(logTag, LOG_TAG);
|
||||
logTag = DataUtils.getDefaultIfNull(logTag, LOG_TAG);
|
||||
|
||||
if(!executionCommand.hasExecuted()) {
|
||||
Logger.logWarn(logTag, "Ignoring call to processPluginExecutionCommandResult() since the execution command has not been ExecutionState.EXECUTED");
|
||||
@@ -109,7 +109,7 @@ public class PluginUtils {
|
||||
public static void processPluginExecutionCommandError(final Context context, String logTag, final ExecutionCommand executionCommand, boolean forceNotification) {
|
||||
if(context == null || executionCommand == null) return;
|
||||
|
||||
logTag = TextDataUtils.getDefaultIfNull(logTag, LOG_TAG);
|
||||
logTag = DataUtils.getDefaultIfNull(logTag, LOG_TAG);
|
||||
|
||||
if(!executionCommand.isStateFailed()) {
|
||||
Logger.logWarn(logTag, "Ignoring call to processPluginExecutionCommandError() since the execution command does not have ExecutionState.FAILED state");
|
||||
@@ -190,7 +190,7 @@ public class PluginUtils {
|
||||
public static boolean sendPluginExecutionCommandResultPendingIntent(Context context, String logTag, String label, String stdout, String stderr, Integer exitCode, Integer errCode, String errmsg, PendingIntent pluginPendingIntent) {
|
||||
if(context == null || pluginPendingIntent == null) return false;
|
||||
|
||||
logTag = TextDataUtils.getDefaultIfNull(logTag, LOG_TAG);
|
||||
logTag = DataUtils.getDefaultIfNull(logTag, LOG_TAG);
|
||||
|
||||
Logger.logDebug(logTag, "Sending execution result for Execution Command \"" + label + "\" to " + pluginPendingIntent.getCreatorPackage());
|
||||
|
||||
@@ -203,12 +203,12 @@ public class PluginUtils {
|
||||
|
||||
// Truncate stdout and stdout to max TRANSACTION_SIZE_LIMIT_IN_BYTES
|
||||
if(stderr == null || stderr.isEmpty()) {
|
||||
truncatedStdout = TextDataUtils.getTruncatedCommandOutput(stdout, TextDataUtils.TRANSACTION_SIZE_LIMIT_IN_BYTES, false, false, false);
|
||||
truncatedStdout = DataUtils.getTruncatedCommandOutput(stdout, DataUtils.TRANSACTION_SIZE_LIMIT_IN_BYTES, false, false, false);
|
||||
} else if (stdout == null || stdout.isEmpty()) {
|
||||
truncatedStderr = TextDataUtils.getTruncatedCommandOutput(stderr, TextDataUtils.TRANSACTION_SIZE_LIMIT_IN_BYTES, false, false, false);
|
||||
truncatedStderr = DataUtils.getTruncatedCommandOutput(stderr, DataUtils.TRANSACTION_SIZE_LIMIT_IN_BYTES, false, false, false);
|
||||
} else {
|
||||
truncatedStdout = TextDataUtils.getTruncatedCommandOutput(stdout, TextDataUtils.TRANSACTION_SIZE_LIMIT_IN_BYTES / 2, false, false, false);
|
||||
truncatedStderr = TextDataUtils.getTruncatedCommandOutput(stderr, TextDataUtils.TRANSACTION_SIZE_LIMIT_IN_BYTES / 2, false, false, false);
|
||||
truncatedStdout = DataUtils.getTruncatedCommandOutput(stdout, DataUtils.TRANSACTION_SIZE_LIMIT_IN_BYTES / 2, false, false, false);
|
||||
truncatedStderr = DataUtils.getTruncatedCommandOutput(stderr, DataUtils.TRANSACTION_SIZE_LIMIT_IN_BYTES / 2, false, false, false);
|
||||
}
|
||||
|
||||
if(truncatedStdout != null && truncatedStdout.length() < stdout.length()){
|
||||
@@ -225,7 +225,7 @@ public class PluginUtils {
|
||||
|
||||
// Truncate errmsg to max TRANSACTION_SIZE_LIMIT_IN_BYTES / 4
|
||||
// trim from end to preserve start of stacktraces
|
||||
truncatedErrmsg = TextDataUtils.getTruncatedCommandOutput(errmsg, TextDataUtils.TRANSACTION_SIZE_LIMIT_IN_BYTES / 4, true, false, false);
|
||||
truncatedErrmsg = DataUtils.getTruncatedCommandOutput(errmsg, DataUtils.TRANSACTION_SIZE_LIMIT_IN_BYTES / 4, true, false, false);
|
||||
if(truncatedErrmsg != null && truncatedErrmsg.length() < errmsg.length()){
|
||||
Logger.logWarn(logTag, "Execution Result for Execution Command \"" + label + "\" errmsg length truncated from " + errmsgOriginalLength + " to " + truncatedErrmsg.length());
|
||||
errmsg = truncatedErrmsg;
|
||||
|
@@ -1,6 +1,6 @@
|
||||
package com.termux.app;
|
||||
|
||||
import com.termux.app.utils.TextDataUtils;
|
||||
import com.termux.app.utils.DataUtils;
|
||||
|
||||
import org.junit.Assert;
|
||||
import org.junit.Test;
|
||||
@@ -13,7 +13,7 @@ public class TermuxActivityTest {
|
||||
private void assertUrlsAre(String text, String... urls) {
|
||||
LinkedHashSet<String> expected = new LinkedHashSet<>();
|
||||
Collections.addAll(expected, urls);
|
||||
Assert.assertEquals(expected, TextDataUtils.extractUrls(text));
|
||||
Assert.assertEquals(expected, DataUtils.extractUrls(text));
|
||||
}
|
||||
|
||||
@Test
|
||||
|
Reference in New Issue
Block a user