This repository has been archived on 2026-10-25. You can view files and clone it. You cannot open issues or pull requests or push a commit.
Files
submarine/internal/tui/theme/issues.go
T
Simon FrankenandClaude Opus 5.5 64fe34b5b0 Add read-only git provider
Implement submodule.Provider with the git CLI so submarine reads real
repositories: `submarine [dir]`, with `--mock` for the built-in data.

- Tree reads .gitmodules recursively; Status derives presence, checkout,
  worktree, staged pin, pushed state and pin -> ref resolution from local
  git commands only (no network).
- Concurrent Status calls are bounded by runtime.NumCPU().
- scripts/make-fixture.sh builds a superproject covering every state; the
  integration tests run against it.
- theme.Ago shows "never" for a zero time.
- Docs updated; decisions D14-D16 added.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-21 15:32:21 +02:00

75 lines
1.8 KiB
Go

package theme
import (
"fmt"
"time"
"github.com/charmbracelet/lipgloss"
"submarine/internal/submodule"
)
// IssueWord is the short label for an issue kind shown in the tree.
func IssueWord(k submodule.IssueKind) string {
switch k {
case submodule.IssueMissing:
return "missing"
case submodule.IssueUnpushed:
return "unpushed"
case submodule.IssueConflict:
return "conflict"
case submodule.IssueOffPin:
return "off pin"
default:
return "changed"
}
}
// LevelStyle returns base with the text color (and weight) for a level.
func (t Theme) LevelStyle(l submodule.Level, base lipgloss.Style) lipgloss.Style {
switch l {
case submodule.LevelDanger:
return base.Foreground(t.Danger).Bold(true)
case submodule.LevelWarn:
return base.Foreground(t.Warn)
default:
return base.Foreground(t.Muted)
}
}
// Delta renders ahead/behind counts like "↑1↓2", muted unless the pin is
// unpushed. Empty if both are zero. base is applied to every segment, e.g.
// to keep a row background.
func (t Theme) Delta(p submodule.PinInfo, base lipgloss.Style) string {
var s string
if p.Ahead > 0 {
c := t.Muted
if !p.Pushed {
c = t.Danger
}
s += base.Foreground(c).Render(fmt.Sprintf("%s%d", t.Glyphs.Ahead, p.Ahead))
}
if p.Behind > 0 {
s += base.Foreground(t.Muted).Render(fmt.Sprintf("%s%d", t.Glyphs.Behind, p.Behind))
}
return s
}
// Ago formats a time relative to now, e.g. "5m ago"; the zero time is "never".
func Ago(t time.Time) string {
if t.IsZero() {
return "never"
}
d := time.Since(t)
switch {
case d < time.Minute:
return "just now"
case d < time.Hour:
return fmt.Sprintf("%dm ago", int(d.Minutes()))
case d < 24*time.Hour:
return fmt.Sprintf("%dh ago", int(d.Hours()))
default:
return fmt.Sprintf("%dd ago", int(d.Hours()/24))
}
}