Files
千川白浪 c1b33c9c4f refactor(app): isolate native macOS adapters
Route generic App and CLI code through lifecycle and driver models. Move native macOS detail, create, settings and legacy flows into explicit files, share progress and redaction through host, and enforce the boundary with a file-scoped architecture ratchet.
2026-11-30 11:18:09 -07:00

43 lines
1.0 KiB
Go

package host
import (
"regexp"
"strconv"
"strings"
)
var (
ctlPercentRE = regexp.MustCompile(`^(.+?): (\d{1,3})% of (\d+(?:\.\d+)?) (MB|GB)$`)
ctlSizeRE = regexp.MustCompile(`^(.+?): (\d+(?:\.\d+)?) (MB|GB)$`)
)
func sizeBytes(num, unit string) int64 {
f, err := strconv.ParseFloat(num, 64)
if err != nil {
return 0
}
if unit == "GB" {
return int64(f * 1e9)
}
return int64(f * 1e6)
}
func ParseCtlLine(line string) (u Update, ok bool) {
line = strings.TrimSpace(line)
if line == "" {
return Update{}, false
}
if m := ctlPercentRE.FindStringSubmatch(line); m != nil {
pct, _ := strconv.Atoi(m[2])
if pct > 100 {
pct = 100
}
total := sizeBytes(m[3], m[4])
return Update{Kind: KindProgress, Step: m[1], Done: total * int64(pct) / 100, Total: total, Percent: float64(pct)}, true
}
if m := ctlSizeRE.FindStringSubmatch(line); m != nil {
return Update{Kind: KindProgress, Step: m[1], Done: sizeBytes(m[2], m[3]), Percent: -1}, true
}
return Update{Kind: KindNote, Message: line, Percent: -1}, true
}