Add better help for /toggle
This commit is contained in:
parent
ae770a97e2
commit
bb5f9156c9
@ -30,6 +30,7 @@ import (
|
||||
"strconv"
|
||||
"strings"
|
||||
"time"
|
||||
"unicode"
|
||||
|
||||
"github.com/lucasb-eyer/go-colorful"
|
||||
"github.com/russross/blackfriday/v2"
|
||||
@ -560,6 +561,7 @@ func cmdSetState(cmd *Command) {
|
||||
}
|
||||
|
||||
type ToggleMessage interface {
|
||||
Name() string
|
||||
Format(state bool) string
|
||||
}
|
||||
|
||||
@ -573,6 +575,10 @@ func (hm HideMessage) Format(state bool) string {
|
||||
}
|
||||
}
|
||||
|
||||
func (hm HideMessage) Name() string {
|
||||
return string(hm)
|
||||
}
|
||||
|
||||
type SimpleToggleMessage string
|
||||
|
||||
func (stm SimpleToggleMessage) Format(state bool) string {
|
||||
@ -583,9 +589,13 @@ func (stm SimpleToggleMessage) Format(state bool) string {
|
||||
}
|
||||
}
|
||||
|
||||
func (stm SimpleToggleMessage) Name() string {
|
||||
return string(unicode.ToUpper(rune(stm[0]))) + string(stm[1:])
|
||||
}
|
||||
|
||||
var toggleMsg = map[string]ToggleMessage{
|
||||
"rooms": HideMessage("room list sidebar"),
|
||||
"users": HideMessage("user list sidebar"),
|
||||
"rooms": HideMessage("Room list sidebar"),
|
||||
"users": HideMessage("User list sidebar"),
|
||||
"baremessages": SimpleToggleMessage("bare message view"),
|
||||
"images": SimpleToggleMessage("image rendering"),
|
||||
"typingnotif": SimpleToggleMessage("typing notifications"),
|
||||
@ -596,13 +606,24 @@ var toggleMsg = map[string]ToggleMessage{
|
||||
"notifications": SimpleToggleMessage("desktop notifications"),
|
||||
}
|
||||
|
||||
func makeUsage() string {
|
||||
var buf strings.Builder
|
||||
buf.WriteString("Usage: /toggle <things...>\n\n")
|
||||
buf.WriteString("List of Things:\n")
|
||||
for key, value := range toggleMsg {
|
||||
_, _ = fmt.Fprintf(&buf, "* %s - %s\n", key, value.Name())
|
||||
}
|
||||
return buf.String()[:buf.Len()-1]
|
||||
}
|
||||
|
||||
func cmdToggle(cmd *Command) {
|
||||
if len(cmd.Args) == 0 {
|
||||
cmd.Reply("Usage: /toggle <rooms/users/baremessages/images/typingnotif/emojis>")
|
||||
cmd.Reply(makeUsage())
|
||||
return
|
||||
}
|
||||
for _, thing := range cmd.Args {
|
||||
var val *bool
|
||||
switch cmd.Args[0] {
|
||||
switch thing {
|
||||
case "rooms":
|
||||
val = &cmd.Config.Preferences.HideRoomList
|
||||
case "users":
|
||||
@ -624,11 +645,13 @@ func cmdToggle(cmd *Command) {
|
||||
case "notifications":
|
||||
val = &cmd.Config.Preferences.DisableNotifications
|
||||
default:
|
||||
cmd.Reply("Usage: /toggle <rooms/users/baremessages/images/typingnotif/emojis>")
|
||||
cmd.Reply("Unknown toggle %s. Use /toggle without arguments for a list of togglable things.", thing)
|
||||
return
|
||||
}
|
||||
*val = !(*val)
|
||||
cmd.Reply(toggleMsg[cmd.Args[0]].Format(*val))
|
||||
debug.Print(thing, *val)
|
||||
cmd.Reply(toggleMsg[thing].Format(*val))
|
||||
}
|
||||
cmd.UI.Render()
|
||||
go cmd.Matrix.SendPreferencesToMatrix()
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user