1
0
Fork 0
mirror of https://we.phorge.it/source/arcanist.git synced 2024-11-10 00:42:40 +01:00

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
This commit is contained in:
Christopher Speck 2021-07-13 22:13:27 -04:00 committed by Christopher Speck
parent 41f6c6ecb2
commit 232363e387
4 changed files with 53 additions and 1 deletions

View file

@ -22,6 +22,7 @@ final class PhutilInteractiveEditor extends Phobject {
private $offset = 0; private $offset = 0;
private $preferred; private $preferred;
private $fallback; private $fallback;
private $taskMessage;
/* -( Creating a New Editor )---------------------------------------------- */ /* -( Creating a New Editor )---------------------------------------------- */
@ -74,6 +75,20 @@ final class PhutilInteractiveEditor extends Phobject {
$editor = $this->getEditor(); $editor = $this->getEditor();
$offset = $this->getLineOffset(); $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); $err = $this->invokeEditor($editor, $path, $offset);
if ($err) { if ($err) {
@ -85,7 +100,6 @@ final class PhutilInteractiveEditor extends Phobject {
'vim' => true, 'vim' => true,
); );
$binary = basename($editor);
if (isset($vi_binaries[$binary])) { if (isset($vi_binaries[$binary])) {
// This runs "Q" (an invalid command), then "q" (a valid command, // This runs "Q" (an invalid command), then "q" (a valid command,
// meaning "quit"). Vim binaries with behavior that makes them poor // meaning "quit"). Vim binaries with behavior that makes them poor
@ -266,6 +280,33 @@ final class PhutilInteractiveEditor extends Phobject {
return $this; 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 * Get the name of the editor program to use. The value of the environmental

View file

@ -674,6 +674,8 @@ EOTEXT
if ($should_edit) { if ($should_edit) {
$edited = $this->newInteractiveEditor($remote_corpus) $edited = $this->newInteractiveEditor($remote_corpus)
->setName('differential-edit-revision-info') ->setName('differential-edit-revision-info')
->setTaskMessage(pht(
'Update the details for a revision, then save and exit.'))
->editInteractively(); ->editInteractively();
if ($edited != $remote_corpus) { if ($edited != $remote_corpus) {
$remote_corpus = $edited; $remote_corpus = $edited;
@ -1476,6 +1478,8 @@ EOTEXT
} else { } else {
$new_template = $this->newInteractiveEditor($template) $new_template = $this->newInteractiveEditor($template)
->setName('new-commit') ->setName('new-commit')
->setTaskMessage(pht(
'Provide the details for a new revision, then save and exit.'))
->editInteractively(); ->editInteractively();
} }
$first = false; $first = false;
@ -1752,6 +1756,8 @@ EOTEXT
$comments = $this->newInteractiveEditor($template) $comments = $this->newInteractiveEditor($template)
->setName('differential-update-comments') ->setName('differential-update-comments')
->setTaskMessage(pht(
'Update the revision comments, then save and exit.'))
->editInteractively(); ->editInteractively();
return $comments; return $comments;

View file

@ -909,6 +909,8 @@ EOTEXT
$commit_message = $this->newInteractiveEditor($template) $commit_message = $this->newInteractiveEditor($template)
->setName('arcanist-patch-commit-message') ->setName('arcanist-patch-commit-message')
->setTaskMessage(pht(
'Supply a commit message for this patch, then save and exit.'))
->editInteractively(); ->editInteractively();
$commit_message = ArcanistCommentRemover::removeComments($commit_message); $commit_message = ArcanistCommentRemover::removeComments($commit_message);

View file

@ -1234,6 +1234,9 @@ abstract class ArcanistWorkflow extends Phobject {
$commit_message = $this->newInteractiveEditor($template) $commit_message = $this->newInteractiveEditor($template)
->setName(pht('commit-message')) ->setName(pht('commit-message'))
->setTaskMessage(pht(
'Supply commit message for uncommitted changes, then save and '.
'exit.'))
->editInteractively(); ->editInteractively();
if ($commit_message === $template) { if ($commit_message === $template) {