clikt
clikt copied to clipboard
Wrapping text in echo
Consider that I want to wrap some text to a fixed number of characters regardless of any other mechanisms to determine the width. Currently, I have to implement my own wrapText method and create an own formatter.
Proposal: Would it be possible to have an optional wrapText: Int
parameter for echo
which specifies a different wrapping width? Or maybe just make wrapText()
available outside of the module?
If you're looking to set the wrap width for all text in a command, you can pass width
to the constructor of ClicktHelpformatter
. If you want to wrap a specific paragraph of help output manually, you can preformat paragraphs by surrounding them with ```
like you would with markdown.
It's only for a specific line of output. For simplicity, let's say I want to make an error message error
stand out by making it look like a quote. Therefore, I would have some output in the command with echo and only in that snippet I want to use a different width. Unfortunately, I do not know the text of the error message (maybe it's a thrown exception), so I can't preformat them without implementing an own wrapText.
Example:
// within one Command's run-method
echo("Some very long text that wraps just okay")
// I want this to wrap at, let's say width 60
println(error.wrapText(60).padStart(10, ' '))
// it would be much better not to have to implement wrapText in this case but being able to do
echo(error.padStart(10, ' '), wrapText = 70)
echo("Some very long text that wraps just okay")
Clikt by default will attempt to determine the width of the current terminal window and wrap to that width.
Do you actually want to wrap to a specific width, or just wrap to the same width as the help output?
Well, yes, and that's great in most cases. But in this case my intention really is to wrap to a specific width. Hence, the question whether it would be possible to have an optional argument or even just a wrapText method provided outside of the module.
The 4.0 release use mordant, so you can use any mordant widget to format text as desired.