21namespace sharg::detail
36class format_help :
public format_help_base<format_help>
39 using base_type = format_help_base<format_help>;
48 format_help() =
default;
49 format_help(format_help
const & pf) =
default;
50 format_help & operator=(format_help
const &) =
default;
51 format_help(format_help &&) =
default;
52 format_help & operator=(format_help &&) =
default;
53 ~format_help() =
default;
58 bool const advanced =
false) :
59 base_type{names, version_updates, advanced} {};
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());
244 if (stdout_is_terminal())
249 if (stdout_is_terminal())
254 if (stdout_is_terminal())
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)
344 for (
auto it = tokens.begin(); it != tokens.end(); ++it)
346 if (it == tokens.begin())
349 pos += text_width(*it);
350 if (pos > layout.screenWidth)
359 if (pos + 1 + text_width(*it) > layout.screenWidth)
365 pos = tab + text_width(*it);
371 pos += text_width(*it) + 1;
385 return to_text(
"\\fB") + str + to_text(
"\\fP");
389 bool prev_was_paragraph{
false};
392 friend struct ::sharg::detail::test_accessor;
395 console_layout_struct layout{};
409class format_short_help :
public format_help
415 void parse(parser_meta_data
const & parser_meta)
421 if (!parser_meta.synopsis.empty())
424 print_line(
"Try -h or --help for more information.\n",
true);
439class format_version :
public format_help
445 void parse(parser_meta_data & parser_meta)
465class format_copyright :
public format_help
471 void parse(parser_meta_data
const & parser_meta)
475 R
"(Copyright (c) 2006-2023, Knut Reinert & Freie Universität Berlin
476Copyright (c) 2016-2023, Knut Reinert & MPI für molekulare Genetik
479Redistribution and use in source and binary forms, with or without
480modification, are permitted provided that the following conditions are met:
482 * Redistributions of source code must retain the above copyright
483 notice, this list of conditions and the following disclaimer.
484 * Redistributions in binary form must reproduce the above copyright
485 notice, this list of conditions and the following disclaimer in the
486 documentation and/or other materials provided with the distribution.
487 * Neither the name of Knut Reinert or the FU Berlin nor the names of
488 its contributors may be used to endorse or promote products derived
489 from this software without specific prior written permission.
491THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
492AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
493IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
494ARE DISCLAIMED. IN NO EVENT SHALL KNUT REINERT OR THE FU BERLIN BE LIABLE
495FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
496DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
497SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
498CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
499LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
500OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
504 << in_bold(
"Copyright information for " + meta.app_name +
":\n") <<
std::string(80,
'-') <<
'\n';
506 if (!
empty(meta.long_copyright))
508 std::cout << to_text(
"\\fP") << meta.long_copyright <<
"\n";
510 else if (!
empty(meta.short_copyright))
512 std::cout << in_bold(meta.app_name +
" full copyright information not available. "
513 +
"Displaying short copyright information instead:\n")
514 << meta.short_copyright <<
"\n";
518 std::cout << to_text(
"\\fP") << meta.app_name <<
" copyright information not available.\n";
522 << in_bold(
"This program contains SeqAn code licensed under the following terms:\n")
524 << seqan_license <<
'\n';
update_notifications
Indicates whether application allows automatic update notifications by the sharg::parser.
Definition: auxiliary.hpp:29
Checks if program is run interactively and retrieves dimensions of terminal (Transferred from seqan2)...
Forward declares sharg::detail::test_accessor.