SeqAn3  3.2.0-rc.1
The Modern C++ library for sequence analysis.
format_man.hpp
Go to the documentation of this file.
1 // -----------------------------------------------------------------------------------------------------
2 // Copyright (c) 2006-2022, Knut Reinert & Freie Universität Berlin
3 // Copyright (c) 2016-2022, Knut Reinert & MPI für molekulare Genetik
4 // This file may be used, modified and/or redistributed under the terms of the 3-clause BSD-License
5 // shipped with this file and also available at: https://github.com/seqan/seqan3/blob/master/LICENSE.md
6 // -----------------------------------------------------------------------------------------------------
7 
13 #pragma once
14 
15 #include <iostream>
16 
19 #include <seqan3/version.hpp>
20 
21 namespace seqan3::detail
22 {
23 
37 class format_man : public format_help_base<format_man>
38 {
40  using base_type = format_help_base<format_man>;
41 
43  friend base_type;
44 
45 public:
49  format_man() = default;
50  format_man(format_man const & pf) = default;
51  format_man & operator=(format_man const & pf) = default;
52  format_man(format_man &&) = default;
53  format_man & operator=(format_man &&) = default;
54  ~format_man() = default;
55 
57  format_man(std::vector<std::string> const & names, bool const advanced = false) : base_type{names, advanced} {};
59 
60 private:
62  void print_header()
63  {
65 
66  // Print .TH line.
67  std::cout << ".TH ";
68  std::transform(meta.app_name.begin(),
69  meta.app_name.end(),
70  out,
71  [](unsigned char c)
72  {
73  return std::toupper(c);
74  });
75  std::cout << " " << std::to_string(meta.man_page_section) << " \"" << meta.date << "\" \"";
76  std::transform(meta.app_name.begin(),
77  meta.app_name.end(),
78  out,
79  [](unsigned char c)
80  {
81  return std::tolower(c);
82  });
83  std::cout << " " << meta.version << "\" \"" << meta.man_page_title << "\"\n";
84 
85  // Print NAME section.
86  std::cout << ".SH NAME\n" << meta.app_name << " \\- " << meta.short_description << std::endl;
87  }
88 
92  void print_section(std::string const & title)
93  {
95  std::cout << ".SH ";
96  std::transform(title.begin(),
97  title.end(),
98  out,
99  [](unsigned char c)
100  {
101  return std::toupper(c);
102  });
103  std::cout << "\n";
104  is_first_in_section = true;
105  }
106 
110  void print_subsection(std::string const & title)
111  {
112  std::cout << ".SS " << title << "\n";
113  is_first_in_section = true;
114  }
115 
122  void print_line(std::string const & text, bool const line_is_paragraph)
123  {
124  if (!is_first_in_section && line_is_paragraph)
125  std::cout << ".sp\n";
126  else if (!is_first_in_section && !line_is_paragraph)
127  std::cout << ".br\n";
128 
129  std::cout << text << "\n";
130  is_first_in_section = false;
131  }
132 
142  void print_list_item(std::string const & term, std::string const & desc)
143  {
144  std::cout << ".TP\n" << term << "\n" << desc << "\n";
145  is_first_in_section = false;
146  }
147 
149  void print_footer()
150  {
151  // no footer
152  }
153 
158  std::string in_bold(std::string const & str)
159  {
160  return "\\fB" + str + "\\fR";
161  }
162 
164  bool is_first_in_section{true};
165 };
166 
167 } // namespace seqan3::detail
T begin(T... args)
T end(T... args)
T endl(T... args)
Provides the format_base struct containing all helper functions that are needed in all formats.
@ advanced
Definition: auxiliary.hpp:255
Checks if program is run interactively and retrieves dimensions of terminal (Transferred from seqan2)...
T to_string(T... args)
T transform(T... args)
Provides SeqAn version macros and global variables.