changeset 24874:a4dc2ef8741c

Don't start GUI by default, require new '--gui' option * libgui/src/octave-gui.cc (gui_application::start_gui_p): much simplified since we no longer need to guess if we have to start the GUI. It simply maps to m_options.gui (). * libinterp/octave.cc (cmdline_options::cmdline_options): ignore old options, handle new gui options. (application::init): check for incompatible options and error. * libinterp/octave.h (cmdline_options): new functions to access the new options and deprecate functions to access old options. * libinterp/options-usage.h: undocument removed options '--force-gui' and '--no-gui'. Document new '--gui' option. Add parsing for new '--gui' option. * NEWS: note important change.
author Carnë Draug <carandraug@octave.org>
date Wed, 14 Mar 2018 14:29:50 +0100
parents 486bc22482ca
children 7c7b60dd4d4c
files NEWS libgui/src/octave-gui.cc libinterp/octave.cc libinterp/octave.h libinterp/options-usage.h
diffstat 5 files changed, 56 insertions(+), 74 deletions(-) [+]
line wrap: on
line diff
--- a/NEWS	Wed Mar 14 12:27:19 2018 +0100
+++ b/NEWS	Wed Mar 14 14:29:50 2018 +0100
@@ -20,6 +20,15 @@
 
       glpk  Qhull
 
+ ** The octave command no longer starts the GUI by default.  Most users
+    starting Octave from command line were expecting the command line
+    interface and Desktop launchers required the `--force-gui' option
+    anyway.  With this change, desktop launchers should change to use
+    the new option `--gui'.  The previous `--force-gui' will continue to
+    work and maps to `--gui' but will be removed in Octave 4.8.  The old
+    option `--no-gui' is now irrelevant and is ignored.  It will also be
+    removed in Octave 4.8.
+
  ** A new container data type--containers.Map--is available.  Map is a
     key/value storage container (a.k.a, a hash) that efficiently allows
     storing and retrieving values by name, rather than by position which
--- a/libgui/src/octave-gui.cc	Wed Mar 14 12:27:19 2018 +0100
+++ b/libgui/src/octave-gui.cc	Wed Mar 14 14:29:50 2018 +0100
@@ -79,53 +79,7 @@
 
   bool gui_application::start_gui_p (void) const
   {
-    if (m_options.no_window_system ())
-      return false;
-
-    std::string err_msg;
-    if (! display_info::display_available (err_msg))
-      {
-        if (! (m_options.inhibit_startup_message () || err_msg.empty ()))
-          warning (err_msg.c_str ());
-
-        return false;
-      }
-
-    if (! m_options.line_editing ())
-      {
-        if (! (m_options.inhibit_startup_message ()
-               || m_options.no_gui ()))
-          warning ("--no-line-editing option given, disabling GUI");
-
-        return false;
-      }
-
-    if (m_options.force_gui ())
-      return true;
-
-    if (m_options.no_gui ())
-      return false;
-
-    if (m_options.persist ())
-      return true;
-
-    // If stdin is not a tty, then assume we are reading commands from a
-    // pipe or a redirected file and the GUI should not start.  If this
-    // is not the case (for example, starting from a desktop "launcher"
-    // with no terminal) and you want to start the GUI, you may use the
-    // --force-gui option to start the GUI.
-
-    if (! octave_isatty_wrapper (fileno (stdin)))
-      return false;
-
-    // If we have code to eval or execute from a file, and we are going
-    // to exit immediately after executing it, don't start the gui.
-
-    std::string code_to_eval = m_options.code_to_eval ();
-    if (! code_to_eval.empty () || m_have_script_file)
-      return false;
-
-    return true;
+    return m_options.gui ();
   }
 
   int gui_application::execute (void)
--- a/libinterp/octave.cc	Wed Mar 14 12:27:19 2018 +0100
+++ b/libinterp/octave.cc	Wed Mar 14 14:29:50 2018 +0100
@@ -154,8 +154,8 @@
               m_exec_path = octave_optarg_wrapper ();
             break;
 
-          case FORCE_GUI_OPTION:
-            m_force_gui = true;
+          case GUI_OPTION: // same value as FORCE_GUI_OPTION
+            m_gui = true;
             break;
 
           case IMAGE_PATH_OPTION:
