survey icon indicating copy to clipboard operation
survey copied to clipboard

Show multiline's answer in new line

Open AielloChan opened this issue 3 years ago • 9 comments

Now, it looks wired:

image

How about showing the answer in a new line, just like below:

image

AielloChan avatar Feb 26 '21 12:02 AielloChan

And it just needs to add a \n in the template.

image

https://github.com/AielloChan/survey/commit/44148ffac0f0a13e6031fb046338aff69e01a889

AielloChan avatar Feb 26 '21 13:02 AielloChan

So, any idea?

AielloChan avatar Mar 22 '21 08:03 AielloChan

Thanks for the ping @AielloChan! It's been hard to wrangle all of the different notifications I get so I appreciate your patience.

At the moment, a change like this would be considered a break in the API. survey is used by many large companies who run integration tests and a change like this would inevitably make those fail.

I know its not the answer you or the others want to hear but I dont think we can change this at the moment. I will leave the issue open and tag it for future consideration though!

AlecAivazis avatar Apr 16 '21 19:04 AlecAivazis

Thanks for the ping @AielloChan! It's been hard to wrangle all of the different notifications I get so I appreciate your patience.

At the moment, a change like this would be considered a break in the API. survey is used by many large companies who run integration tests and a change like this would inevitably make those fail.

I know its not the answer you or the others want to hear but I dont think we can change this at the moment. I will leave the issue open and tag it for future consideration though!

Okay, this would be the best choice for now. 😄

AielloChan avatar Apr 30 '21 01:04 AielloChan

I agree with @AielloChan the current behavior bugged me as-well. I am just staring with Go so am I far from being one which could provide any implementation advice nor I fully understand how survey is internally working.

Given the templating engine of Go and an extension of PromptConfig it should be possible to flag this feature. So no integration test on larger companies will break

graugans avatar Apr 11 '22 15:04 graugans

After checking the source code I guess PromptConfig will change the behavior of all prompts. What do you think about this:

From fee69eed1c232b6f3d6f84ac6a5a8f3ceea52f49 Mon Sep 17 00:00:00 2001
From: Christian Ege <[email protected]>
Date: Mon, 11 Apr 2022 18:20:25 +0000
Subject: [PATCH] Proposal for adding a newline after Inputs

Signed-off-by: Christian Ege <[email protected]>
---
 input.go     | 2 ++
 multiline.go | 9 +++++----
 2 files changed, 7 insertions(+), 4 deletions(-)

diff --git a/input.go b/input.go
index dbc7c08..453c6c8 100644
--- a/input.go
+++ b/input.go
@@ -26,6 +26,7 @@ type Input struct {
        options       []core.OptionAnswer
        selectedIndex int
        showingHelp   bool
+       PrintNewline  bool
 }
 
 // data available to the templates when processing
@@ -60,6 +61,7 @@ var InputQuestionTemplate = `
     {{- if and .Suggest }}{{color "cyan"}}{{ print .Config.SuggestInput }} for suggestions{{end -}}
   ]{{color "reset"}} {{end}}
   {{- if .Default}}{{color "white"}}({{.Default}}) {{color "reset"}}{{end}}
+  {{- if .PrintNewline}}{{"\n"}}{{end}}
 {{- end}}`
 
 func (i *Input) onRune(config *PromptConfig) terminal.OnRuneFn {
diff --git a/multiline.go b/multiline.go
index bff9622..a4c4d5a 100644
--- a/multiline.go
+++ b/multiline.go
@@ -8,9 +8,10 @@ import (
 
 type Multiline struct {
        Renderer
-       Message string
-       Default string
-       Help    string
+       Message      string
+       Default      string
+       Help         string
+       PrintNewline bool
 }
 
 // data available to the templates when processing
@@ -32,7 +33,7 @@ var MultilineQuestionTemplate = `
   {{- if .Answer }}{{ "\n" }}{{ end }}
 {{- else }}
   {{- if .Default}}{{color "white"}}({{.Default}}) {{color "reset"}}{{end}}
-  {{- color "cyan"}}[Enter 2 empty lines to finish]{{color "reset"}}
+  {{- color "cyan"}}[Enter 2 empty lines to fonish]{{color "reset"}}{{- if .PrintNewline}}{{"\n"}}{{end}}
 {{- end}}`
 
 func (i *Multiline) Prompt(config *PromptConfig) (interface{}, error) {
-- 
2.30.2

Of course the tests are missing. But would that be something acceptable?

graugans avatar Apr 11 '22 18:04 graugans

I'm running into this styling issue myself as well currently. The solution proposed by @graugans seems like a good option to me. What do you think @AlecAivazis?

silvanbrummen avatar Nov 01 '22 21:11 silvanbrummen

+1

CastawayEGR avatar Nov 05 '22 18:11 CastawayEGR

@AlecAivazis would a PR just adding that missing line break to the go template be acceptable? I don't mind submitting that. I noticed pterm input and some other tools do this so it's only the survey library that I've noticed the multiline editing on the same line happen in. It's a minor "nit" but it's sufficiently jarring to users that I figured I'd see if I could help get this through.

sheldonhull avatar Feb 17 '23 19:02 sheldonhull