24namespace seqan3::detail
39class format_help :
public format_help_base<format_help>
42 using base_type = format_help_base<format_help>;
51 format_help() =
default;
52 format_help(format_help
const & pf) =
default;
53 format_help & operator=(format_help
const &) =
default;
54 format_help(format_help &&) =
default;
55 format_help & operator=(format_help &&) =
default;
56 ~format_help() =
default;
65 struct console_layout_struct
70 uint32_t defaultScreenWidth;
72 uint32_t maximalScreenWidth;
74 uint32_t minimalScreenWidth;
78 uint32_t centerPadding;
80 uint32_t rightPadding;
82 uint32_t leftColumnWidth;
84 uint32_t rightColumnWidth;
86 uint32_t rightColumnTab;
90 console_layout_struct(uint32_t
const terminal_width) :
92 defaultScreenWidth{80},
93 maximalScreenWidth{120},
94 minimalScreenWidth{40},
102 screenWidth = (terminal_width > 0) ? terminal_width : defaultScreenWidth;
103 screenWidth =
std::max(screenWidth, minimalScreenWidth);
104 screenWidth =
std::min(screenWidth, maximalScreenWidth);
105 screenWidth -= rightPadding;
107 rightColumnWidth = screenWidth - leftPadding - leftColumnWidth - centerPadding - rightPadding;
108 rightColumnTab = leftPadding + leftColumnWidth + centerPadding;
112 console_layout_struct() : console_layout_struct{get_terminal_width()}
122 if (!
empty(meta.short_description))
123 std::cout <<
" - " << meta.short_description;
127 text_width(meta.app_name) + (
empty(meta.short_description) ? 0 : 3) + text_width(meta.short_description);
144 return std::toupper(c);
147 prev_was_paragraph =
false;
159 prev_was_paragraph =
false;
167 void print_line(
std::string const & text,
bool const line_is_paragraph)
169 if (prev_was_paragraph)
174 print_text(text, layout.leftPadding);
175 prev_was_paragraph = line_is_paragraph;
194 if (prev_was_paragraph)
202 unsigned pos = layout.leftPadding + term.
size();
203 if (pos + layout.centerPadding > layout.rightColumnTab)
208 std::fill_n(out, layout.rightColumnTab - pos,
' ');
209 print_text(desc, layout.rightColumnTab);
211 prev_was_paragraph =
false;
227 for (
auto it = str.
begin(); it != str.
end(); ++it)
233 assert(it != str.
end());
241 assert(it != str.
end());
286 for (
unsigned i = 0; i < text.
size(); ++i)
294 if (i + 1 == text.
size())
300 if (text[i + 1] ==
'\\' || text[i + 1] ==
'-')
307 if (i + 2 == text.
size())
314 if (text[i + 1] ==
'f')
316 if (text[i + 2] ==
'B' || text[i + 2] ==
'I' || text[i + 2] ==
'P')
330 void print_text(
std::string const & text,
unsigned const tab)
348 for (TConstIter it = tokens.
begin(); it != tokens.
end(); ++it)
350 if (it == tokens.
begin())
353 pos += text_width(*it);
354 if (pos > layout.screenWidth)
363 if (pos + 1 + text_width(*it) > layout.screenWidth)
369 pos = tab + text_width(*it);
375 pos += text_width(*it) + 1;
389 return to_text(
"\\fB") + str + to_text(
"\\fP");
393 bool prev_was_paragraph{
false};
396 friend struct ::seqan3::detail::test_accessor;
399 console_layout_struct layout{};
413class format_short_help :
public format_help
419 void parse(argument_parser_meta_data
const & parser_meta)
425 if (!parser_meta.synopsis.empty())
428 print_line(
"Try -h or --help for more information.\n",
true);
445class format_version :
public format_help
451 void parse(argument_parser_meta_data & parser_meta)
473class format_copyright :
public format_help
479 void parse(argument_parser_meta_data
const & parser_meta)
484 R
"(Copyright (c) 2006-2022, Knut Reinert & Freie Universität Berlin
485Copyright (c) 2016-2022, Knut Reinert & MPI für molekulare Genetik
488Redistribution and use in source and binary forms, with or without
489modification, are permitted provided that the following conditions are met:
491 * Redistributions of source code must retain the above copyright
492 notice, this list of conditions and the following disclaimer.
493 * Redistributions in binary form must reproduce the above copyright
494 notice, this list of conditions and the following disclaimer in the
495 documentation and/or other materials provided with the distribution.
496 * Neither the name of Knut Reinert or the FU Berlin nor the names of
497 its contributors may be used to endorse or promote products derived
498 from this software without specific prior written permission.
500THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
501AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
502IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
503ARE DISCLAIMED. IN NO EVENT SHALL KNUT REINERT OR THE FU BERLIN BE LIABLE
504FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
505DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
506SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
507CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
508LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
509OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
513 << in_bold(
"Copyright information for " + meta.app_name +
":\n") <<
std::string(80,
'-') <<
'\n';
515 if (!
empty(meta.long_copyright))
517 stream << to_text(
"\\fP") << meta.long_copyright <<
"\n";
519 else if (!
empty(meta.short_copyright))
521 stream << in_bold(meta.app_name +
" full copyright information not available. "
522 +
"Displaying short copyright information instead:\n")
523 << meta.short_copyright <<
"\n";
527 stream << to_text(
"\\fP") << meta.app_name <<
" copyright information not available.\n";
531 << in_bold(
"This program contains SeqAn code licensed under the following terms:\n")
533 << seqan_license <<
'\n';
T back_inserter(T... args)
@ advanced
Definition: auxiliary.hpp:255
Checks if program is run interactively and retrieves dimensions of terminal (Transferred from seqan2)...
Forward declares seqan3::detail::test_accessor.