all repos — bibel @ 0be549fc2abddcf0f0e574436c2607ed7f844ab0

Unnamed repository; edit this file 'description' to name the repository.

cmd/bibel.go (view raw)

 1package main
 2
 3import (
 4	"fmt"
 5	"os"
 6	"time"
 7
 8	"github.com/alexflint/go-arg"
 9	"golang.org/x/term"
10	"maxwelljensen/bibel/internal"
11	"maxwelljensen/bibel/internal/tui"
12)
13
14// Args defines the command line arguments
15type Args struct {
16	Plain bool `arg:"-p,--plain" help:"output plain text without formatting or TUI"`
17}
18
19// Description returns a description of the program
20func (Args) Description() string {
21	return "Display today's Bible reading from the four Gospels (Matthew, Mark, Luke, John).\n" +
22		"Reads 12 verses per day based on the current date."
23}
24
25func main() {
26	var args Args
27	arg.MustParse(&args)
28
29	// Load Bible data
30	biblePath := "books/pol_nbg.json"
31	bibleData, err := bible.LoadBible(biblePath)
32	if err != nil {
33		fmt.Fprintf(os.Stderr, "Error loading Bible data: %v\n", err)
34		os.Exit(1)
35	}
36
37	// Initialise date progression
38	dateProg := bible.NewDateProgression(bibleData)
39
40	// Get current date
41	currentDate := time.Now()
42
43	// Calculate position for today
44	todayBookmark, err := dateProg.GetPositionForDate(currentDate)
45	if err != nil {
46		fmt.Fprintf(os.Stderr, "Error calculating date position: %v\n", err)
47		os.Exit(1)
48	}
49
50	// If plain mode, just print plain text (no TUI)
51	if args.Plain {
52		formatter := bible.NewFormatter()
53		// In plain mode, we don't print the header
54		fmt.Println(formatter.ExtractAndFormat(bibleData, todayBookmark))
55		return
56	}
57
58	// Check if we're running in a terminal
59	// If not, fall back to formatted output (similar to plain mode but with header)
60	if !term.IsTerminal(int(os.Stdout.Fd())) {
61		formatter := bible.NewFormatter()
62		fmt.Println(formatter.FormatHeader(todayBookmark))
63		fmt.Println(formatter.ExtractAndFormat(bibleData, todayBookmark))
64		return
65	}
66
67	// Create and run TUI program
68	program := tui.CreateTUIProgram(bibleData, todayBookmark, false)
69	if err := program.Start(); err != nil {
70		fmt.Fprintf(os.Stderr, "Error running TUI: %v\n", err)
71		os.Exit(1)
72	}
73}
74