Trim placeholder from input via InputFromEditor
This commit is contained in:
parent
ca45159ec3
commit
6465ce5146
@ -3,6 +3,7 @@ package cli
|
|||||||
import (
|
import (
|
||||||
"os"
|
"os"
|
||||||
"os/exec"
|
"os/exec"
|
||||||
|
"strings"
|
||||||
)
|
)
|
||||||
|
|
||||||
// InputFromEditor retrieves user input by opening an editor (one specified by
|
// InputFromEditor retrieves user input by opening an editor (one specified by
|
||||||
@ -34,8 +35,15 @@ func InputFromEditor(placeholder string, pattern string) (string, error) {
|
|||||||
bytes, _ := os.ReadFile(msgFile.Name())
|
bytes, _ := os.ReadFile(msgFile.Name())
|
||||||
content := string(bytes)
|
content := string(bytes)
|
||||||
|
|
||||||
if content == placeholder {
|
if placeholder != "" {
|
||||||
return "", nil
|
if content == placeholder {
|
||||||
|
return "", nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// strip placeholder if content begins with it
|
||||||
|
if strings.HasPrefix(content, placeholder) {
|
||||||
|
content = content[len(placeholder):]
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return content, nil
|
return content, nil
|
||||||
|
Loading…
Reference in New Issue
Block a user