package main import ( "citrons.xyz/talk/tui" "citrons.xyz/talk/proto" "fmt" ) type nameChangeMsg struct { index int uid string oldName string newName string } type userStatusMsg struct { index int uid string username string status string } type whoMsg struct { index int uid string username string status string isGone bool } func (m nameChangeMsg) Id() string { return fmt.Sprintf("name change.%d", m.index) } func (m userStatusMsg) Id() string { return fmt.Sprintf("user status.%d", m.index) } func (m whoMsg) Id() string { return fmt.Sprintf("who.%d", m.index) } func (m nameChangeMsg) Show(odd bool) { tui.Push("", tui.Box {Width: tui.Fill, Height: tui.TextSize}) tui.Text("nick: ", &tui.Style { Fg: tui.BrightBlack, Bg: colorDefault[odd], }) tui.Text(m.oldName, &tui.Style { Fg: tui.White, Bg: colorDefault[odd], Italic: true, }) tui.Text(" -> ", &tui.Style { Fg: tui.BrightBlack, Bg: colorDefault[odd], }) tui.Text(m.newName, &tui.Style { Fg: tui.White, Bg: colorDefault[odd], Bold: true, }) tui.Pop() } func (m userStatusMsg) Show(odd bool) { tui.Push("", tui.Box {Width: tui.Fill, Height: tui.TextSize}) tui.Text("status: ", &tui.Style { Fg: tui.BrightBlack, Bg: colorDefault[odd], }) tui.Text(m.username, &tui.Style { Fg: tui.White, Bg: colorDefault[odd], Bold: true, }) tui.Text(" : ", &tui.Style { Fg: tui.BrightBlack, Bg: colorDefault[odd], }) tui.Text(m.status, nil) tui.Pop() } func (m whoMsg) Show(odd bool) { tui.Push("", tui.Box { Width: tui.Fill, Height: tui.Children, Dir: tui.Right, Style: &tui.Style {Bg: colorCmd[odd], Fg: tui.White}, }) tui.Push("", tui.Box {Width: tui.TextSize, Height: tui.TextSize}) tui.Text("* ", nil) tui.Pop() tui.Push("", tui.Box {Width: tui.Fill, Height: tui.TextSize}) tui.Text(m.username, &tui.Style { Fg: tui.White, Bg: colorCmd[odd], Bold: true, }) tui.Text(" : ", nil) if m.status != "" { tui.Text(m.status, nil) } else { var text string if m.isGone { text = "gone" } else { text = "no status" } tui.Text(text, &tui.Style { Fg: tui.White, Bg: colorCmd[odd], Italic: true, }) } tui.Pop() tui.Pop() } func (w *cmdWindow) nameChange(uid, oldName, newName string) { lastIndex++ w.Buf.Add(nameChangeMsg {lastIndex, uid, oldName, newName}) } func (w *cmdWindow) userStatus(uid, status string) { globalApp.cache.Fetch(uid, func(u *proto.Object) { var name string if u != nil { name = u.Fields[""] } lastIndex++ w.Buf.Add(userStatusMsg {lastIndex, uid, name, status}) }) } func (w *cmdWindow) who(uid string) { globalApp.cache.Fetch(uid, func(u *proto.Object) { if u == nil { w.err("error fetching user information") return } lastIndex++ w.Buf.Add(whoMsg { lastIndex, uid, u.Fields[""], u.Fields["status"], u.Kind == "gone", }) }) }