add makefile

This commit is contained in:
Adem Baccara
2025-08-17 15:36:32 +01:00
parent bd658e9c7b
commit 59845a359f
16 changed files with 445 additions and 46 deletions
+76 -9
View File
@@ -1,23 +1,28 @@
package ui
import (
"github.com/gdamore/tcell/v2"
"github.com/rivo/tview"
"strings"
"time"
"github.com/gdamore/tcell/v2"
"github.com/rivo/tview"
)
type AppHeader struct {
*tview.Flex
version string
repoURL string
version string
buildTime string
gitCommit string
repoURL string
}
func NewAppHeader(version, repoURL string) *AppHeader {
func NewAppHeader(version, gitCommit, buildTime, repoURL string) *AppHeader {
header := &AppHeader{
Flex: tview.NewFlex(),
version: version,
repoURL: repoURL,
Flex: tview.NewFlex(),
version: version,
repoURL: repoURL,
buildTime: buildTime,
gitCommit: gitCommit,
}
header.build()
return header
@@ -57,7 +62,24 @@ func (h *AppHeader) buildCenterSection(bg tcell.Color) *tview.TextView {
SetDynamicColors(true).
SetTextAlign(tview.AlignCenter)
center.SetBackgroundColor(bg)
center.SetText("[black:#2ECC71::b] " + h.version + " [-] [black:#3B82F6::b] TUI [-]")
commit := shortCommit(h.gitCommit)
// Build tag-like chips for version, commit, and build time
versionTag := makeTag(h.version, "#22C55E") // green
commitTag := ""
if commit != "" {
commitTag = makeTag(commit, "#A78BFA") // violet
}
timeTag := makeTag(formatBuildTime(h.buildTime), "#3B82F6") // blue
text := versionTag
if commitTag != "" {
text += " " + commitTag
}
text += " " + timeTag
center.SetText(text)
return center
}
@@ -77,3 +99,48 @@ func (h *AppHeader) createSeparator() *tview.TextView {
separator.SetText("[#444444]" + strings.Repeat("─", 200) + "[-]")
return separator
}
// shortCommit returns first 7 chars of commit if it looks valid; otherwise empty string.
func shortCommit(c string) string {
c = strings.TrimSpace(c)
if c == "" || c == "unknown" || c == "(devel)" {
return ""
}
if len(c) > 7 {
return c[:7]
}
return c
}
// formatBuildTime tries to parse common time formats and returns a concise human-readable string.
func formatBuildTime(s string) string {
s = strings.TrimSpace(s)
if s == "" {
return "unknown"
}
layouts := []string{
"2006-01-02 15:04:05",
time.RFC3339,
time.RFC1123,
time.RFC1123Z,
}
var t time.Time
var err error
for _, l := range layouts {
t, err = time.Parse(l, s)
if err == nil {
return t.Format("Mon, 02 Jan 2006 15:04")
}
}
return s
}
// makeTag returns a rectangular-looking colored chip for the given text.
func makeTag(text, bg string) string {
text = strings.TrimSpace(text)
if text == "" {
return ""
}
return "[black:" + bg + "::b] " + text + " [-]"
}