1 /********************************************************************************
2  *  Copyright (C) 2015-2020 by Mihai Moldovan <ionic@ionic.de> +49 721 14595728 *
3  *                                                                              *
4  *  This program is free software; you can redistribute it and/or modify        *
5  *  it under the terms of the GNU General Public License as published by        *
6  *  the Free Software Foundation; either version 2 of the License, or           *
7  *  (at your option) any later version.                                         *
8  *                                                                              *
9  *  This program is distributed in the hope that it will be useful,             *
10  *  but WITHOUT ANY WARRANTY; without even the implied warranty of              *
11  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the               *
12  *  GNU General Public License for more details.                                *
13  *                                                                              *
14  *  You should have received a copy of the GNU General Public License           *
15  *  along with this program; if not, write to the                               *
16  *  Free Software Foundation, Inc.,                                             *
17  *  59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.                   *
18  ********************************************************************************/
19 
20 #ifndef HELP_H
21 #define HELP_H
22 
23 #include <QPair>
24 #include <QStringList>
25 #include <QTextStream>
26 #include <cstddef>
27 
28 namespace help {
29   typedef QStringList prelude_t;
30   typedef QPair<QString, QString> params_elem_t;
31   typedef QList<params_elem_t> params_t;
32   typedef QPair<prelude_t, params_t> data_t;
33   typedef QPair<QString, QString> string_split_t;
34 
35   /* Builds a prelude_t object. Values are hardcoded here. */
36   prelude_t build_prelude ();
37 
38   /* Builds a params_t object. Values are hardcoded here. */
39   params_t build_params ();
40 
41   /* Merges prelude_t and params_t into a data_t object. */
42   data_t build_data ();
43 
44   /* Cleanup functions for string trimming. */
45   prelude_t cleanup_prelude (prelude_t prelude);
46   params_t cleanup_params (params_t params);
47 
48   /*
49    * Splits a string into two components.
50    * The first component is at most max_length (or 200) characters long.
51    * The string is split on the nearest space surrounding max_length
52    * (or max_length itself.)
53    * Caveat: if the string length is less than max_length, no splitting
54    * is performed.
55    * In that case, the second component is empty.
56    */
57   string_split_t split_long_line (QString &line, std::ptrdiff_t max_length = 100);
58 
59   /*
60    * Returns a help_data_t structure as a QString.
61    * If terminal_output is true, the terminal width is probed for and the function
62    * family tries its best to adhere to the auto-detected width.
63    * Additionally, terminal_output controls whether the resulting string is
64    * printed to stderr or not.
65    */
66   QString pretty_print (bool terminal_output = true);
67   QString pretty_print (data_t data, bool terminal_output = true);
68 }
69 
70 #endif /* !defined (HELP_H) */
71