Optimisation & fixes

This commit is contained in:
2026-06-21 12:59:55 +01:00
parent ab65c2e17b
commit d5125a0d62
14 changed files with 1074 additions and 126 deletions
+11 -4
View File
@@ -5,6 +5,7 @@ import (
"os"
"strings"
"sync"
"unicode/utf8"
"github.com/lukaszraczylo/kportal/internal/config"
)
@@ -195,15 +196,21 @@ func hyperlink(url, text string) string {
return fmt.Sprintf("\x1b]8;;%s\x1b\\%s\x1b]8;;\x1b\\", url, text)
}
// truncate truncates a string to maxLen, adding "..." if needed
// truncate truncates a string to maxLen runes, adding "..." if needed.
// It counts and slices by rune (not byte) so multibyte aliases/resource names
// are never cut mid-rune into mojibake.
func truncate(s string, maxLen int) string {
if len(s) <= maxLen {
if maxLen <= 0 {
return ""
}
if utf8.RuneCountInString(s) <= maxLen {
return s
}
r := []rune(s)
if maxLen <= 3 {
return s[:maxLen]
return string(r[:maxLen])
}
return s[:maxLen-3] + "..."
return string(r[:maxLen-3]) + "..."
}
// formatStatusWithIndicator adds color-coded indicator symbols to status