okami.mom/albedo

git clone https://git.nkp.pet/okami.mom/albedo

Aly Raffaufrefactor(tui): replace pick helpers with explicit branches8499f48

main
725 B33 linesraw
1package tui
2
3import "slices"
4
5type Notice struct {
6	Message string
7	Error   bool
8}
9
10type Notices []Notice
11
12func (ns *Notices) Add(msg string, isErr bool) bool {
13	if msg == "" || slices.Contains(*ns, Notice{msg, isErr}) {
14		return false
15	}
16	*ns = append(*ns, Notice{Message: msg, Error: isErr})
17	return true
18}
19
20func (ns *Notices) AddNotice(msg string) bool { return ns.Add(msg, false) }
21func (ns *Notices) AddError(msg string) bool  { return ns.Add(msg, true) }
22func (ns *Notices) Clear()                    { *ns = nil }
23
24func (ns Notices) HasError() bool {
25	return slices.ContainsFunc(ns, func(n Notice) bool { return n.Error })
26}
27
28func (ns Notices) ChromeRows() int {
29	if len(ns) == 0 {
30		return 0
31	}
32	return len(ns) + 1
33}