20 #include <range/v3/view/repeat_n.hpp> 40 class format_help :
public format_help_base<format_help>
43 using base_type = format_help_base<format_help>;
52 format_help() =
default;
53 format_help(format_help
const & pf) =
default;
54 format_help & operator=(format_help
const &) =
default;
55 format_help(format_help &&) =
default;
56 format_help & operator=(format_help &&) =
default;
57 ~format_help() =
default;
60 format_help(
bool const advanced) : base_type{advanced}
67 struct console_layout_struct
72 unsigned defaultScreenWidth;
74 unsigned maximalScreenWidth;
76 unsigned minimalScreenWidth;
80 unsigned centerPadding;
82 unsigned rightPadding;
84 unsigned leftColumnWidth;
86 unsigned rightColumnWidth;
88 unsigned rightColumnTab;
91 console_layout_struct() :
92 screenWidth{0}, defaultScreenWidth{80}, maximalScreenWidth{120}, minimalScreenWidth{40},
93 leftPadding{4}, centerPadding{2}, rightPadding{2}, leftColumnWidth{4}, rightColumnWidth{0}
96 unsigned cols = get_terminal_width();
97 screenWidth = (cols > 0) ? cols : defaultScreenWidth;
98 screenWidth =
std::max(screenWidth, minimalScreenWidth);
99 screenWidth =
std::min(screenWidth, maximalScreenWidth);
100 screenWidth -= rightPadding;
102 rightColumnWidth = screenWidth - leftPadding - leftColumnWidth - centerPadding - rightPadding;
103 rightColumnTab = leftPadding + leftColumnWidth + centerPadding;
113 if (!
empty(meta.short_description))
114 std::cout <<
" - " << meta.short_description;
117 unsigned len = text_width(meta.app_name) + (
empty(meta.short_description) ? 0 : 3) +
118 text_width(meta.short_description);
132 prev_was_paragraph =
false;
143 std::cout << title << to_text(
"\\fP") <<
'\n';
144 prev_was_paragraph =
false;
152 void print_line(
std::string const & text,
bool const line_is_paragraph)
154 if (prev_was_paragraph)
159 print_text(text, layout.leftPadding);
160 prev_was_paragraph = line_is_paragraph;
179 if (prev_was_paragraph)
187 unsigned pos = layout.leftPadding + term.
size();
188 if (pos + layout.centerPadding > layout.rightColumnTab)
193 std::fill_n(out, layout.rightColumnTab - pos,
' ');
194 print_text(desc, layout.rightColumnTab);
196 prev_was_paragraph =
false;
205 std::cout <<
"\n" << to_text(
"\\fB") <<
"VERSION" << to_text(
"\\fP") <<
"\n";
207 std::cout << to_text(
"\\fB") <<
"Last update: " << to_text(
"\\fP") << meta.date <<
"\n";
209 std::cout << to_text(
"\\fB") << meta.app_name <<
" version: " << to_text(
"\\fP") << meta.version <<
"\n";
214 if (!
empty(meta.url))
216 std::cout <<
"\n" << to_text(
"\\fB") <<
"URL" << to_text(
"\\fP") <<
"\n";
231 if ((!
empty(meta.short_copyright)) || (!
empty(meta.long_copyright)) || (!
empty(meta.citation)))
233 std::cout <<
"\n" << to_text(
"\\fB") <<
"LEGAL" << to_text(
"\\fP") <<
"\n";
235 if (!
empty(meta.short_copyright))
238 std::cout << to_text(
"\\fB") << meta.app_name <<
" Copyright: " 239 << to_text(
"\\fP") << meta.short_copyright <<
"\n";
242 std::cout << to_text(
"\\fB") <<
"SeqAn Copyright: " << to_text(
"\\fP")
243 <<
"2006-2015 Knut Reinert, FU-Berlin; released under the 3-clause BSDL.\n";
244 if (!
empty(meta.citation))
247 std::cout << to_text(
"\\fB") <<
"In your academic works please cite: " << to_text(
"\\fP")
248 << meta.citation <<
"\n";
250 if (!
empty(meta.long_copyright))
253 std::cout <<
"For full copyright and/or warranty information see " << to_text(
"\\fB")
254 <<
"--copyright" << to_text(
"\\fP") <<
".\n";
266 for (
auto it = str.
begin(); it != str.
end(); ++it)
272 assert(it != str.
end());
280 assert(it != str.
end());
325 for (
unsigned i = 0; i < text.
size(); ++i)
333 if (i + 1 == text.
size())
339 if (text[i + 1] ==
'\\' || text[i + 1] ==
'-')
346 if (i + 2 == text.
size())
353 if (text[i + 1] ==
'f')
355 if (text[i + 2] ==
'B' || text[i + 2] ==
'I' || text[i + 2] ==
'P')
369 void print_text(
std::string const & text,
unsigned const tab)
386 for (TConstIter it = tokens.begin(); it != tokens.end(); ++it)
388 if (it == tokens.begin())
391 pos += text_width(*it);
392 if (pos > layout.screenWidth)
401 if (pos + 1 + text_width(*it) > layout.screenWidth)
407 pos = tab + text_width(*it);
413 pos += text_width(*it) + 1;
422 bool prev_was_paragraph{
false};
424 console_layout_struct layout{};
436 class format_short_help :
public format_help
442 void parse(argument_parser_meta_data
const & parser_meta)
448 if (!parser_meta.synopsis.empty())
451 print_line(
"Try -h or --help for more information.\n",
true);
466 class format_version :
public format_help
472 void parse(argument_parser_meta_data & parser_meta)
492 class format_copyright :
public format_help
498 void parse(argument_parser_meta_data
const & parser_meta)
503 R
"(Copyright (c) 2006-2019, Knut Reinert & Freie Universität Berlin 504 Copyright (c) 2016-2019, Knut Reinert & MPI für molekulare Genetik 507 Redistribution and use in source and binary forms, with or without 508 modification, are permitted provided that the following conditions are met: 510 * Redistributions of source code must retain the above copyright 511 notice, this list of conditions and the following disclaimer. 512 * Redistributions in binary form must reproduce the above copyright 513 notice, this list of conditions and the following disclaimer in the 514 documentation and/or other materials provided with the distribution. 515 * Neither the name of Knut Reinert or the FU Berlin nor the names of 516 its contributors may be used to endorse or promote products derived 517 from this software without specific prior written permission. 519 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 520 AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 521 IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 522 ARE DISCLAIMED. IN NO EVENT SHALL KNUT REINERT OR THE FU BERLIN BE LIABLE 523 FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 524 DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 525 SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 526 CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 527 LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 528 OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH 534 if (!
empty(meta.long_copyright))
536 strem << to_text(
"\\fP") << meta.long_copyright <<
"\n";
538 else if (!
empty(meta.short_copyright))
540 strem << to_text(
"\\fP") << meta.app_name <<
" full copyright information not available. Displaying" 541 <<
" short copyright information instead:\n" << to_text(
"\\fP") << meta.short_copyright <<
"\n";
545 strem << to_text(
"\\fP") << meta.app_name <<
" copyright information not available.\n";
549 <<
"This program contains SeqAn3 code licensed under the following terms:\n" << to_text(
"\\fP")
#define SEQAN3_VERSION_MINOR
The minor version as MACRO.
Definition: version.hpp:22
Checks if program is run interactively and retrieves dimensions of terminal (Transferred from seqan2)...
Definition: aligned_sequence_concept.hpp:35
T back_inserter(T... args)
::ranges::empty empty
Alias for ranges::empty. Checks whether a range is empty.
Definition: ranges:194
constexpr auto repeat_n
A view factory that repeats a given value n times.
Definition: repeat_n.hpp:97
#define SEQAN3_VERSION_PATCH
The patch version as MACRO.
Definition: version.hpp:24
#define SEQAN3_VERSION_MAJOR
The major version as MACRO.
Definition: version.hpp:20
Provides SeqAn version macros and global variables.
Provides seqan3::debug_stream and related types.