From 939338aaaca61802d0d09b18e3d914e7947bca9b Mon Sep 17 00:00:00 2001 From: agnostic-apollo Date: Tue, 6 Apr 2021 17:09:54 +0500 Subject: [PATCH] Allow users to report an issue from terminal transcript by selection "Report Issue" from context menu --- .../java/com/termux/app/TermuxActivity.java | 36 +++++++++---------- .../com/termux/app/models/UserAction.java | 3 +- .../termux/app/terminal/TermuxViewClient.java | 28 +++++++++++++++ .../com/termux/app/utils/TermuxUtils.java | 2 +- app/src/main/res/values/strings.xml | 1 + 5 files changed, 50 insertions(+), 20 deletions(-) diff --git a/app/src/main/java/com/termux/app/TermuxActivity.java b/app/src/main/java/com/termux/app/TermuxActivity.java index 5d872ee5..750bee55 100644 --- a/app/src/main/java/com/termux/app/TermuxActivity.java +++ b/app/src/main/java/com/termux/app/TermuxActivity.java @@ -135,15 +135,14 @@ public final class TermuxActivity extends Activity implements ServiceConnection private static final int CONTEXT_MENU_SELECT_URL_ID = 0; private static final int CONTEXT_MENU_SHARE_TRANSCRIPT_ID = 1; - private static final int CONTEXT_MENU_PASTE_ID = 3; + private static final int CONTEXT_MENU_AUTOFILL_ID = 2; + private static final int CONTEXT_MENU_RESET_TERMINAL_ID = 3; private static final int CONTEXT_MENU_KILL_PROCESS_ID = 4; - private static final int CONTEXT_MENU_RESET_TERMINAL_ID = 5; - private static final int CONTEXT_MENU_STYLING_ID = 6; - private static final int CONTEXT_MENU_HELP_ID = 8; - private static final int CONTEXT_MENU_TOGGLE_KEEP_SCREEN_ON = 9; - private static final int CONTEXT_MENU_AUTOFILL_ID = 10; - private static final int CONTEXT_MENU_SETTINGS_ID = 11; - + private static final int CONTEXT_MENU_STYLING_ID = 5; + private static final int CONTEXT_MENU_TOGGLE_KEEP_SCREEN_ON = 6; + private static final int CONTEXT_MENU_HELP_ID = 7; + private static final int CONTEXT_MENU_SETTINGS_ID = 8; + private static final int CONTEXT_MENU_REPORT_ID = 9; private static final int REQUESTCODE_PERMISSION_STORAGE = 1234; @@ -526,6 +525,7 @@ public final class TermuxActivity extends Activity implements ServiceConnection menu.add(Menu.NONE, CONTEXT_MENU_TOGGLE_KEEP_SCREEN_ON, Menu.NONE, R.string.action_toggle_keep_screen_on).setCheckable(true).setChecked(mPreferences.getKeepScreenOn()); menu.add(Menu.NONE, CONTEXT_MENU_HELP_ID, Menu.NONE, R.string.action_open_help); menu.add(Menu.NONE, CONTEXT_MENU_SETTINGS_ID, Menu.NONE, R.string.action_open_settings); + menu.add(Menu.NONE, CONTEXT_MENU_REPORT_ID, Menu.NONE, R.string.action_report_issue); } /** Hook system menu to show context menu instead. */ @@ -546,29 +546,29 @@ public final class TermuxActivity extends Activity implements ServiceConnection case CONTEXT_MENU_SHARE_TRANSCRIPT_ID: mTermuxViewClient.shareSessionTranscript(); return true; - case CONTEXT_MENU_PASTE_ID: - mTermuxViewClient.doPaste(); - return true; - case CONTEXT_MENU_KILL_PROCESS_ID: - showKillSessionDialog(session); + case CONTEXT_MENU_AUTOFILL_ID: + requestAutoFill(); return true; case CONTEXT_MENU_RESET_TERMINAL_ID: resetSession(session); return true; + case CONTEXT_MENU_KILL_PROCESS_ID: + showKillSessionDialog(session); + return true; case CONTEXT_MENU_STYLING_ID: showStylingDialog(); return true; + case CONTEXT_MENU_TOGGLE_KEEP_SCREEN_ON: + toggleKeepScreenOn(); + return true; case CONTEXT_MENU_HELP_ID: startActivity(new Intent(this, HelpActivity.class)); return true; case CONTEXT_MENU_SETTINGS_ID: startActivity(new Intent(this, SettingsActivity.class)); return true; - case CONTEXT_MENU_TOGGLE_KEEP_SCREEN_ON: - toggleKeepScreenOn(); - return true; - case CONTEXT_MENU_AUTOFILL_ID: - requestAutoFill(); + case CONTEXT_MENU_REPORT_ID: + mTermuxViewClient.reportIssueFromTranscript(); return true; default: return super.onContextItemSelected(item); diff --git a/app/src/main/java/com/termux/app/models/UserAction.java b/app/src/main/java/com/termux/app/models/UserAction.java index 9a27992f..ad56fbef 100644 --- a/app/src/main/java/com/termux/app/models/UserAction.java +++ b/app/src/main/java/com/termux/app/models/UserAction.java @@ -3,7 +3,8 @@ package com.termux.app.models; public enum UserAction { PLUGIN_EXECUTION_COMMAND("plugin execution command"), - CRASH_REPORT("crash report"); + CRASH_REPORT("crash report"), + REPORT_ISSUE_FROM_TRANSCRIPT("report issue from transcript"); private final String name; diff --git a/app/src/main/java/com/termux/app/terminal/TermuxViewClient.java b/app/src/main/java/com/termux/app/terminal/TermuxViewClient.java index 08f8ae7d..329e8f41 100644 --- a/app/src/main/java/com/termux/app/terminal/TermuxViewClient.java +++ b/app/src/main/java/com/termux/app/terminal/TermuxViewClient.java @@ -20,11 +20,17 @@ import android.widget.Toast; import com.termux.R; import com.termux.app.TermuxActivity; +import com.termux.app.TermuxConstants; +import com.termux.app.activities.ReportActivity; +import com.termux.app.models.ReportInfo; +import com.termux.app.models.UserAction; 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.DataUtils; import com.termux.app.utils.Logger; +import com.termux.app.utils.MarkdownUtils; +import com.termux.app.utils.TermuxUtils; import com.termux.terminal.KeyHandler; import com.termux.terminal.TerminalEmulator; import com.termux.terminal.TerminalSession; @@ -394,6 +400,28 @@ public class TermuxViewClient implements TerminalViewClient { dialog.show(); } + public void reportIssueFromTranscript() { + TerminalSession session = mActivity.getCurrentSession(); + if (session == null) return; + + String transcriptText = session.getEmulator().getScreen().getTranscriptTextWithoutJoinedLines().trim(); + if (transcriptText == null) return; + + transcriptText = DataUtils.getTruncatedCommandOutput(transcriptText, DataUtils.TRANSACTION_SIZE_LIMIT_IN_BYTES, false, true, false).trim(); + + StringBuilder reportString = new StringBuilder(); + + String title = TermuxConstants.TERMUX_APP_NAME + " Report Issue"; + + reportString.append("## Transcript\n"); + reportString.append("\n").append(MarkdownUtils.getMarkdownCodeForString(transcriptText, true)); + + reportString.append("\n\n").append(TermuxUtils.getAppInfoMarkdownString(mActivity, true)); + reportString.append("\n\n").append(TermuxUtils.getDeviceInfoMarkdownString(mActivity)); + + ReportActivity.startReportActivity(mActivity, new ReportInfo(UserAction.REPORT_ISSUE_FROM_TRANSCRIPT, TermuxConstants.TERMUX_APP.TERMUX_ACTIVITY_NAME, title, null, reportString.toString(), "\n\n" + TermuxUtils.getReportIssueMarkdownString(mActivity), false)); + } + public void doPaste() { TerminalSession session = mActivity.getCurrentSession(); if (session == null) return; diff --git a/app/src/main/java/com/termux/app/utils/TermuxUtils.java b/app/src/main/java/com/termux/app/utils/TermuxUtils.java index 79ead17a..acff15cb 100644 --- a/app/src/main/java/com/termux/app/utils/TermuxUtils.java +++ b/app/src/main/java/com/termux/app/utils/TermuxUtils.java @@ -250,7 +250,7 @@ public class TermuxUtils { StringBuilder markdownString = new StringBuilder(); - markdownString.append("## Report Issue"); + markdownString.append("## Where To Report An Issue"); markdownString.append("\n\n").append(context.getString(R.string.msg_report_issue)).append("\n"); diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index ca6a00ae..11b39d2c 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -72,6 +72,7 @@ Keep screen on Help Settings + Report Issue The &TERMUX_STYLING_APP_NAME; Plugin App is not installed. Install