stream.place chat terminal ui

added colors

+11 -4
+11 -4
beeper.go
··· 15 15 "github.com/gopxl/beep" 16 16 "github.com/gopxl/beep/speaker" 17 17 "github.com/gopxl/beep/wav" 18 + "hash/fnv" 18 19 "log/slog" 19 20 "os" 20 21 "time" ··· 63 64 np, 64 65 tp, 65 66 } 66 - fmt.Println("starting!!") 67 67 go consumeLoop(context.Background(), ns) 68 68 ns.tp.Run() 69 69 } ··· 216 216 } 217 217 218 218 func (m model) View() string { 219 - s := "" 219 + s := "\n" 220 220 for _, record := range m.records { 221 221 str := "invalid handle" 222 222 if record.handle != nil { 223 223 str = fmt.Sprintf("%s ", *record.handle) 224 224 } 225 - bold := lipgloss.NewStyle().Bold(true) 226 - 225 + bold := lipgloss.NewStyle().Bold(true).Foreground(lipgloss.Color(hashStringToColor(str))) 227 226 bdy := "" 228 227 if record.text != nil { 229 228 bdy = fmt.Sprintf("%s", *record.text) ··· 232 231 } 233 232 return s 234 233 } 234 + 235 + func hashStringToColor(s string) string { 236 + h := fnv.New32a() 237 + h.Write([]byte(s)) 238 + ui := h.Sum32() 239 + guess := fmt.Sprintf("#%06x", ui) 240 + return guess[0:7] 241 + }