Closed PierreKieffer closed 2 years ago
So, my mistake. After exploring the code, the method does exist via the Editor. You must pass a default value and set the AppendDefault bool to true. This method allows to open the editor (vim by default) and edit the default text value.
func Edit() error {
content := ""
var menu = &survey.Editor{
Message: "Edit : ",
FileName: "*.json",
Default: `{"foo" : "bar"}`,
AppendDefault: true,
}
err := survey.AskOne(menu, &content)
if err != nil {
return err
}
fmt.Println(content)
return nil
}
I would like to modify data that already exists. One solution would be to write this data to a temporary file and open it via the survey.Editor method, Is there a way to do this ?
Something like :
prompt := &survey.Editor{ Message: "Shell code snippet", FileName: "*.sh", DefaultContent : "foobar", }
And when the temp file is opened in text editor, the file is pre filled with
DefaultContent
Or maybe there is another solution to edit something as input? thanks in advance