25 namespace seqan3::detail
38 class format_help :
public format_help_base<format_help>
41 using base_type = format_help_base<format_help>;
49 format_help() =
default;
50 format_help(format_help
const & pf) =
default;
51 format_help & operator=(format_help
const &) =
default;
52 format_help(format_help &&) =
default;
53 format_help & operator=(format_help &&) =
default;
54 ~format_help() =
default;
64 struct console_layout_struct
69 uint32_t defaultScreenWidth;
71 uint32_t maximalScreenWidth;
73 uint32_t minimalScreenWidth;
77 uint32_t centerPadding;
79 uint32_t rightPadding;
81 uint32_t leftColumnWidth;
83 uint32_t rightColumnWidth;
85 uint32_t rightColumnTab;
89 console_layout_struct(uint32_t
const terminal_width) :
90 screenWidth{0}, defaultScreenWidth{80}, maximalScreenWidth{120}, minimalScreenWidth{40},
91 leftPadding{4}, centerPadding{2}, rightPadding{2}, leftColumnWidth{4}, rightColumnWidth{0}
94 screenWidth = (terminal_width > 0) ? terminal_width : defaultScreenWidth;
95 screenWidth =
std::max(screenWidth, minimalScreenWidth);
96 screenWidth =
std::min(screenWidth, maximalScreenWidth);
97 screenWidth -= rightPadding;
99 rightColumnWidth = screenWidth - leftPadding - leftColumnWidth - centerPadding - rightPadding;
100 rightColumnTab = leftPadding + leftColumnWidth + centerPadding;
104 console_layout_struct() : console_layout_struct{get_terminal_width()} {}
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)
378 std::cpp20::back_inserter(tokens));
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};
425 friend struct ::seqan3::detail::test_accessor;
428 console_layout_struct layout{};
440 class format_short_help :
public format_help
446 void parse(argument_parser_meta_data
const & parser_meta)
452 if (!parser_meta.synopsis.empty())
455 print_line(
"Try -h or --help for more information.\n",
true);
470 class format_version :
public format_help
476 void parse(argument_parser_meta_data & parser_meta)
496 class format_copyright :
public format_help
502 void parse(argument_parser_meta_data
const & parser_meta)
507 R
"(Copyright (c) 2006-2020, Knut Reinert & Freie Universität Berlin
508 Copyright (c) 2016-2020, Knut Reinert & MPI für molekulare Genetik
511 Redistribution and use in source and binary forms, with or without
512 modification, are permitted provided that the following conditions are met:
514 * Redistributions of source code must retain the above copyright
515 notice, this list of conditions and the following disclaimer.
516 * Redistributions in binary form must reproduce the above copyright
517 notice, this list of conditions and the following disclaimer in the
518 documentation and/or other materials provided with the distribution.
519 * Neither the name of Knut Reinert or the FU Berlin nor the names of
520 its contributors may be used to endorse or promote products derived
521 from this software without specific prior written permission.
523 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
524 AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
525 IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
526 ARE DISCLAIMED. IN NO EVENT SHALL KNUT REINERT OR THE FU BERLIN BE LIABLE
527 FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
528 DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
529 SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
530 CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
531 LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
532 OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
535 stream << std::string(80, '=') << to_text(
"\n\\fB") <<
"Copyright information for "
536 << meta.app_name <<
":\n" << to_text(
"\\fP") <<
std::string(80,
'-') <<
'\n';
538 if (!
empty(meta.long_copyright))
540 stream << to_text(
"\\fP") << meta.long_copyright <<
"\n";
542 else if (!
empty(meta.short_copyright))
544 stream << to_text(
"\\fP") << meta.app_name <<
" full copyright information not available. Displaying"
545 <<
" short copyright information instead:\n" << to_text(
"\\fP") << meta.short_copyright <<
"\n";
549 stream << to_text(
"\\fP") << meta.app_name <<
" copyright information not available.\n";
552 stream <<
std::string(80,
'=') << to_text(
"\n\\fB")
553 <<
"This program contains SeqAn code licensed under the following terms:\n" << to_text(
"\\fP")
554 <<
std::string(80,
'-') <<
'\n' << seqan_license <<
'\n';