Refactor for better modularity (share more code among edit functions, rename "offline" package to "backend"

This commit is contained in:
2024-04-15 18:16:05 -04:00
parent 53e0799a4a
commit 257a698b88
19 changed files with 834 additions and 0 deletions
+37
View File
@@ -0,0 +1,37 @@
//go:build !windows
package backend
import (
"fmt"
"os"
)
const FallbackEditor = "vi" // vi is pre-installed on most UNIX systems
// dirInit creates the libmutton directories
func dirInit() {
// create EntryRoot
err := os.MkdirAll(EntryRoot, 0700)
if err != nil {
fmt.Println(AnsiError + "Failed to create \"" + EntryRoot + "\":" + err.Error() + AnsiReset)
os.Exit(1)
}
// create config directory
err = os.MkdirAll(ConfigDir, 0700)
if err != nil {
fmt.Println(AnsiError + "Failed to create \"" + ConfigDir + "\":" + err.Error() + AnsiReset)
os.Exit(1)
}
}
// textEditorFallback returns the value of the $EDITOR environment variable, or FallbackEditor if it is not set
func textEditorFallback() string {
// ensure textEditor is set
textEditor := os.Getenv("EDITOR")
if textEditor == "" {
textEditor = FallbackEditor
}
return textEditor
}