mirror of
https://github.com/rwinkhart/MUTN.git
synced 2026-08-28 04:46:41 -04:00
Strip carriage returns from user input
This commit is contained in:
@@ -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":
|
||||
|
||||
+1
-1
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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
|
||||
}
|
||||
@@ -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)
|
||||
}
|
||||
Reference in New Issue
Block a user