Allow optionally adding notes to new password entries

This commit is contained in:
2024-03-07 12:01:49 -05:00
parent 14b3d7bd45
commit 56ffe7e36f
2 changed files with 22 additions and 7 deletions
+9 -5
View File
@@ -17,11 +17,15 @@ func AddEntry(targetLocation string, hidePassword bool, isNote bool) {
var unencryptedEntry []string
if !isNote {
username := input("Username: ")
password := inputHidden("Password: ")
url := input("URL: ")
// TODO prompt for optional note
unencryptedEntry = []string{password, username, url}
username := input("Username:")
password := inputHidden("Password:")
url := input("URL:")
if inputBinary("Add a note to this entry?") {
note := newNote()
unencryptedEntry = append([]string{password, username, url}, note...)
} else {
unencryptedEntry = []string{password, username, url}
}
} else {
note := newNote()
unencryptedEntry = append([]string{"", "", ""}, note...)
+13 -2
View File
@@ -11,7 +11,7 @@ import (
// input prompts the user for input and returns the input as a string
func input(prompt string) string {
fmt.Print("\n" + prompt)
fmt.Print("\n" + prompt + " ")
var input string
fmt.Scanln(&input)
return input
@@ -19,13 +19,24 @@ func input(prompt string) string {
// inputHidden prompts the user for input and returns the input as a string, hiding the input from the terminal
func inputHidden(prompt string) string {
fmt.Print("\n" + prompt)
fmt.Print("\n" + prompt + " ")
byteInput, _ := terminal.ReadPassword(int(os.Stdin.Fd()))
password := string(byteInput)
fmt.Println()
return password
}
// inputBinary prompts the user with a yes/no question and returns the response as a boolean
func inputBinary(prompt string) bool {
reader := bufio.NewReader(os.Stdin)
fmt.Print("\n" + prompt + " (y/N) ")
char, _, _ := reader.ReadRune()
if char == 'y' || char == 'Y' {
return true
}
return false
}
// newNote uses the user-specified text editor to create a new note and returns the note as a slice of strings
func newNote() []string {
tempFile := offline.CreateTempFile()