manifoldco / promptui

Interactive prompt for command-line applications
https://www.manifold.co
BSD 3-Clause "New" or "Revised" License
6.03k stars 333 forks source link

Left padding Label to achieve Right align #142

Closed wakatara closed 4 years ago

wakatara commented 4 years ago

Is there a way to left pad (with spaces) the Label field to get a right justified prompts of all questions?

With the Label field I am currently iterating through a loop and calling prompui each time and passing a variable name to the Label :

func askThingy(thing string) {
    validate := func(input string) error {
        err := !!(strings.ContainsAny(input, "yns") || input == "")
        if err != false {
            return errors.New("Must be [y/n/s/⏎]")
        }
        return nil
    }

    prompt := promptui.Prompt{
        Label:    thing + " [y/n/s/⏎]",
        Validate: validate,
    }

Obvious things I tried did not work (but now I say that I assume I can write in a pad variable that calculates the offset from the length of the thing string to achieve that effect.

Is there any other way though that you would recommend that is more idiomatic of the library (or built-in)?

wakatara commented 4 years ago

I ended up writing my own prompt from scratch because this seemed way more complex to get sorted with the API.. It's a great library though. Thanks for all your hard work.