feat(ui): home dashboard ala mirador — jam blok, panel judul-di-border, metrik docker+host, navigasi 0/1
CI / test (push) Successful in 10s

This commit is contained in:
oxpoe committed 2026-10-15 09:43:54 +07:00
1 parent fe781591e3
commit 76cdb0b5bb
10 files changed
+641 -66

No files matched your search

+77
View File
@@ -0,0 +1,77 @@
package app
import (
"strings"
"charm.land/lipgloss/v2"
)
// ansiTruncate — potong string ber-ANSI ke lebar tampilan w (sel), aman
// terhadap escape sequence; bila terpotong ditutup reset + "…".
// Dipakai panel() agar konten tidak pernah wrap (tinggi panel tetap).
func ansiTruncate(s string, w int) string {
if w <= 0 {
return ""
}
if lipgloss.Width(s) <= w {
return s
}
const (
stNormal = iota
stEsc
stCSI
stOSC
stOSCEsc
)
state := stNormal
width := 0
var b strings.Builder
for _, r := range s {
switch state {
case stNormal:
if r == 0x1b {
state = stEsc
b.WriteRune(r)
continue
}
if width >= w-1 { // sisakan satu sel untuk "…"
b.WriteString("\x1b[0m…")
return b.String()
}
b.WriteRune(r)
width++
case stEsc:
b.WriteRune(r)
switch {
case r == '[':
state = stCSI
case r == ']':
state = stOSC
case r >= 0x20 && r <= 0x2f:
// intermediate — tunggu final byte
default:
state = stNormal
}
case stCSI:
b.WriteRune(r)
if r >= 0x40 && r <= 0x7e {
state = stNormal
}
case stOSC:
b.WriteRune(r)
if r == 0x07 {
state = stNormal
} else if r == 0x1b {
state = stOSCEsc
}
case stOSCEsc:
b.WriteRune(r)
if r == '\\' {
state = stNormal
} else {
state = stOSC
}
}
}
return b.String()
}