@@ -186,7 +186,7 @@
             break;
 
           case NO_GUI_OPTION:
-            m_no_gui = true;
+            // This option does nothing now.
             break;
 
           case NO_INIT_FILE_OPTION:
@@ -229,14 +229,6 @@
           }
       }
 
-    // Check for various incompatible argument pairs
-    if (m_force_gui && m_no_gui)
-      {
-        std::cerr << "error: only one of --force-gui and --no-gui may be used\n";
-
-        octave_print_terse_usage_and_exit ();
-      }
-
     m_remaining_args = string_vector (argv+octave_optind_wrapper (),
                                       argc-octave_optind_wrapper ());
   }
@@ -369,6 +361,21 @@
         octave_print_terse_usage_and_exit ();
       }
 
+    if (m_options.gui ())
+      {
+        if (m_options.no_window_system ())
+          {
+            std::cerr << "error: --gui and --no-window-system are mutually exclusive options" << std::endl;
+            octave_print_terse_usage_and_exit ();
+          }
+        if (! m_options.line_editing ())
+          {
+            std::cerr << "error: --gui and --no-line-editing are mutually exclusive options" << std::endl;
+            octave_print_terse_usage_and_exit ();
+          }
+      }
+
+
     m_is_octave_program = ((m_have_script_file || m_have_eval_option_code)
                            && ! m_options.persist ()
                            && ! m_options.traditional ());
--- a/libinterp/octave.h	Wed Mar 14 12:27:19 2018 +0100
+++ b/libinterp/octave.h	Wed Mar 14 14:29:50 2018 +0100
@@ -50,13 +50,20 @@
 
     bool debug_jit (void) const { return m_debug_jit; }
     bool echo_commands (void) const { return m_echo_commands; }
-    bool force_gui (void) const { return m_force_gui; }
+
+    OCTAVE_DEPRECATED (4.4, "use 'gui' instead")
+    bool force_gui (void) const { return m_gui; }
+
     bool forced_interactive (void) const { return m_forced_interactive; }
     bool forced_line_editing (void) const { return m_forced_line_editing; }
+    bool gui (void) const { return m_gui; }
     bool inhibit_startup_message (void) const { return m_inhibit_startup_message; }
     bool jit_compiler (void) const { return m_jit_compiler; }
     bool line_editing (void) const { return m_line_editing; }
-    bool no_gui (void) const { return m_no_gui; }
+
+    OCTAVE_DEPRECATED (4.4, "use '! gui' instead")
+    bool no_gui (void) const { return ! gui (); }
+
     bool no_window_system (void) const { return m_no_window_system; }
     bool persist (void) const { return m_persist; }
     bool read_history_file (void) const { return m_read_history_file; }
@@ -79,13 +86,20 @@
 
     void debug_jit (bool arg) { m_debug_jit = arg; }
     void echo_commands (bool arg) { m_echo_commands = arg; }
-    void force_gui (bool arg) { m_force_gui = arg; }
+
+    OCTAVE_DEPRECATED (4.4, "use 'gui' instead")
+    void force_gui (bool arg) { m_gui = arg; }
+
     void forced_line_editing (bool arg) { m_forced_line_editing = arg; }
     void forced_interactive (bool arg) { m_forced_interactive = arg; }
+    void gui (bool arg) { m_gui = arg; }
     void inhibit_startup_message (bool arg) { m_inhibit_startup_message = arg; }
     void jit_compiler (bool arg) { m_jit_compiler = arg; }
     void line_editing (bool arg) { m_line_editing = arg; }
-    void no_gui (bool arg) { m_no_gui = arg; }
+
+    OCTAVE_DEPRECATED (4.4, "this has been removed and is the default now")
+    void no_gui (bool) { return; }
+
     void no_window_system (bool arg) { m_no_window_system = arg; }
     void persist (bool arg) { m_persist = arg; }
     void read_history_file (bool arg) { m_read_history_file = arg; }
@@ -116,8 +130,9 @@
     // (--echo-commands, -x)
     bool m_echo_commands = false;
 
