stream.place chat terminal ui

added colors

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