Skip to content

Commit

Permalink
Allow users to report an issue from terminal transcript by selection …
Browse files Browse the repository at this point in the history
…"Report Issue" from context menu
  • Loading branch information
agnostic-apollo committed Apr 6, 2021
1 parent 067709b commit 939338a
Show file tree
Hide file tree
Showing 5 changed files with 50 additions and 20 deletions.
36 changes: 18 additions & 18 deletions app/src/main/java/com/termux/app/TermuxActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -526,6 +525,7 @@ public void onCreateContextMenu(ContextMenu menu, View v, ContextMenuInfo menuIn
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. */
Expand All @@ -546,29 +546,29 @@ public boolean onContextItemSelected(MenuItem item) {
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);
Expand Down
3 changes: 2 additions & 1 deletion app/src/main/java/com/termux/app/models/UserAction.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@
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;

Expand Down
28 changes: 28 additions & 0 deletions app/src/main/java/com/termux/app/terminal/TermuxViewClient.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,17 @@

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;
Expand Down Expand Up @@ -394,6 +400,28 @@ public void showUrlSelection() {
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;
Expand Down
2 changes: 1 addition & 1 deletion app/src/main/java/com/termux/app/utils/TermuxUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -250,7 +250,7 @@ public static String getReportIssueMarkdownString(@NonNull final Context context

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");

Expand Down
1 change: 1 addition & 0 deletions app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@
<string name="action_toggle_keep_screen_on">Keep screen on</string>
<string name="action_open_help">Help</string>
<string name="action_open_settings">Settings</string>
<string name="action_report_issue">Report Issue</string>

<string name="error_styling_not_installed">The &TERMUX_STYLING_APP_NAME; Plugin App is not installed.</string>
<string name="action_styling_install">Install</string>
Expand Down

0 comments on commit 939338a

Please sign in to comment.