summaryrefslogtreecommitdiff
path: root/internal/config
diff options
context:
space:
mode:
authorLukasz Kasprzak <lukas@labunix.xyz>2026-07-24 11:29:57 +0200
committerLukasz Kasprzak <lukas@labunix.xyz>2026-07-24 11:29:57 +0200
commita26fed000ad9f292618f9cecfd2b505dddfd004a (patch)
tree3b6001cc5a20c3451677773159553aa134d4a6c9 /internal/config
parente50b003d84b091b60c8028468edc633f04e39731 (diff)
downloadlectio-a26fed000ad9f292618f9cecfd2b505dddfd004a.tar.gz
lectio-a26fed000ad9f292618f9cecfd2b505dddfd004a.zip
books: language-scoped --ref/--list via customizable books.toml + sigla_style config; v0.7.0
Diffstat (limited to 'internal/config')
-rw-r--r--internal/config/config.go47
-rw-r--r--internal/config/config.toml1
-rw-r--r--internal/config/config_test.go21
3 files changed, 68 insertions, 1 deletions
diff --git a/internal/config/config.go b/internal/config/config.go
index 616af97..8ee15e1 100644
--- a/internal/config/config.go
+++ b/internal/config/config.go
@@ -24,7 +24,7 @@ var seedTOML []byte
// Version is lectio's release version, shared by every binary's
// -v/--version output (lectio, lectio-ui, lectio-web).
-const Version = "0.6.0"
+const Version = "0.7.0"
// validVersions are the five scripture versions lectio understands.
var validVersions = map[string]bool{
@@ -92,6 +92,20 @@ func NormalizeUILanguage(lang string) string {
return l
}
+// NormalizeSiglaStyle maps a sigla_style setting to one of "auto", "polish",
+// "english"; anything unrecognised (incl. "") falls back to "auto". Accepts the
+// short aliases "pl"/"en" for convenience.
+func NormalizeSiglaStyle(s string) string {
+ switch strings.ToLower(strings.TrimSpace(s)) {
+ case "polish", "pl":
+ return "polish"
+ case "english", "en":
+ return "english"
+ default:
+ return "auto"
+ }
+}
+
// Config holds lectio's user-configurable settings.
type Config struct {
SchemaVersion int `toml:"schema_version"`
@@ -103,6 +117,7 @@ type Config struct {
All bool `toml:"all"`
Offline bool `toml:"offline"`
UILanguage string `toml:"ui_language"`
+ SiglaStyle string `toml:"sigla_style"`
WebTheme string `toml:"web_theme"`
WebPort int `toml:"web_port"`
WebDisplay string `toml:"web_display"`
@@ -122,6 +137,23 @@ func (c Config) PartShown(lectionary, partID string) bool {
return true
}
+// SiglaLang resolves the book dialect (a books.toml section code, "en"/"pl")
+// that `lectio --ref`/`--list` use: the explicit sigla_style, or -- when "auto"
+// -- the UI language.
+func (c Config) SiglaLang() string {
+ switch c.SiglaStyle {
+ case "polish":
+ return "pl"
+ case "english":
+ return "en"
+ default:
+ if c.UILanguage == "pl" {
+ return "pl"
+ }
+ return "en"
+ }
+}
+
// Default returns lectio's built-in configuration, used when no config file
// is found and as the base that a partial config file overrides.
func Default() Config {
@@ -135,6 +167,7 @@ func Default() Config {
All: false,
Offline: false,
UILanguage: "en",
+ SiglaStyle: "auto",
WebTheme: "transfiguration",
WebPort: 0,
WebDisplay: "horizontal",
@@ -159,6 +192,17 @@ func configPath() (path string, isDefault bool, err error) {
return filepath.Join(dir, "lectio", "config.toml"), true, nil
}
+// BooksPath returns the path to the optional user books.toml (in the same
+// directory as the config file). There is no embedded seed on disk -- absence
+// means "use the built-in defaults".
+func BooksPath() (string, error) {
+ p, _, err := configPath()
+ if err != nil {
+ return "", err
+ }
+ return filepath.Join(filepath.Dir(p), "books.toml"), nil
+}
+
// seedIfMissing writes the embedded default config to path if nothing is
// there yet.
func seedIfMissing(path string) error {
@@ -208,6 +252,7 @@ func Load() (Config, error) {
}
cfg.WebDisplay = NormalizeDisplay(cfg.WebDisplay)
cfg.UILanguage = NormalizeUILanguage(cfg.UILanguage)
+ cfg.SiglaStyle = NormalizeSiglaStyle(cfg.SiglaStyle)
if err := validate(cfg); err != nil {
return Config{}, err
diff --git a/internal/config/config.toml b/internal/config/config.toml
index 656ddc5..8324032 100644
--- a/internal/config/config.toml
+++ b/internal/config/config.toml
@@ -7,6 +7,7 @@ width = 0 # CLI wrap width; 0 = detect terminal
all = false # default to all parts (true) or just the gospel (false)
offline = false # true = never fetch; read only harvested sigla + cache
ui_language = "en" # interface language (labels/keybar/banner): "en" or "pl". Readings stay source-language.
+sigla_style = "auto" # citation dialect for `lectio --ref`/`--list`: "auto" (follow ui_language), "polish" (J 3,16), or "english" (Jn 3:16)
web_theme = "transfiguration" # default lectio-web theme (built-in order/season name, or a user theme in ~/.config/lectio/themes/)
web_port = 0 # lectio-web port; 0 = try 1099, then any free port
web_display = "horizontal" # default lectio-web layout ("uklad"): "horizontal" (stacked), "vertical" (columns), "interlinear" (verse-by-verse)
diff --git a/internal/config/config_test.go b/internal/config/config_test.go
index a72383b..cc0c941 100644
--- a/internal/config/config_test.go
+++ b/internal/config/config_test.go
@@ -178,6 +178,27 @@ func TestPagerLoadsSetting(t *testing.T) {
}
}
+func TestSiglaStyleDefaultsAndDialect(t *testing.T) {
+ if got := Default().SiglaStyle; got != "auto" {
+ t.Errorf("default SiglaStyle=%q want auto", got)
+ }
+ cases := []struct{ style, ui, want string }{
+ {"auto", "en", "en"},
+ {"auto", "pl", "pl"},
+ {"polish", "en", "pl"},
+ {"english", "pl", "en"},
+ }
+ for _, c := range cases {
+ cfg := Config{SiglaStyle: NormalizeSiglaStyle(c.style), UILanguage: c.ui}
+ if got := cfg.SiglaLang(); got != c.want {
+ t.Errorf("SiglaLang(style=%q,ui=%q)=%q want %q", c.style, c.ui, got, c.want)
+ }
+ }
+ if NormalizeSiglaStyle("nonsense") != "auto" {
+ t.Error("unknown sigla_style should normalize to auto")
+ }
+}
+
func TestPartShown(t *testing.T) {
var empty Config
if !empty.PartShown("new", "psalm") {