package keylog import ( "fmt" "path/filepath" "regexp" "strings" "time" ) const hourBucketLayout = "2006-01-02-15" var logFilenamePattern = regexp.MustCompile(`^\d{4}-\d{2}-\d{2}-\d{2}\.log$`) func HourBucket(t time.Time) string { return t.Local().Format(hourBucketLayout) } func LogFilename(bucket string) string { return bucket + ".log" } func ValidLogFilename(name string) bool { return logFilenamePattern.MatchString(filepath.Base(name)) } func normalizeWindow(window string) string { window = strings.TrimSpace(window) if window == "" { return "?" } return window } func eventSource(injected bool) string { if injected { return "injected" } return "user" } func sectionHeader(source, window string) string { return fmt.Sprintf("[%s ยท %s]\n", source, normalizeWindow(window)) }