mirror of
https://github.com/rwinkhart/MUTN.git
synced 2026-09-02 07:07:24 -04:00
Strip trailing whitespace from each line in notes before saving
This commit is contained in:
+10
-1
@@ -7,6 +7,7 @@ import (
|
|||||||
"os"
|
"os"
|
||||||
"os/exec"
|
"os/exec"
|
||||||
"reflect"
|
"reflect"
|
||||||
|
"strings"
|
||||||
)
|
)
|
||||||
|
|
||||||
// RenameCli renames an entry at oldLocation to a new location (user input)
|
// RenameCli renames an entry at oldLocation to a new location (user input)
|
||||||
@@ -134,8 +135,16 @@ func editNote(baseNote []string) ([]string, bool) {
|
|||||||
// close tempFile
|
// close tempFile
|
||||||
tempFile.Close()
|
tempFile.Close()
|
||||||
|
|
||||||
|
// remove trailing empty strings from the edited note
|
||||||
|
note = offline.RemoveTrailingEmptyStrings(note)
|
||||||
|
|
||||||
|
// trim trailing whitespace from each note line
|
||||||
|
for i, line := range note {
|
||||||
|
note[i] = strings.TrimRight(line, " \t\r\n")
|
||||||
|
}
|
||||||
|
|
||||||
// return the edited note if it is different from baseNote
|
// return the edited note if it is different from baseNote
|
||||||
if !reflect.DeepEqual(offline.RemoveTrailingEmptyStrings(note), baseNote) {
|
if !reflect.DeepEqual(note, baseNote) {
|
||||||
return note, true
|
return note, true
|
||||||
} else {
|
} else {
|
||||||
return []string{}, false
|
return []string{}, false
|
||||||
|
|||||||
@@ -63,7 +63,7 @@ func inputBinary(prompt string) bool {
|
|||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
|
||||||
// inputMenu prompts the user with a menu and returns the user's choice as an integer
|
// inputMenuGen prompts the user with a menu and returns the user's choice as an integer
|
||||||
func inputMenuGen(prompt string, options []string) int {
|
func inputMenuGen(prompt string, options []string) int {
|
||||||
for i, option := range options {
|
for i, option := range options {
|
||||||
fmt.Printf("%d. %s\n", i+1, option)
|
fmt.Printf("%d. %s\n", i+1, option)
|
||||||
@@ -71,13 +71,14 @@ func inputMenuGen(prompt string, options []string) int {
|
|||||||
return inputInt(prompt, len(options))
|
return inputInt(prompt, len(options))
|
||||||
}
|
}
|
||||||
|
|
||||||
// writeEntryShortcut writes an entry to targetLocation (trimming trailing blank lines) and previews it, or errors if no data is supplied
|
// writeEntryShortcut writes an entry to targetLocation and previews it (errors if no data is supplied)
|
||||||
func writeEntryShortcut(targetLocation string, unencryptedEntry []string, hidePassword bool) {
|
func writeEntryShortcut(targetLocation string, unencryptedEntry []string, hidePassword bool) {
|
||||||
if offline.EntryIsNotEmpty(unencryptedEntry) {
|
if offline.EntryIsNotEmpty(unencryptedEntry) {
|
||||||
trimmedEntry := offline.RemoveTrailingEmptyStrings(unencryptedEntry)
|
// write the entry to the target location
|
||||||
offline.WriteEntry(targetLocation, trimmedEntry)
|
offline.WriteEntry(targetLocation, unencryptedEntry)
|
||||||
|
// preview the entry
|
||||||
fmt.Println(ansiBold + "\nEntry Preview:" + offline.AnsiReset)
|
fmt.Println(ansiBold + "\nEntry Preview:" + offline.AnsiReset)
|
||||||
EntryReader(trimmedEntry, hidePassword, true)
|
EntryReader(unencryptedEntry, hidePassword, true)
|
||||||
} else {
|
} else {
|
||||||
fmt.Println(offline.AnsiError + "No data supplied for entry" + offline.AnsiReset)
|
fmt.Println(offline.AnsiError + "No data supplied for entry" + offline.AnsiReset)
|
||||||
os.Exit(1)
|
os.Exit(1)
|
||||||
|
|||||||
Reference in New Issue
Block a user