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 var unencryptedEntry []string
if !isNote { if !isNote {
username := input("Username: ") username := input("Username:")
password := inputHidden("Password: ") password := inputHidden("Password:")
url := input("URL: ") url := input("URL:")
// TODO prompt for optional note if inputBinary("Add a note to this entry?") {
unencryptedEntry = []string{password, username, url} note := newNote()
unencryptedEntry = append([]string{password, username, url}, note...)
} else {
unencryptedEntry = []string{password, username, url}
}
} else { } else {
note := newNote() note := newNote()
unencryptedEntry = append([]string{"", "", ""}, note...) 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 // input prompts the user for input and returns the input as a string
func input(prompt string) string { func input(prompt string) string {
fmt.Print("\n" + prompt) fmt.Print("\n" + prompt + " ")
var input string var input string
fmt.Scanln(&input) fmt.Scanln(&input)
return 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 // inputHidden prompts the user for input and returns the input as a string, hiding the input from the terminal
func inputHidden(prompt string) string { func inputHidden(prompt string) string {
fmt.Print("\n" + prompt) fmt.Print("\n" + prompt + " ")
byteInput, _ := terminal.ReadPassword(int(os.Stdin.Fd())) byteInput, _ := terminal.ReadPassword(int(os.Stdin.Fd()))
password := string(byteInput) password := string(byteInput)
fmt.Println() fmt.Println()
return password 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 // newNote uses the user-specified text editor to create a new note and returns the note as a slice of strings
func newNote() []string { func newNote() []string {
tempFile := offline.CreateTempFile() tempFile := offline.CreateTempFile()