custom lingo for those who don't like honking

This commit is contained in:
Ted Unangst 2020-09-25 22:37:28 -04:00
parent 86b4af8654
commit 60c27f27fc
4 changed files with 55 additions and 19 deletions

View File

@ -43,12 +43,16 @@ func adminscreen() {
var avatarColors string var avatarColors string
getconfig("avatarcolors", &avatarColors) getconfig("avatarcolors", &avatarColors)
loadLingo()
messages := []*struct { type adminfield struct {
name string name string
label string label string
text string text string
}{ oneline bool
}
messages := []*adminfield{
{ {
name: "servermsg", name: "servermsg",
label: "server", label: "server",
@ -68,8 +72,17 @@ func adminscreen() {
name: "avatarcolors", name: "avatarcolors",
label: "avatar colors (4 RGBA hex numbers)", label: "avatar colors (4 RGBA hex numbers)",
text: string(avatarColors), text: string(avatarColors),
oneline: true,
}, },
} }
for _, l := range []string{"honked", "bonked", "honked back", "qonked", "evented"} {
messages = append(messages, &adminfield{
name: "lingo-" + strings.ReplaceAll(l, " ", ""),
label: "lingo for " + l,
text: relingo[l],
oneline: true,
})
}
cursel := 0 cursel := 0
hidecursor := func() { hidecursor := func() {
@ -145,17 +158,20 @@ func adminscreen() {
} }
msglineno := func(idx int) int { msglineno := func(idx int) int {
off := 2 off := 1
if idx == -1 { if idx == -1 {
return off return off
} }
for i, m := range messages { for i, m := range messages {
off += 2 off += 1
if i == idx { if i == idx {
return off return off
} }
if !m.oneline {
off += 1
off += linecount(m.text) off += linecount(m.text)
} }
}
off += 2 off += 2
return off return off
} }
@ -170,13 +186,15 @@ func adminscreen() {
label := messages[idx].label label := messages[idx].label
if idx == cursel { if idx == cursel {
label = reverse(label) label = reverse(label)
if editing { }
label = magenta(label) label = magenta(label)
}
}
text := forscreen(messages[idx].text) text := forscreen(messages[idx].text)
if messages[idx].oneline {
stdout.WriteString(fmt.Sprintf("%s\t %s", label, text))
} else {
stdout.WriteString(fmt.Sprintf("%s\n %s", label, text)) stdout.WriteString(fmt.Sprintf("%s\n %s", label, text))
} }
}
drawscreen := func() { drawscreen := func() {
clearscreen() clearscreen()
@ -202,20 +220,20 @@ func adminscreen() {
selectnext := func() { selectnext := func() {
if cursel < len(messages)-1 { if cursel < len(messages)-1 {
movecursor(4, msglineno(cursel)) movecursor(4, msglineno(cursel))
stdout.WriteString(messages[cursel].label) stdout.WriteString(magenta(messages[cursel].label))
cursel++ cursel++
movecursor(4, msglineno(cursel)) movecursor(4, msglineno(cursel))
stdout.WriteString(reverse(messages[cursel].label)) stdout.WriteString(reverse(magenta(messages[cursel].label)))
stdout.Flush() stdout.Flush()
} }
} }
selectprev := func() { selectprev := func() {
if cursel > 0 { if cursel > 0 {
movecursor(4, msglineno(cursel)) movecursor(4, msglineno(cursel))
stdout.WriteString(messages[cursel].label) stdout.WriteString(magenta(messages[cursel].label))
cursel-- cursel--
movecursor(4, msglineno(cursel)) movecursor(4, msglineno(cursel))
stdout.WriteString(reverse(messages[cursel].label)) stdout.WriteString(reverse(magenta(messages[cursel].label)))
stdout.Flush() stdout.Flush()
} }
} }
@ -231,6 +249,9 @@ func adminscreen() {
case '\x1b': case '\x1b':
break loop break loop
case '\n': case '\n':
if m.oneline {
break loop
}
m.text += "\n" m.text += "\n"
drawscreen() drawscreen()
case 127: case 127:

View File

@ -2,6 +2,8 @@ changelog
=== next === next
- Custom lingo for those who don't like honking.
+ Better support for rich text bios. + Better support for rich text bios.
+ Follow and unfollow should work a little better. + Follow and unfollow should work a little better.

12
fun.go
View File

@ -51,6 +51,17 @@ func init() {
allowedclasses["dl"] = true allowedclasses["dl"] = true
} }
var relingo = make(map[string]string)
func loadLingo() {
for _, l := range []string{"honked", "bonked", "honked back", "qonked", "evented"} {
v := l
k := "lingo-" + strings.ReplaceAll(l, " ", "")
getconfig(k, &v)
relingo[l] = v
}
}
func reverbolate(userid int64, honks []*Honk) { func reverbolate(userid int64, honks []*Honk) {
var user *WhatAbout var user *WhatAbout
somenumberedusers.Get(userid, &user) somenumberedusers.Get(userid, &user)
@ -162,6 +173,7 @@ func reverbolate(userid int64, honks []*Honk) {
h.HTPrecis = template.HTML(h.Precis) h.HTPrecis = template.HTML(h.Precis)
h.HTML = template.HTML(h.Noise) h.HTML = template.HTML(h.Noise)
h.What = relingo[h.What]
} }
} }

1
web.go
View File

@ -2346,6 +2346,7 @@ func serve() {
go redeliverator() go redeliverator()
go tracker() go tracker()
go bgmonitor() go bgmonitor()
loadLingo()
w100 := wait100ms() w100 := wait100ms()
readviews = templates.Load(debugMode, readviews = templates.Load(debugMode,