allow multiline text using three double-quotes (#239)
This commit is contained in:
parent
eadee46840
commit
39bb25d5f6
1 changed files with 19 additions and 0 deletions
19
cmd/cmd.go
19
cmd/cmd.go
|
@ -358,6 +358,9 @@ func generateInteractive(cmd *cobra.Command, model string) error {
|
||||||
}
|
}
|
||||||
defer scanner.Close()
|
defer scanner.Close()
|
||||||
|
|
||||||
|
var multiLineBuffer string
|
||||||
|
var isMultiLine bool
|
||||||
|
|
||||||
for {
|
for {
|
||||||
line, err := scanner.Readline()
|
line, err := scanner.Readline()
|
||||||
switch {
|
switch {
|
||||||
|
@ -376,6 +379,22 @@ func generateInteractive(cmd *cobra.Command, model string) error {
|
||||||
line = strings.TrimSpace(line)
|
line = strings.TrimSpace(line)
|
||||||
|
|
||||||
switch {
|
switch {
|
||||||
|
case isMultiLine:
|
||||||
|
if strings.HasSuffix(line, `"""`) {
|
||||||
|
isMultiLine = false
|
||||||
|
multiLineBuffer += strings.TrimSuffix(line, `"""`)
|
||||||
|
line = multiLineBuffer
|
||||||
|
multiLineBuffer = ""
|
||||||
|
scanner.SetPrompt(">>> ")
|
||||||
|
} else {
|
||||||
|
multiLineBuffer += line + " "
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
case strings.HasPrefix(line, `"""`):
|
||||||
|
isMultiLine = true
|
||||||
|
multiLineBuffer = strings.TrimPrefix(line, `"""`) + " "
|
||||||
|
scanner.SetPrompt("... ")
|
||||||
|
continue
|
||||||
case strings.HasPrefix(line, "/list"):
|
case strings.HasPrefix(line, "/list"):
|
||||||
args := strings.Fields(line)
|
args := strings.Fields(line)
|
||||||
if err := ListHandler(cmd, args[1:]); err != nil {
|
if err := ListHandler(cmd, args[1:]); err != nil {
|
||||||
|
|
Loading…
Reference in a new issue