Android-cuttlefish cvd tool
help_format.h
Go to the documentation of this file.
1/*
2 * Copyright (C) 2026 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17#pragma once
18
19#include <stddef.h>
20
21#include <string>
22#include <vector>
23
25
26namespace cuttlefish {
27
28constexpr size_t kDefaultMaxLineWidth = 80;
29
31 public:
32 static HelpParagraph Raw(std::string text);
33
34 explicit HelpParagraph(std::string);
35
36 std::string Formatted(size_t max_line_width) const;
37
38 private:
39 enum class Style {
40 Wrapped,
41 Raw,
42 };
43
44 HelpParagraph(std::string, Style style);
45
46 std::string text_;
48};
49
50// Formats text (typically a command description) to be displayed in the
51// terminal. Each string in the input is considered to be a different paragraph
52// and should not contain line changes. Each paragraph will be broken into lines
53// of at most max_line_width columns without splitting individual words. An
54// empty line will be added after each paragraph.
55std::string FormatHelpText(const std::vector<HelpParagraph>& text,
56 size_t max_line_width = kDefaultMaxLineWidth);
57
58// Formats the help messages of a list of flags to be displayed in the terminal.
59// The return string will contain lines of at most max_line_width characters
60// except when necessary to avoid splitting a word.
61std::string FormatFlagsHelp(const std::vector<Flag>& flags,
62 size_t max_line_width = kDefaultMaxLineWidth);
63} // namespace cuttlefish
Definition: help_format.h:30
Style style_
Definition: help_format.h:47
std::string Formatted(size_t max_line_width) const
Definition: help_format.cpp:74
std::string text_
Definition: help_format.h:46
static HelpParagraph Raw(std::string text)
Definition: help_format.cpp:65
Style
Definition: help_format.h:39
HelpParagraph(std::string)
Definition: help_format.cpp:69
static const char *const text[]
Definition: ext2_err.c:10
Definition: alloc_driver.h:20
std::string FormatHelpText(const std::vector< HelpParagraph > &text, size_t max_line_width)
Definition: help_format.cpp:83
std::string FormatFlagsHelp(const std::vector< Flag > &flags, size_t max_line_width)
Definition: help_format.cpp:93
constexpr size_t kDefaultMaxLineWidth
Definition: help_format.h:28