aboutsummaryrefslogtreecommitdiff
path: root/internal/tui/tui.go
diff options
context:
space:
mode:
Diffstat (limited to 'internal/tui/tui.go')
-rw-r--r--internal/tui/tui.go23
1 files changed, 16 insertions, 7 deletions
diff --git a/internal/tui/tui.go b/internal/tui/tui.go
index 47314b6..16cb304 100644
--- a/internal/tui/tui.go
+++ b/internal/tui/tui.go
@@ -44,24 +44,33 @@ type errMsg struct {
}
// New builds the initial model: cfg.Offline drops "pl" from the version
-// list (render.OfflineVersions), the active version starts at
-// cfg.DefaultVersion (falling back to the first version if not found, or
-// "" if there are none), and the date starts at today. The first fetch is
-// issued by Init, not here.
-func New(cfg config.Config) Model {
+// list (render.OfflineVersions). startVersion selects the active version
+// (falling back to cfg.DefaultVersion when ""), still resolved through
+// EffectiveVersions/indexOf so an unavailable version falls back to index 0.
+// startDate selects the starting date (falling back to today when ""). The
+// first fetch is issued by Init, not here.
+func New(cfg config.Config, startDate, startVersion string) Model {
versions := render.EffectiveVersions(append([]string(nil), cfg.Versions...), cfg.Lectionary, cfg.Offline)
- idx := indexOf(versions, cfg.DefaultVersion)
+ if startVersion == "" {
+ startVersion = cfg.DefaultVersion
+ }
+ idx := indexOf(versions, startVersion)
if idx < 0 {
idx = 0
}
idx = clampIndex(idx, len(versions))
+ date := startDate
+ if date == "" {
+ date = time.Now().Format("2006-01-02")
+ }
+
return Model{
cfg: cfg,
versions: versions,
verIdx: idx,
- date: time.Now().Format("2006-01-02"),
+ date: date,
loading: true,
}
}