1// SPDX-FileCopyrightText: Amolith <amolith@secluded.site>
2//
3// SPDX-License-Identifier: AGPL-3.0-or-later
4
5// Package ui provides lipgloss styles for terminal output.
6package ui
7
8import (
9 "os"
10 "time"
11
12 "github.com/charmbracelet/lipgloss"
13)
14
15// Terminal output styles using ANSI colors for broad compatibility.
16var (
17 Success = lipgloss.NewStyle().Foreground(lipgloss.Color("2")) // green
18 Warning = lipgloss.NewStyle().Foreground(lipgloss.Color("3")) // yellow
19 Error = lipgloss.NewStyle().Foreground(lipgloss.Color("1")) // red
20 Muted = lipgloss.NewStyle().Foreground(lipgloss.Color("8")) // gray
21 Bold = lipgloss.NewStyle().Bold(true)
22)
23
24// dateFormat holds the date format string derived from locale.
25var dateFormat = initDateFormat()
26
27// initDateFormat determines the date format based on LC_TIME or LANG.
28func initDateFormat() string {
29 locale := os.Getenv("LC_TIME")
30 if locale == "" {
31 locale = os.Getenv("LANG")
32 }
33
34 // US English uses month-first; most other locales use day-first or ISO
35 switch {
36 case len(locale) >= 2 && locale[:2] == "en" && len(locale) >= 5 && locale[3:5] == "US":
37 return "01/02/2006"
38 case len(locale) >= 2 && locale[:2] == "en":
39 return "02/01/2006"
40 default:
41 return "2006-01-02" // ISO 8601 as sensible default
42 }
43}
44
45// FormatDate formats a time.Time as a date string using the user's locale.
46func FormatDate(t time.Time) string {
47 return t.Format(dateFormat)
48}