diff --git a/go.mod b/go.mod index 3048822..63a1b82 100644 --- a/go.mod +++ b/go.mod @@ -24,6 +24,6 @@ require ( gopkg.in/vansante/go-ffprobe.v2 v2.0.2 gopkg.in/yaml.v2 v2.3.0 maunium.net/go/mautrix v0.7.6 - maunium.net/go/mauview v0.1.1 + maunium.net/go/mauview v0.1.2 maunium.net/go/tcell v0.2.0 ) diff --git a/go.sum b/go.sum index 4572c2b..4ffbc00 100644 --- a/go.sum +++ b/go.sum @@ -121,5 +121,7 @@ maunium.net/go/mautrix v0.7.6 h1:jB9oCimPq0mVyolwQBC/9N1fu21AU+Ryq837cLf4gOo= maunium.net/go/mautrix v0.7.6/go.mod h1:Va/74MijqaS0DQ3aUqxmFO54/PMfr1LVsCOcGRHbYmo= maunium.net/go/mauview v0.1.1 h1:wfTXyPx3LGAGpTskh+UbBv/QItUWnEpaneHmywoYnfY= maunium.net/go/mauview v0.1.1/go.mod h1:3QBUiuLct9moP1LgDhCGIg0Ovxn38Bd2sGndnUOuj4o= +maunium.net/go/mauview v0.1.2 h1:6Y3GpyckIlzCNkry6k025YhWg8oh5XJFj3RAMf4VwWo= +maunium.net/go/mauview v0.1.2/go.mod h1:3QBUiuLct9moP1LgDhCGIg0Ovxn38Bd2sGndnUOuj4o= maunium.net/go/tcell v0.2.0 h1:1Q0kN3wCOGAIGu1r3QHADsjSUOPDylKREvCv3EzJpVg= maunium.net/go/tcell v0.2.0/go.mod h1:9Apcb3lNNS6C6lCqKT9UFp7BTRzHXfWE+/tgufsAMho= diff --git a/ui/commands.go b/ui/commands.go index f8b7232..8235c15 100644 --- a/ui/commands.go +++ b/ui/commands.go @@ -454,60 +454,8 @@ func cmdUnknownCommand(cmd *Command) { } func cmdHelp(cmd *Command) { - cmd.Reply(`# General -/help - Show this "temporary" help message. -/quit - Quit gomuks. -/clearcache - Clear cache and quit gomuks. -/logout - Log out of Matrix. -/toggle - Temporary command to toggle various UI features. - -Things: rooms, users, baremessages, images, typingnotif, unverified - -# Sending special messages -/me - Send an emote message. -/notice - Send a notice (generally used for bot messages). -/rainbow - Send rainbow text (markdown not supported). -/rainbowme - Send rainbow text in an emote. -/reply [text] - Reply to the selected message. -/react - React to the selected message. -/redact [reason] - Redact the selected message. -/edit - Edit the selected message. - -# Encryption -/fingerprint - View the fingerprint of your device. - -/devices - View the device list of a user. -/device - Show info about a specific device. -/unverify - Un-verify a device. -/blacklist - Blacklist a device. -/verify [fingerprint] - - Verify a device. If the fingerprint is not provided, - interactive emoji verification will be started. -/reset-session - Reset the outbound Megolm session in the current room. - -/import - Import encryption keys -/export - Export encryption keys -/export-room - Export encryption keys for the current room. - -# Rooms -/pm <...> - Create a private chat with the given user(s). -/create [room name] - Create a room. - -/join [server] - Join a room. -/accept - Accept the invite. -/reject - Reject the invite. - -/invite - Invite the given user to the room. -/roomnick - Change your per-room displayname. -/tag - Add the room to . -/untag - Remove the room from . -/tags - List the tags the room is in. -/alias - Add or remove local addresses. - -/leave - Leave the current room. -/kick [reason] - Kick a user. -/ban [reason] - Ban a user. -/unban - Unban a user.`) + view := cmd.MainView + view.ShowModal(NewHelpModal(view)) } func cmdLeave(cmd *Command) { diff --git a/ui/help-modal.go b/ui/help-modal.go new file mode 100644 index 0000000..41d644e --- /dev/null +++ b/ui/help-modal.go @@ -0,0 +1,106 @@ +package ui + +import ( + "maunium.net/go/tcell" + + "maunium.net/go/gomuks/debug" + "maunium.net/go/mauview" +) + +const helpText = `# General +/help - Show this help dialog. +/quit - Quit gomuks. +/clearcache - Clear cache and quit gomuks. +/logout - Log out of Matrix. +/toggle - Temporary command to toggle various UI features. + +# Sending special messages +/me - Send an emote message. +/notice - Send a notice (generally used for bot messages). +/rainbow - Send rainbow text. +/rainbowme - Send rainbow text in an emote. +/reply [text] - Reply to the selected message. +/react - React to the selected message. +/redact [reason] - Redact the selected message. +/edit - Edit the selected message. + +# Encryption +/fingerprint - View the fingerprint of your device. + +/devices - View the device list of a user. +/device - Show info about a specific device. +/unverify - Un-verify a device. +/blacklist - Blacklist a device. +/verify [fingerprint] + - Verify a device. If the fingerprint is not provided, + interactive emoji verification will be started. +/reset-session - Reset the outbound Megolm session in the current room. + +/import - Import encryption keys +/export - Export encryption keys +/export-room - Export encryption keys for the current room. + +# Rooms +/pm <...> - Create a private chat with the given user(s). +/create [room name] - Create a room. + +/join [server] - Join a room. +/accept - Accept the invite. +/reject - Reject the invite. + +/invite - Invite the given user to the room. +/roomnick - Change your per-room displayname. +/tag - Add the room to . +/untag - Remove the room from . +/tags - List the tags the room is in. +/alias - Add or remove local addresses. + +/leave - Leave the current room. +/kick [reason] - Kick a user. +/ban [reason] - Ban a user. +/unban - Unban a user.` + +type HelpModal struct { + mauview.FocusableComponent + parent *MainView +} + +func NewHelpModal(parent *MainView) *HelpModal { + hm := &HelpModal{parent: parent} + + text := mauview.NewTextView(). + SetText(helpText). + SetScrollable(true). + SetWrap(false) + + box := mauview.NewBox(text). + SetBorder(true). + SetTitle("Help"). + SetBlurCaptureFunc(func() bool { + hm.parent.HideModal() + return true + }) + box.Focus() + + hm.FocusableComponent = mauview.FractionalCenter(box, 42, 10, 0.5, 0.5) + + return hm +} + +func (hm *HelpModal) Focus() { + debug.Print("focus") + hm.FocusableComponent.Focus() +} + +func (hm *HelpModal) Blur() { + debug.Print("blur") + hm.FocusableComponent.Blur() +} + +func (hm *HelpModal) OnKeyEvent(event mauview.KeyEvent) bool { + if event.Key() == tcell.KeyEscape || event.Rune() == 'q' { + hm.parent.HideModal() + return true + } + return hm.FocusableComponent.OnKeyEvent(event) +}