Fix line wrapping for long options
authorTeemu Murtola <teemu.murtola@gmail.com>
Mon, 30 Dec 2013 17:01:03 +0000 (19:01 +0200)
committerGerrit Code Review <gerrit@gerrit.gromacs.org>
Tue, 14 Jan 2014 05:52:20 +0000 (06:52 +0100)
The default line length for console output should only be set in
HelpWriterContext::writeTextBlock(), but not in the lower-level helpers,
which are generally called from contexts where line wrapping is getting
done on a higher level.

For example, 'gmx help hbond' shows some extra line breaks in the long
option descriptions without this fix.

Also removed an unused overload, that would also violate the above principle.

Change-Id: Ia40cea399c0f0f95d6d53ca2872d93baba47844e

src/gromacs/onlinehelp/helpwritercontext.cpp
src/gromacs/onlinehelp/helpwritercontext.h

index b28b261a111c026b75edcfb88e14fbbfb9d93c60..42517ed38ec58024017edfdfb7bdd8b53ae501c5 100644 (file)
@@ -559,10 +559,6 @@ void HelpWriterContext::Impl::processMarkup(const std::string &text,
         {
             result = repall(result, sandrTty);
             result = replaceLinks(result);
-            if (wrapper->settings().lineLength() == 0)
-            {
-                wrapper->settings().setLineLength(78);
-            }
             return wrapper->wrap(result);
         }
         case eHelpOutputFormat_Man:
@@ -667,12 +663,11 @@ void HelpWriterContext::writeTitle(const std::string &title) const
 
 void HelpWriterContext::writeTextBlock(const std::string &text) const
 {
-    writeTextBlock(TextLineWrapperSettings(), text);
-}
-
-void HelpWriterContext::writeTextBlock(const TextLineWrapperSettings &settings,
-                                       const std::string             &text) const
-{
+    TextLineWrapperSettings settings;
+    if (outputFormat() == eHelpOutputFormat_Console)
+    {
+        settings.setLineLength(78);
+    }
     outputFile().writeLine(substituteMarkupAndWrapToString(settings, text));
 }
 
index fc1d5f54b989b2465769e594484695302550a758..c0947005e2635c7e94a63e94b8b4f377fc1c3172 100644 (file)
@@ -232,19 +232,6 @@ class HelpWriterContext
          * and writes the result directly to the output file.
          */
         void writeTextBlock(const std::string &text) const;
-        /*! \brief
-         * Writes a formatted text block into the output.
-         *
-         * \param[in] settings Line wrapper settings.
-         * \param[in] text     Text to format.
-         * \throws    std::bad_alloc if out of memory.
-         * \throws    FileIOError on any I/O error.
-         *
-         * Convenience function that calls substituteMarkupAndWrapToString()
-         * and writes the result directly to the output file.
-         */
-        void writeTextBlock(const TextLineWrapperSettings &settings,
-                            const std::string             &text) const;
 
     private:
         class Impl;