From 232363e387da36d8132d17ffc575ab894af04c30 Mon Sep 17 00:00:00 2001 From: Christopher Speck Date: Tue, 13 Jul 2021 22:13:27 -0400 Subject: [PATCH] Display informative message when arc launches an editor Summary: Update `PhutilInteractiveEditor` to allow specifying a "task message" which will be displayed just prior to launching the user's editor. Refs T3271 Test Plan: I ran several `arc diff` commands in varying states to invoke my editor and verified that it printed out the text indicating that my editor was being launched. Reviewers: epriestley, #blessed_reviewers Reviewed By: epriestley, #blessed_reviewers Subscribers: Korvin Maniphest Tasks: T3271 Differential Revision: https://secure.phabricator.com/D21700 --- src/console/PhutilInteractiveEditor.php | 43 ++++++++++++++++++++++++- src/workflow/ArcanistDiffWorkflow.php | 6 ++++ src/workflow/ArcanistPatchWorkflow.php | 2 ++ src/workflow/ArcanistWorkflow.php | 3 ++ 4 files changed, 53 insertions(+), 1 deletion(-) diff --git a/src/console/PhutilInteractiveEditor.php b/src/console/PhutilInteractiveEditor.php index 3db79cc3..3e12611c 100644 --- a/src/console/PhutilInteractiveEditor.php +++ b/src/console/PhutilInteractiveEditor.php @@ -22,6 +22,7 @@ final class PhutilInteractiveEditor extends Phobject { private $offset = 0; private $preferred; private $fallback; + private $taskMessage; /* -( Creating a New Editor )---------------------------------------------- */ @@ -74,6 +75,20 @@ final class PhutilInteractiveEditor extends Phobject { $editor = $this->getEditor(); $offset = $this->getLineOffset(); + $binary = basename($editor); + + // This message is primarily an assistance to users with GUI-based + // editors configured. Users with terminal-based editors won't have a + // chance to see this prior to the editor being launched. + echo tsprintf( + "%s\n", + pht('Launching editor "%s"...', $binary)); + + $task_message = $this->getTaskMessage(); + if ($task_message !== null) { + echo tsprintf("%s\n", $task_message); + } + $err = $this->invokeEditor($editor, $path, $offset); if ($err) { @@ -85,7 +100,6 @@ final class PhutilInteractiveEditor extends Phobject { 'vim' => true, ); - $binary = basename($editor); if (isset($vi_binaries[$binary])) { // This runs "Q" (an invalid command), then "q" (a valid command, // meaning "quit"). Vim binaries with behavior that makes them poor @@ -266,6 +280,33 @@ final class PhutilInteractiveEditor extends Phobject { return $this; } + /** + * Set the message that identifies the task for which the editor is being + * launched, displayed to the user prior to it being launched. + * + * @param string The message to display to the user. + * @return $this + * + * @task config + */ + public function setTaskMessage($task_message) { + $this->taskMessage = $task_message; + return $this; + } + + /** + * Retrieve the current message that will display to the user just prior to + * invoking the editor. + * + * @return string The message that will display to the user, or null if no + * message will be displayed. + * + * @task config + */ + public function getTaskMessage() { + return $this->taskMessage; + } + /** * Get the name of the editor program to use. The value of the environmental diff --git a/src/workflow/ArcanistDiffWorkflow.php b/src/workflow/ArcanistDiffWorkflow.php index f0b48acf..38aa4b62 100644 --- a/src/workflow/ArcanistDiffWorkflow.php +++ b/src/workflow/ArcanistDiffWorkflow.php @@ -674,6 +674,8 @@ EOTEXT if ($should_edit) { $edited = $this->newInteractiveEditor($remote_corpus) ->setName('differential-edit-revision-info') + ->setTaskMessage(pht( + 'Update the details for a revision, then save and exit.')) ->editInteractively(); if ($edited != $remote_corpus) { $remote_corpus = $edited; @@ -1476,6 +1478,8 @@ EOTEXT } else { $new_template = $this->newInteractiveEditor($template) ->setName('new-commit') + ->setTaskMessage(pht( + 'Provide the details for a new revision, then save and exit.')) ->editInteractively(); } $first = false; @@ -1752,6 +1756,8 @@ EOTEXT $comments = $this->newInteractiveEditor($template) ->setName('differential-update-comments') + ->setTaskMessage(pht( + 'Update the revision comments, then save and exit.')) ->editInteractively(); return $comments; diff --git a/src/workflow/ArcanistPatchWorkflow.php b/src/workflow/ArcanistPatchWorkflow.php index b7938b3c..bb733702 100644 --- a/src/workflow/ArcanistPatchWorkflow.php +++ b/src/workflow/ArcanistPatchWorkflow.php @@ -909,6 +909,8 @@ EOTEXT $commit_message = $this->newInteractiveEditor($template) ->setName('arcanist-patch-commit-message') + ->setTaskMessage(pht( + 'Supply a commit message for this patch, then save and exit.')) ->editInteractively(); $commit_message = ArcanistCommentRemover::removeComments($commit_message); diff --git a/src/workflow/ArcanistWorkflow.php b/src/workflow/ArcanistWorkflow.php index 9d6adb91..08362db2 100644 --- a/src/workflow/ArcanistWorkflow.php +++ b/src/workflow/ArcanistWorkflow.php @@ -1234,6 +1234,9 @@ abstract class ArcanistWorkflow extends Phobject { $commit_message = $this->newInteractiveEditor($template) ->setName(pht('commit-message')) + ->setTaskMessage(pht( + 'Supply commit message for uncommitted changes, then save and '. + 'exit.')) ->editInteractively(); if ($commit_message === $template) {