Strip carriage returns from user input

This commit is contained in:
2024-03-08 12:48:19 -05:00
parent 82b4fbee64
commit edf1a4cd9a
5 changed files with 28 additions and 4 deletions
+8 -2
View File
@@ -1,6 +1,7 @@
package main package main
import ( import (
"fmt"
"github.com/rwinkhart/MUTN/src/cli" "github.com/rwinkhart/MUTN/src/cli"
"github.com/rwinkhart/MUTN/src/offline" "github.com/rwinkhart/MUTN/src/offline"
"os" "os"
@@ -22,7 +23,7 @@ func main() {
if strings.HasPrefix(args[1], "/") { if strings.HasPrefix(args[1], "/") {
// store location of target entry // 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) // entry reader shortcut (if no other arguments are supplied)
if argsCount == 2 { if argsCount == 2 {
@@ -154,11 +155,16 @@ func main() {
case "sync": case "sync":
if !offline.Windows { if !offline.Windows {
cli.SshypSync() // TODO Remove after native sync is implemented cli.SshypSync() // TODO Remove after native sync is implemented
} else {
fmt.Println(offline.AnsiError + "\"sync\" is not yet implemented" + offline.AnsiReset)
} }
os.Exit(0) os.Exit(0)
case "init": case "init":
cli.TempInitCli() 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": case "add":
cli.HelpAdd() cli.HelpAdd()
case "edit": case "edit":
+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
+8
View File
@@ -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
}
+10
View File
@@ -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)
}