Strip carriage returns from user input

This commit is contained in:
2024-03-08 12:48:19 -05:00
parent 4394020dd2
commit 05a15260fd
2 changed files with 2 additions and 2 deletions
+1 -1
View File
@@ -130,7 +130,7 @@ func editNote(baseNote []string) ([]string, bool) {
note = append(note, scanner.Text()) note = append(note, scanner.Text())
} }
// close the tempFile // close tempFile
tempFile.Close() tempFile.Close()
// return the edited note if it is different from baseNote // return the edited note if it is different from baseNote
+1 -1
View File
@@ -22,7 +22,7 @@ func input(prompt string) string {
fmt.Print("\n" + prompt + " ") fmt.Print("\n" + prompt + " ")
reader := bufio.NewReader(os.Stdin) reader := bufio.NewReader(os.Stdin)
userInput, _ := reader.ReadString('\n') userInput, _ := reader.ReadString('\n')
return strings.TrimRight(userInput, "\n ") // remove trailing newlines and spaces return strings.TrimRight(userInput, "\n\r ") // remove trailing newlines, carriage returns, and spaces
} }
// 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