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;
57 format_help(std::vector<std::string>
const & names,
bool const advanced =
false) : base_type{names, advanced}
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()} {}
110 std::ostream_iterator<char> out(std::cout);
112 std::cout << meta.app_name;
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);
119 std::fill_n(out, len,
'=');
126 void print_section(std::string
const & title)
128 std::ostream_iterator<char> out(std::cout);
129 std::cout <<
'\n' << to_text(
"\\fB");
130 std::transform(title.begin(), title.end(), out, [] (
unsigned char c) { return std::toupper(c); });
131 std::cout << to_text(
"\\fP") <<
'\n';
132 prev_was_paragraph =
false;
138 void print_subsection(std::string
const & title)
140 std::ostream_iterator<char> out(std::cout);
141 std::cout <<
'\n' << to_text(
"\\fB");
142 std::fill_n(out, layout.leftPadding / 2,
' ');
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)
157 std::ostream_iterator<char> out(std::cout);
158 std::fill_n(out, layout.leftPadding,
' ');
159 print_text(text, layout.leftPadding);
160 prev_was_paragraph = line_is_paragraph;
177 void print_list_item(std::string
const & term, std::string
const & desc)
179 if (prev_was_paragraph)
182 std::ostream_iterator<char> out(std::cout);
185 std::fill_n(out, layout.leftPadding,
' ');
186 std::cout << to_text(term);
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;
202 std::ostream_iterator<char> out(std::cout);
205 std::cout <<
"\n" << to_text(
"\\fB") <<
"VERSION" << to_text(
"\\fP") <<
"\n";
206 std::fill_n(out, layout.leftPadding,
' ');
207 std::cout << to_text(
"\\fB") <<
"Last update: " << to_text(
"\\fP") << meta.date <<
"\n";
208 std::fill_n(out, layout.leftPadding,
' ');
209 std::cout << to_text(
"\\fB") << meta.app_name <<
" version: " << to_text(
"\\fP") << meta.version <<
"\n";
210 std::fill_n(out, layout.leftPadding,
' ');
211 std::cout << to_text(
"\\fB") <<
"SeqAn version: " << to_text(
"\\fP") <<
SEQAN3_VERSION_MAJOR <<
'.'
214 if (!empty(meta.url))
216 std::cout <<
"\n" << to_text(
"\\fB") <<
"URL" << to_text(
"\\fP") <<
"\n";
217 std::fill_n(out, layout.leftPadding,
' ');
218 std::cout << meta.url <<
"\n";
228 std::ostream_iterator<char> out(std::cout);
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))
237 std::fill_n(out, layout.leftPadding,
' ');
238 std::cout << to_text(
"\\fB") << meta.app_name <<
" Copyright: "
239 << to_text(
"\\fP") << meta.short_copyright <<
"\n";
241 std::fill_n(out, layout.leftPadding,
' ');
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))
246 std::fill_n(out, layout.leftPadding,
' ');
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))
252 std::fill_n(out, layout.leftPadding,
' ');
253 std::cout <<
"For full copyright and/or warranty information see " << to_text(
"\\fB")
254 <<
"--copyright" << to_text(
"\\fP") <<
".\n";
262 std::string to_text(std::string
const & str)
266 for (
auto it = str.begin(); it != str.end(); ++it)
272 assert(it != str.end());
275 result.push_back(*it);
280 assert(it != str.end());
284 result.append(
"\033[4m");
289 result.append(
"\033[1m");
294 result.append(
"\033[0m");
298 result.append(
"\\f");
299 result.push_back(*it);
304 result.push_back(
'\\');
305 result.push_back(*it);
310 result.push_back(*it);
321 unsigned text_width(std::string
const & text)
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)
372 std::ostream_iterator<char> out(std::cout);
375 std::istringstream iss(text.c_str());
376 std::vector<std::string> tokens;
377 std::ranges::copy(std::istream_iterator<std::string>(iss), std::istream_iterator<std::string>(),
378 std::cpp20::back_inserter(tokens));
382 std::fill_n(out, tab - pos,
' ');
385 typedef std::vector<std::string>::const_iterator TConstIter;
386 for (TConstIter it = tokens.begin(); it != tokens.end(); ++it)
388 if (it == tokens.begin())
390 std::cout << to_text(*it);
391 pos += text_width(*it);
392 if (pos > layout.screenWidth)
395 std::fill_n(out, tab,
' ');
401 if (pos + 1 + text_width(*it) > layout.screenWidth)
405 fill_n(out, tab,
' ');
406 std::cout << to_text(*it);
407 pos = tab + text_width(*it);
412 std::cout << to_text(*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);
457 std::exit(EXIT_SUCCESS);
470 class format_version :
public format_help
476 void parse(argument_parser_meta_data & parser_meta)
483 std::exit(EXIT_SUCCESS);
496 class format_copyright :
public format_help
502 void parse(argument_parser_meta_data
const & parser_meta)
505 debug_stream_type stream{std::cout};
506 std::string seqan_license{
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';
556 std::exit(EXIT_SUCCESS);
seqan3::type_list< trait_t< pack_t >... > transform
Apply a transformation trait to every type in the pack and return a seqan3::type_list of the results.
Definition: traits.hpp:307
Checks if program is run interactively and retrieves dimensions of terminal (Transferred from seqan2)...
Forward declares seqan3::detail::test_accessor.
Provides SeqAn version macros and global variables.
#define SEQAN3_VERSION_MAJOR
The major version as MACRO.
Definition: version.hpp:20
#define SEQAN3_VERSION_PATCH
The patch version as MACRO.
Definition: version.hpp:24
#define SEQAN3_VERSION_MINOR
The minor version as MACRO.
Definition: version.hpp:22