From edf1a4cd9ada605b7a554281c143ddea1320cac6 Mon Sep 17 00:00:00 2001 From: Randall Winkhart Date: Fri, 8 Mar 2024 12:48:19 -0500 Subject: [PATCH] Strip carriage returns from user input --- main.go | 10 ++++++++-- src/cli/edit.go | 2 +- src/cli/utilitiesMisc.go | 2 +- src/offline/targetLocationFormatUNIX.go | 8 ++++++++ src/offline/targetLocationFormatWIN.go | 10 ++++++++++ 5 files changed, 28 insertions(+), 4 deletions(-) create mode 100644 src/offline/targetLocationFormatUNIX.go create mode 100644 src/offline/targetLocationFormatWIN.go diff --git a/main.go b/main.go index 3978de3..0227269 100644 --- a/main.go +++ b/main.go @@ -1,6 +1,7 @@ package main import ( + "fmt" "github.com/rwinkhart/MUTN/src/cli" "github.com/rwinkhart/MUTN/src/offline" "os" @@ -22,7 +23,7 @@ func main() { if strings.HasPrefix(args[1], "/") { // store location of target entry - targetLocation := offline.EntryRoot + offline.PathSeparator + args[1][1:] + targetLocation := offline.TargetLocationFormat(args[1][1:]) // entry reader shortcut (if no other arguments are supplied) if argsCount == 2 { @@ -154,11 +155,16 @@ func main() { case "sync": if !offline.Windows { cli.SshypSync() // TODO Remove after native sync is implemented + } else { + fmt.Println(offline.AnsiError + "\"sync\" is not yet implemented" + offline.AnsiReset) } os.Exit(0) case "init": cli.TempInitCli() - case "tweak": // TODO offline.Tweak(), exit after run + case "tweak": + fmt.Println(offline.AnsiError + "\"tweak\" is not yet implemented" + offline.AnsiReset) + os.Exit(0) + // TODO offline.Tweak() case "add": cli.HelpAdd() case "edit": diff --git a/src/cli/edit.go b/src/cli/edit.go index 8711694..a4ae86f 100644 --- a/src/cli/edit.go +++ b/src/cli/edit.go @@ -130,7 +130,7 @@ func editNote(baseNote []string) ([]string, bool) { note = append(note, scanner.Text()) } - // close the tempFile + // close tempFile tempFile.Close() // return the edited note if it is different from baseNote diff --git a/src/cli/utilitiesMisc.go b/src/cli/utilitiesMisc.go index 59874dd..d240d65 100644 --- a/src/cli/utilitiesMisc.go +++ b/src/cli/utilitiesMisc.go @@ -22,7 +22,7 @@ func input(prompt string) string { fmt.Print("\n" + prompt + " ") reader := bufio.NewReader(os.Stdin) 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 diff --git a/src/offline/targetLocationFormatUNIX.go b/src/offline/targetLocationFormatUNIX.go new file mode 100644 index 0000000..c249e65 --- /dev/null +++ b/src/offline/targetLocationFormatUNIX.go @@ -0,0 +1,8 @@ +//go:build !windows + +package offline + +// TargetLocationFormat returns the target location of an entry formatted for the current platform +func TargetLocationFormat(entryName string) string { + return EntryRoot + PathSeparator + entryName +} diff --git a/src/offline/targetLocationFormatWIN.go b/src/offline/targetLocationFormatWIN.go new file mode 100644 index 0000000..0064bbc --- /dev/null +++ b/src/offline/targetLocationFormatWIN.go @@ -0,0 +1,10 @@ +//go:build windows + +package offline + +import "strings" + +// TargetLocationFormat returns the target location of an entry formatted for the current platform +func TargetLocationFormat(entryName string) string { + return EntryRoot + PathSeparator + strings.ReplaceAll(entryName, "/", PathSeparator) +}