-
Notifications
You must be signed in to change notification settings - Fork 47
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Support for tabs and hanging indent #211
Comments
Hi @cmcqueen That's a great use case! We do have some support for this already via the That is, you can do this kind of indentation by first constructing the pub fn main() {
let options = vec![
(
'i',
"filename",
"Input file. ELF, PE (portable executable) object file formats are accepted.",
),
(
'o',
"filename",
"Output file. Binary, Intel hex or Motorola hex file formats are accepted.",
),
(
'v',
"int",
"Verbosity level. Set to 42 to receive more output than you ever wanted.",
),
];
for (short, param, help) in &options {
let left_column = format!("-{} <{}>", short, param);
// Adjust 20 as needed, perhaps compute it from the longest parameter name
let initial_indent = format!("{:1$}", left_column, 20);
let subsequent_indent = " ".repeat(20);
let wrapper = textwrap::Wrapper::new(65) // 65 is your line width
.initial_indent(&initial_indent)
.subsequent_indent(&subsequent_indent);
println!("{}", wrapper.fill(help));
}
} If you want to be more careful, you should measure the length of the strings using the unicode-width crate, just like textwrap does internally. Does this help? By the way, crates like clap already do this kind of formatting for you. |
Having written the code above, I realize that it could be useful to ship a utility function that does this kind of thing. |
Thanks, I guess they're not so easy to find in the documentation, since one doesn't find them on the main page, but has to follow the |
Thanks, that's good feedback! I think I need a Features section somewhere on the first page you see in the documentation. Like this: Features
I'll keep the issue open so I remember to update the documentation like this before the next release. |
The use case I'm thinking of is for a command-line program describing its options. Eg
The text was updated successfully, but these errors were encountered: