stegterm/internal/tui/style.go
2026-09-14 11:00:27 +03:00

52 lines
1.7 KiB
Go
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

package tui
import (
"fmt"
"strings"
"github.com/charmbracelet/lipgloss"
)
// Палитра и панель с рамкой — перенесены из burterm без изменений
// (там это была лишь часть большей темы с таб-баром/логотипом; здесь
// переключать нечего — экран один, — так что взято только то, что
// реально используется вкладкой Steganography: рамка вокруг блока
// метаданных).
var (
colorBorder = lipgloss.Color("62") // приглушённый синий/фиолетовый — рамка панели
colorPanelTitle = lipgloss.Color("213") // розовый — заголовок панели
)
var (
panelBorderStyle = lipgloss.NewStyle().
Border(lipgloss.RoundedBorder()).
BorderForeground(colorBorder).
Padding(0, 1)
panelTitleStyle = lipgloss.NewStyle().
Foreground(colorPanelTitle).
Bold(true)
)
// panel оборачивает body в рамку с заголовком первой строкой внутри неё.
func panel(title, body string, width int) string {
if width < 10 {
width = 10
}
content := panelTitleStyle.Render(strings.ToUpper(title)) + "\n" + body
return panelBorderStyle.Width(width).Render(content)
}
// humanBytes форматирует размер в человекочитаемом виде (KiB/MiB/...).
func humanBytes(n uint64) string {
const unit = 1024
if n < unit {
return fmt.Sprintf("%d B", n)
}
div, exp := uint64(unit), 0
for n2 := n / unit; n2 >= unit; n2 /= unit {
div *= unit
exp++
}
return fmt.Sprintf("%.1f %ciB", float64(n)/float64(div), "KMGTPE"[exp])
}