/**
  * @param array $banned_editors
  *   Indexed array containing full paths to editors that have failed.
  * @return string
  *   Full path to the preferred editor to use.
  */
 protected function locatePreferredEditor($banned_editors = [])
 {
     // Use environment variable settings without prompting if they're going to
     // work.
     if ($this->preferredEditor && !in_array($this->preferredEditor, $banned_editors)) {
         return $this->preferredEditor;
     } else {
         if ($this->envVarEditor && !in_array($this->envVarEditor, $banned_editors)) {
             $this->preferredEditor = $this->envVarEditor;
         } else {
             $available_editors = $this->locateAvailableEditors();
             $filtered = [];
             foreach ($available_editors['X'] as $path => $name) {
                 if (!in_array($path, $banned_editors)) {
                     $filtered[$path] = $name;
                 }
             }
             $available_editors['X'] = $filtered;
             $filtered = [];
             foreach ($available_editors['term'] as $path => $name) {
                 if (!in_array($path, $banned_editors)) {
                     $filtered[$path] = $name;
                 }
             }
             $available_editors['term'] = $filtered;
             $num = count($available_editors['X']) + count($available_editors['term']);
             if ($num == 1) {
                 $this->preferredEditor = current(array_keys(array_merge($available_editors['X'], $available_editors['term'])));
             } else {
                 if ($num == 0) {
                     cli\out('No text editor was found at common locations. ');
                     $editor = false;
                     while (!file_exists($editor)) {
                         $editor = cli\prompt('Enter the path to your text editor');
                     }
                 } else {
                     $choices = array_map(function ($item) {
                         return $item . ' (GUI)';
                     }, $available_editors['X']);
                     $choices += $available_editors['term'];
                     cli\out("The following text editors were found on your system:\n");
                     $this->preferredEditor = cli\menu($choices, current(array_keys($choices)), 'Enter the number of the editor you prefer');
                 }
             }
         }
     }
     return $this->preferredEditor;
 }
Esempio n. 2
0
 /**
  * Show raw data in console even if verbose mode is not in force.
  * 
  * @param string $data The data to go in output.
  * @param boolean $newLine Whether to display a new line after $data.
  */
 protected function out($data, $newLine = true)
 {
     CliTools\out($data);
     if ($newLine === true) {
         CliTools\out("\n");
     }
 }