User config, custom journal dir

This commit is contained in:
2026-07-24 15:35:56 +09:30
parent b483ea2b26
commit f2d61cd4f6
4 changed files with 111 additions and 10 deletions
+18 -10
View File
@@ -15,10 +15,23 @@ import (
"charm.land/bubbles/v2/textarea"
tea "charm.land/bubbletea/v2"
"charm.land/lipgloss/v2"
"code.ppl.town/justin/journal/config"
)
func main() {
p := tea.NewProgram(initialModel())
cfg, created, err := config.LoadOrCreate()
if err != nil {
fmt.Printf("could not get config: %s", err.Error())
os.Exit(1)
}
if created {
cp, _ := config.Path()
fmt.Printf("configuration created at '%s' - please check and re-run\n", cp)
os.Exit(0)
}
p := tea.NewProgram(initialModel(cfg))
if _, err := p.Run(); err != nil {
log.Fatal(err)
@@ -43,13 +56,8 @@ type model struct {
transientMsgs []transientMsg
}
func getWriter() (WriteSeekCloser, error) {
hd, err := os.UserHomeDir()
if err != nil {
return nil, err
}
fp := filepath.Join(hd, "journal")
func getWriter(cfg config.Config) (WriteSeekCloser, error) {
fp := cfg.JournalDir
fpS, err := os.Stat(fp)
if err != nil {
return nil, err
@@ -67,7 +75,7 @@ func getWriter() (WriteSeekCloser, error) {
return file, nil
}
func initialModel() model {
func initialModel(cfg config.Config) model {
ti := textarea.New()
ti.Placeholder = "What's happening Peter ..."
ti.SetVirtualCursor(false)
@@ -77,7 +85,7 @@ func initialModel() model {
ti.SetHeight(20)
ti.SetWidth(80)
fh, err := getWriter()
fh, err := getWriter(cfg)
if err != nil {
panic(err)
}