aboutsummaryrefslogtreecommitdiff
path: root/ui
diff options
context:
space:
mode:
authorTulir Asokan <tulir@maunium.net>2019-06-16 16:32:56 +0300
committerTulir Asokan <tulir@maunium.net>2019-06-16 16:32:56 +0300
commit859fd6092b6141363cef1cb58c2608f524314dc2 (patch)
tree61b8b69a81c4013d5cc639a72be1e7c6cc2c9a9b /ui
parentd23c5b1bfca629e4a930ad0655f856d82b62da3d (diff)
Add/change commands
Diffstat (limited to 'ui')
-rw-r--r--ui/command-processor.go5
-rw-r--r--ui/commands.go79
2 files changed, 56 insertions, 28 deletions
diff --git a/ui/command-processor.go b/ui/command-processor.go
index 26644c5..79faccc 100644
--- a/ui/command-processor.go
+++ b/ui/command-processor.go
@@ -82,6 +82,8 @@ func NewCommandProcessor(parent *MainView) *CommandProcessor {
"state": {"setstate"},
"mstate": {"msetstate"},
"rb": {"rainbow"},
+ "rbme": {"rainbowme"},
+ "myroomnick": {"roomnick"},
"createroom": {"create"},
"dm": {"pm"},
"query": {"pm"},
@@ -105,7 +107,10 @@ func NewCommandProcessor(parent *MainView) *CommandProcessor {
"msendevent": cmdMSendEvent,
"setstate": cmdSetState,
"msetstate": cmdMSetState,
+ "roomnick": cmdRoomNick,
"rainbow": cmdRainbow,
+ "rainbowme": cmdRainbowMe,
+ "notice": cmdNotice,
"invite": cmdInvite,
"hprof": cmdHeapProfile,
"cprof": cmdCPUProfile,
diff --git a/ui/commands.go b/ui/commands.go
index 0b15d8e..3a55f32 100644
--- a/ui/commands.go
+++ b/ui/commands.go
@@ -62,17 +62,57 @@ func (gt GradientTable) GetInterpolatedColorFor(t float64) colorful.Color {
}
var rainbow = GradientTable{
- {colorful.LinearRgb(1, 0, 0), 0.0},
- {colorful.LinearRgb(1, 0.5, 0), 0.1},
- {colorful.LinearRgb(0.5, 0.5, 0), 0.2}, // Yellow is 0.5, 0.5 instead of 1, 1 to make it readable on light themes
- {colorful.LinearRgb(0.5, 1, 0), 0.3},
- {colorful.LinearRgb(0, 1, 0), 0.4},
- {colorful.LinearRgb(0, 1, 0.5), 0.5},
- {colorful.LinearRgb(0, 1, 1), 0.6},
- {colorful.LinearRgb(0, 0.5, 1), 0.7},
- {colorful.LinearRgb(0.5, 0, 1), 0.8},
- {colorful.LinearRgb(1, 0, 1), 0.9},
- {colorful.LinearRgb(1, 0, 0.5), 1},
+ {colorful.LinearRgb(1, 0, 0), 0 / 11.0},
+ {colorful.LinearRgb(1, 0.5, 0), 1 / 11.0},
+ {colorful.LinearRgb(1, 1, 0), 2 / 11.0},
+ {colorful.LinearRgb(0.5, 1, 0), 3 / 11.0},
+ {colorful.LinearRgb(0, 1, 0), 4 / 11.0},
+ {colorful.LinearRgb(0, 1, 0.5), 5 / 11.0},
+ {colorful.LinearRgb(0, 1, 1), 6 / 11.0},
+ {colorful.LinearRgb(0, 0.5, 1), 7 / 11.0},
+ {colorful.LinearRgb(0, 0, 1), 8 / 11.0},
+ {colorful.LinearRgb(0.5, 0, 1), 9 / 11.0},
+ {colorful.LinearRgb(1, 0, 1), 10 / 11.0},
+ {colorful.LinearRgb(1, 0, 0.5), 11 / 11.0},
+}
+
+// TODO this command definitely belongs in a plugin once we have a plugin system.
+func makeRainbow(cmd *Command, msgtype mautrix.MessageType) {
+ text := strings.Join(cmd.Args, " ")
+ var html strings.Builder
+ for i, char := range text {
+ if unicode.IsSpace(char) {
+ html.WriteRune(char)
+ continue
+ }
+ color := rainbow.GetInterpolatedColorFor(float64(i) / float64(len(text))).Hex()
+ _, _ = fmt.Fprintf(&html, "<font color=\"%s\">%c</font>", color, char)
+ }
+ go cmd.Room.SendMessage(msgtype, html.String())
+ cmd.UI.Render()
+}
+
+func cmdRainbow(cmd *Command) {
+ makeRainbow(cmd, mautrix.MsgText)
+}
+
+func cmdRainbowMe(cmd *Command) {
+ makeRainbow(cmd, mautrix.MsgEmote)
+}
+
+func cmdNotice(cmd *Command) {
+ go cmd.Room.SendMessage(mautrix.MsgNotice, strings.Join(cmd.Args, " "))
+ cmd.UI.Render()
+}
+
+func cmdRoomNick(cmd *Command) {
+ room := cmd.Room.MxRoom()
+ member := room.GetMember(room.SessionUserID)
+ member.Displayname = strings.Join(cmd.Args, " ")
+ _, err := cmd.Matrix.Client().SendStateEvent(room.ID, mautrix.StateMember, room.SessionUserID, member)
+ if err != nil {
+ cmd.Reply("Failed to set room nick:", err)
+ }
}
func cmdHeapProfile(cmd *Command) {
@@ -127,23 +167,6 @@ func cmdTrace(cmd *Command) {
runTimedProfile(cmd, trace.Start, trace.Stop, "Call tracing", "gomuks.trace")
}
-// TODO this command definitely belongs in a plugin once we have a plugin system.
-func cmdRainbow(cmd *Command) {
- text := strings.Join(cmd.Args, " ")
- var html strings.Builder
- _, _ = fmt.Fprint(&html, "**🌈** ")
- for i, char := range text {
- if unicode.IsSpace(char) {
- html.WriteRune(char)
- continue
- }
- color := rainbow.GetInterpolatedColorFor(float64(i) / float64(len(text))).Hex()
- _, _ = fmt.Fprintf(&html, "<font color=\"%s\">%c</font>", color, char)
- }
- go cmd.Room.SendMessage("m.text", html.String())
- cmd.UI.Render()
-}
-
func cmdQuit(cmd *Command) {
cmd.Gomuks.Stop(true)
}