-    // If TRUE, force the GUI to start.
-    // (--force-gui)
+    // If TRUE, start the GUI.
+    // (--gui) and (--force-gui) for backwards compatibility
+    bool m_gui = false;
     bool m_force_gui = false;
 
     // TRUE means the user forced this shell to be interactive.
@@ -140,10 +155,6 @@
     // (--no-line-editing)
     bool m_line_editing = true;
 
-    // If TRUE don't start the GUI.
-    // (--no-gui)
-    bool m_no_gui = false;
-
     // If TRUE, ignore the window system even if it is available.
     // (--no-window-system, -W)
     bool m_no_window_system = false;
--- a/libinterp/options-usage.h	Wed Mar 14 12:27:19 2018 +0100
+++ b/libinterp/options-usage.h	Wed Mar 14 14:29:50 2018 +0100
@@ -33,9 +33,9 @@
 static const char *usage_string =
   "octave [-HVWdfhiqvx] [--debug] [--debug-jit] [--doc-cache-file file]\n\
        [--echo-commands] [--eval CODE] [--exec-path path]\n\
-       [--force-gui] [--help] [--image-path path]\n\
+       [--gui] [--help] [--image-path path]\n\
        [--info-file file] [--info-program prog] [--interactive]\n\
-       [--jit-compiler] [--line-editing] [--no-gui] [--no-history]\n\
+       [--jit-compiler] [--line-editing] [--no-history]\n\
        [--no-init-file] [--no-init-path] [--no-line-editing]\n\
        [--no-site-file] [--no-window-system] [--norc] [-p path]\n\
        [--path path] [--persist] [--silent] [--traditional]\n\
@@ -59,14 +59,15 @@
 #define DOC_CACHE_FILE_OPTION 2
 #define EVAL_OPTION 3
 #define EXEC_PATH_OPTION 4
-#define FORCE_GUI_OPTION 5
+#define FORCE_GUI_OPTION 5 // ignored since Octave 4.4, remove for 4.8
+#define GUI_OPTION 5
 #define IMAGE_PATH_OPTION 6
 #define INFO_FILE_OPTION 7
 #define INFO_PROG_OPTION 8
 #define DEBUG_JIT_OPTION 9
 #define JIT_COMPILER_OPTION 10
 #define LINE_EDITING_OPTION 11
-#define NO_GUI_OPTION 12
+#define NO_GUI_OPTION 12 // ignored since Octave 4.4, remove for 4.8
 #define NO_INIT_FILE_OPTION 13
 #define NO_INIT_PATH_OPTION 14
 #define NO_LINE_EDITING_OPTION 15
@@ -85,6 +86,7 @@
   { "eval",                     octave_required_arg, 0, EVAL_OPTION },
   { "exec-path",                octave_required_arg, 0, EXEC_PATH_OPTION },
   { "force-gui",                octave_no_arg,       0, FORCE_GUI_OPTION },
+  { "gui",                      octave_no_arg,       0, GUI_OPTION },
   { "help",                     octave_no_arg,       0, 'h' },
   { "image-path",               octave_required_arg, 0, IMAGE_PATH_OPTION },
   { "info-file",                octave_required_arg, 0, INFO_FILE_OPTION },
@@ -135,7 +137,7 @@
   --echo-commands, -x     Echo commands as they are executed.\n\
   --eval CODE             Evaluate CODE.  Exit when done unless --persist.\n\
   --exec-path PATH        Set path for executing subprograms.\n\
-  --force-gui             Force graphical user interface to start.\n\
+  --gui                   Start the graphical user interface.\n\
   --help, -h,             Print short help message and exit.\n\
   --image-path PATH       Add PATH to head of image search path.\n\
   --info-file FILE        Use top-level info file FILE.\n\
@@ -143,7 +145,6 @@
   --interactive, -i       Force interactive behavior.\n\
   --jit-compiler          Enable the JIT compiler.\n\
   --line-editing          Force readline use for command-line editing.\n\
-  --no-gui                Disable the graphical user interface.\n\
   --no-history, -H        Don't save commands to the history list\n\
   --no-init-file          Don't read the ~/.octaverc or .octaverc files.\n\
   --no-init-path          Don't initialize function search path.\n\