format.go (1864B)
1 package user 2 3 import ( 4 "fmt" 5 "strings" 6 7 "code.dwrz.net/src/pkg/color" 8 "code.dwrz.net/src/pkg/dqs/stats" 9 ) 10 11 func (u *User) FormatPrint() string { 12 var str strings.Builder 13 14 str.WriteString(color.BrightBlack) 15 str.WriteString("Name: ") 16 str.WriteString(color.Reset) 17 str.WriteString(u.Name) 18 str.WriteString("\n") 19 20 str.WriteString(color.BrightBlack) 21 str.WriteString("Birthday: ") 22 str.WriteString(color.Reset) 23 str.WriteString(u.Birthday.Format("2006-01-02")) 24 str.WriteString("\n") 25 26 str.WriteString(color.BrightBlack) 27 str.WriteString("Units: ") 28 str.WriteString(color.Reset) 29 str.WriteString(fmt.Sprintf("%s", u.Units)) 30 str.WriteString("\n") 31 32 str.WriteString(color.BrightBlack) 33 str.WriteString("Height: ") 34 str.WriteString(color.Reset) 35 str.WriteString(fmt.Sprintf( 36 "%.2f %s", u.UnitHeight(), u.Units.Height()), 37 ) 38 str.WriteString("\n") 39 40 str.WriteString(color.BrightBlack) 41 str.WriteString("Weight: ") 42 str.WriteString(color.Reset) 43 str.WriteString(fmt.Sprintf( 44 "%.2f %s", u.UnitWeight(), u.Units.Weight()), 45 ) 46 str.WriteString("\n") 47 48 str.WriteString(color.BrightBlack) 49 str.WriteString("Body Fat: ") 50 str.WriteString(color.Reset) 51 str.WriteString(fmt.Sprintf( 52 "%.2f%% (%.2f %s)", 53 u.BodyFat, u.UnitBodyFatWeight(), u.Units.Weight(), 54 )) 55 str.WriteString("\n") 56 57 str.WriteString(color.BrightBlack) 58 str.WriteString("BMI: ") 59 str.WriteString(color.Reset) 60 str.WriteString(fmt.Sprintf("%.2f", stats.BMI(u.Height, u.Weight))) 61 str.WriteString("\n") 62 63 str.WriteString(color.BrightBlack) 64 str.WriteString("Diet: ") 65 str.WriteString(color.Reset) 66 str.WriteString(fmt.Sprintf("%s", u.Diet)) 67 str.WriteString("\n") 68 69 str.WriteString(color.BrightBlack) 70 str.WriteString("Target Weight: ") 71 str.WriteString(color.Reset) 72 str.WriteString(fmt.Sprintf( 73 "%.2f %s", u.UnitTargetWeight(), u.Units.Weight(), 74 )) 75 str.WriteString("\n") 76 77 return str.String() 78 }