mirror of
https://github.com/rwinkhart/MUTN.git
synced 2026-08-28 04:46:41 -04:00
Switch to dependence on github.com/rwinkhart/libmutton
This commit is contained in:
+11
-11
@@ -8,8 +8,8 @@ import (
|
||||
"reflect"
|
||||
"strings"
|
||||
|
||||
"github.com/rwinkhart/MUTN/src/backend"
|
||||
"github.com/rwinkhart/MUTN/src/sync"
|
||||
"github.com/rwinkhart/libmutton/core"
|
||||
"github.com/rwinkhart/libmutton/sync"
|
||||
)
|
||||
|
||||
// RenameCli renames an entry at oldLocationIncomplete to a new location (user input) on both the client and the server
|
||||
@@ -24,7 +24,7 @@ func RenameCli(oldLocationIncomplete string) {
|
||||
// EditEntryField edits a field of an entry at targetLocation (user input)
|
||||
func EditEntryField(targetLocation string, hideSecrets bool, field int) {
|
||||
// fetch old entry data (with all required lines present)
|
||||
unencryptedEntry := backend.GetOldEntryData(targetLocation, field)
|
||||
unencryptedEntry := core.GetOldEntryData(targetLocation, field)
|
||||
|
||||
// edit the field
|
||||
switch field {
|
||||
@@ -44,7 +44,7 @@ func EditEntryField(targetLocation string, hideSecrets bool, field int) {
|
||||
// edit the note
|
||||
editedNote, noteEdited := editNote(noteData)
|
||||
if !noteEdited { // exit early if the note was not edited
|
||||
fmt.Println(backend.AnsiError + "Entry is unchanged" + backend.AnsiReset)
|
||||
fmt.Println(core.AnsiError + "Entry is unchanged" + core.AnsiReset)
|
||||
os.Exit(1)
|
||||
}
|
||||
unencryptedEntry = append(nonNoteData, editedNote...)
|
||||
@@ -57,10 +57,10 @@ func EditEntryField(targetLocation string, hideSecrets bool, field int) {
|
||||
// GenUpdate generates a new password for an entry at targetLocation (user input)
|
||||
func GenUpdate(targetLocation string, hideSecrets bool) {
|
||||
// fetch old entry data
|
||||
unencryptedEntry := backend.GetOldEntryData(targetLocation, 0)
|
||||
unencryptedEntry := core.GetOldEntryData(targetLocation, 0)
|
||||
|
||||
// generate a new password
|
||||
unencryptedEntry[0] = backend.StringGen(inputInt("Password length:", -1), inputBinary("Generate a complex (special characters) password?"), 0.2, false)
|
||||
unencryptedEntry[0] = core.StringGen(inputInt("Password length:", -1), inputBinary("Generate a complex (special characters) password?"), 0.2, false)
|
||||
|
||||
// write and preview the modified entry
|
||||
writeEntryCLI(targetLocation, unencryptedEntry, hideSecrets, false)
|
||||
@@ -69,13 +69,13 @@ func GenUpdate(targetLocation string, hideSecrets bool) {
|
||||
// editNote uses the user-specified text editor to edit an existing note (or create a new one if baseNote is empty)
|
||||
// returns the edited note and a boolean indicating whether the note was edited
|
||||
func editNote(baseNote []string) ([]string, bool) {
|
||||
tempFile := backend.CreateTempFile()
|
||||
tempFile := core.CreateTempFile()
|
||||
defer func(name string) {
|
||||
_ = os.Remove(name) // error ignored; if the file could be created, it can probably be removed
|
||||
}(tempFile.Name())
|
||||
|
||||
// fetch the user's text editor
|
||||
editor := backend.ParseConfig([][2]string{{"MUTN", "textEditor"}}, "")[0]
|
||||
editor := core.ParseConfig([][2]string{{"MUTN", "textEditor"}}, "")[0]
|
||||
|
||||
// write baseNote to tempFile (if it is not empty)
|
||||
if len(baseNote) > 0 {
|
||||
@@ -94,13 +94,13 @@ func editNote(baseNote []string) ([]string, bool) {
|
||||
cmd.Stderr = os.Stderr
|
||||
err := cmd.Run()
|
||||
if err != nil {
|
||||
panic(backend.AnsiError + "Failed to write note with " + editor + backend.AnsiReset) // panic is used to ensure the tempFile is removed, as per the defer statement
|
||||
panic(core.AnsiError + "Failed to write note with " + editor + core.AnsiReset) // panic is used to ensure the tempFile is removed, as per the defer statement
|
||||
}
|
||||
|
||||
// open the tempFile for reading
|
||||
tempFile, err = os.Open(tempFile.Name())
|
||||
if err != nil {
|
||||
panic(backend.AnsiError + "Failed to read note written with " + editor + backend.AnsiReset) // panic is used to ensure the tempFile is removed, as per the defer statement
|
||||
panic(core.AnsiError + "Failed to read note written with " + editor + core.AnsiReset) // panic is used to ensure the tempFile is removed, as per the defer statement
|
||||
}
|
||||
|
||||
// read the edited note from the tempFile
|
||||
@@ -114,7 +114,7 @@ func editNote(baseNote []string) ([]string, bool) {
|
||||
_ = tempFile.Close() // error ignored; if the file could be opened, it can probably be closed
|
||||
|
||||
// remove trailing empty strings from the edited note
|
||||
note = backend.RemoveTrailingEmptyStrings(note)
|
||||
note = core.RemoveTrailingEmptyStrings(note)
|
||||
|
||||
// trim trailing whitespace from each note line
|
||||
for i, line := range note {
|
||||
|
||||
Reference in New Issue
Block a user