Change even more things
This commit is contained in:
parent
a8dcdfbaa1
commit
535fbbb4f7
@ -101,7 +101,29 @@ func cmdUnknownCommand(cmd *Command) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func cmdHelp(cmd *Command) {
|
func cmdHelp(cmd *Command) {
|
||||||
cmd.Reply("Known command. Don't try \"/help\" for help.")
|
cmd.Reply(`/help - Show the temporary help message.
|
||||||
|
|
||||||
|
/quit - Quit gomuks.
|
||||||
|
/clearcache - Clear cache and quit gomuks.
|
||||||
|
/logout - Log out of Matrix.
|
||||||
|
|
||||||
|
/me <message> - Send an emote message.
|
||||||
|
/rainbow <message> - Send a rainbow message (markdown not supported).
|
||||||
|
|
||||||
|
/join <room address> - Join a room.
|
||||||
|
/leave - Leave the current room.
|
||||||
|
|
||||||
|
/invite <user id> - Invite a user.
|
||||||
|
/kick <user id> [reason] - Kick a user.
|
||||||
|
/ban <user id> [reason] - Ban a user.
|
||||||
|
/unban <user id> - Unban a user.
|
||||||
|
|
||||||
|
/send <room id> <type> <json> - Send a custom event to the given room.
|
||||||
|
/msend <type> <json> - Send a custom event to the current room.
|
||||||
|
/setstate <room id> <type> <key/-> <json> - Send a custom event to the given room.
|
||||||
|
/msetstate <type> <key/-> <json> - Send a custom event to the current room.
|
||||||
|
|
||||||
|
/toggle <thing> - Temporary command to toggle various UI features.`)
|
||||||
}
|
}
|
||||||
|
|
||||||
func cmdLeave(cmd *Command) {
|
func cmdLeave(cmd *Command) {
|
||||||
@ -126,14 +148,14 @@ func cmdInvite(cmd *Command) {
|
|||||||
|
|
||||||
func cmdBan(cmd *Command) {
|
func cmdBan(cmd *Command) {
|
||||||
if len(cmd.Args) < 1 {
|
if len(cmd.Args) < 1 {
|
||||||
cmd.Reply("Usage: /ban <user> <optional:reason>")
|
cmd.Reply("Usage: /ban <user> [reason]")
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
reason := "you are the weakest link, goodbye!"
|
reason := "you are the weakest link, goodbye!"
|
||||||
if len(cmd.Args) >= 2 {
|
if len(cmd.Args) >= 2 {
|
||||||
reason = strings.Join(cmd.Args[1:]," ")
|
reason = strings.Join(cmd.Args[1:], " ")
|
||||||
}
|
}
|
||||||
_, err := cmd.Matrix.Client().BanUser(cmd.Room.MxRoom().ID, &mautrix.ReqBanUser{reason,cmd.Args[0]})
|
_, err := cmd.Matrix.Client().BanUser(cmd.Room.MxRoom().ID, &mautrix.ReqBanUser{reason, cmd.Args[0]})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
debug.Print("Error in ban call:", err)
|
debug.Print("Error in ban call:", err)
|
||||||
cmd.Reply("Failed to ban user:", err)
|
cmd.Reply("Failed to ban user:", err)
|
||||||
@ -155,14 +177,14 @@ func cmdUnban(cmd *Command) {
|
|||||||
|
|
||||||
func cmdKick(cmd *Command) {
|
func cmdKick(cmd *Command) {
|
||||||
if len(cmd.Args) < 1 {
|
if len(cmd.Args) < 1 {
|
||||||
cmd.Reply("Usage: /kick <user> <optional:reason>")
|
cmd.Reply("Usage: /kick <user> [reason]")
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
reason := "you are the weakest link, goodbye!"
|
reason := "you are the weakest link, goodbye!"
|
||||||
if len(cmd.Args) >= 2 {
|
if len(cmd.Args) >= 2 {
|
||||||
reason = strings.Join(cmd.Args[1:]," ")
|
reason = strings.Join(cmd.Args[1:], " ")
|
||||||
}
|
}
|
||||||
_, err := cmd.Matrix.Client().KickUser(cmd.Room.MxRoom().ID, &mautrix.ReqKickUser{reason,cmd.Args[0]})
|
_, err := cmd.Matrix.Client().KickUser(cmd.Room.MxRoom().ID, &mautrix.ReqKickUser{reason, cmd.Args[0]})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
debug.Print("Error in kick call:", err)
|
debug.Print("Error in kick call:", err)
|
||||||
debug.Print("Failed to kick user:", err)
|
debug.Print("Failed to kick user:", err)
|
||||||
@ -192,7 +214,7 @@ func cmdMSendEvent(cmd *Command) {
|
|||||||
cmd.Reply("Usage: /msend <event type> <content>")
|
cmd.Reply("Usage: /msend <event type> <content>")
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
cmd.Args = append([]string{cmd.Room.MxRoom().ID},cmd.Args...)
|
cmd.Args = append([]string{cmd.Room.MxRoom().ID}, cmd.Args...)
|
||||||
cmdSendEvent(cmd)
|
cmdSendEvent(cmd)
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -230,7 +252,7 @@ func cmdMSetState(cmd *Command) {
|
|||||||
cmd.Reply("Usage: /msetstate <event type> <state key> <content>")
|
cmd.Reply("Usage: /msetstate <event type> <state key> <content>")
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
cmd.Args = append([]string{cmd.Room.MxRoom().ID},cmd.Args...)
|
cmd.Args = append([]string{cmd.Room.MxRoom().ID}, cmd.Args...)
|
||||||
cmdSetState(cmd)
|
cmdSetState(cmd)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -382,6 +382,9 @@ func (list *RoomList) OnPasteEvent(event mauview.PasteEvent) bool {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (list *RoomList) OnMouseEvent(event mauview.MouseEvent) bool {
|
func (list *RoomList) OnMouseEvent(event mauview.MouseEvent) bool {
|
||||||
|
if event.HasMotion() {
|
||||||
|
return false
|
||||||
|
}
|
||||||
switch event.Buttons() {
|
switch event.Buttons() {
|
||||||
case tcell.WheelUp:
|
case tcell.WheelUp:
|
||||||
list.AddScrollOffset(-WheelScrollOffsetDiff)
|
list.AddScrollOffset(-WheelScrollOffsetDiff)
|
||||||
@ -411,7 +414,7 @@ func (list *RoomList) clickRoom(line, column int, mod bool) bool {
|
|||||||
trl := list.items[tag]
|
trl := list.items[tag]
|
||||||
if line--; line == -1 {
|
if line--; line == -1 {
|
||||||
trl.ToggleCollapse()
|
trl.ToggleCollapse()
|
||||||
break
|
return true
|
||||||
}
|
}
|
||||||
|
|
||||||
if trl.IsCollapsed() {
|
if trl.IsCollapsed() {
|
||||||
|
@ -24,6 +24,7 @@ import (
|
|||||||
"strings"
|
"strings"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
|
"github.com/kyokomi/emoji"
|
||||||
"github.com/mattn/go-runewidth"
|
"github.com/mattn/go-runewidth"
|
||||||
|
|
||||||
"maunium.net/go/gomuks/debug"
|
"maunium.net/go/gomuks/debug"
|
||||||
@ -57,6 +58,8 @@ type RoomView struct {
|
|||||||
ulBorderScreen *mauview.ProxyScreen
|
ulBorderScreen *mauview.ProxyScreen
|
||||||
ulScreen *mauview.ProxyScreen
|
ulScreen *mauview.ProxyScreen
|
||||||
|
|
||||||
|
inputSubmitFunc func(room *RoomView, text string)
|
||||||
|
|
||||||
prevScreen mauview.Screen
|
prevScreen mauview.Screen
|
||||||
|
|
||||||
parent *MainView
|
parent *MainView
|
||||||
@ -125,12 +128,7 @@ func (view *RoomView) LoadHistory(matrix ifc.MatrixContainer, dir string) (int,
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (view *RoomView) SetInputSubmitFunc(fn func(room *RoomView, text string)) *RoomView {
|
func (view *RoomView) SetInputSubmitFunc(fn func(room *RoomView, text string)) *RoomView {
|
||||||
// FIXME
|
view.inputSubmitFunc = fn
|
||||||
/*view.input.SetDoneFunc(func(key tcell.Key) {
|
|
||||||
if key == tcell.KeyEnter {
|
|
||||||
fn(view, view.input.GetText())
|
|
||||||
}
|
|
||||||
})*/
|
|
||||||
return view
|
return view
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -249,11 +247,27 @@ func (view *RoomView) Draw(screen mauview.Screen) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (view *RoomView) OnKeyEvent(event mauview.KeyEvent) bool {
|
func (view *RoomView) OnKeyEvent(event mauview.KeyEvent) bool {
|
||||||
|
msgView := view.MessageView()
|
||||||
|
switch event.Key() {
|
||||||
|
case tcell.KeyPgUp:
|
||||||
|
if msgView.IsAtTop() {
|
||||||
|
go view.parent.LoadHistory(view.Room.ID)
|
||||||
|
}
|
||||||
|
msgView.AddScrollOffset(+msgView.Height() / 2)
|
||||||
|
return true
|
||||||
|
case tcell.KeyPgDn:
|
||||||
|
msgView.AddScrollOffset(-msgView.Height() / 2)
|
||||||
|
return true
|
||||||
|
case tcell.KeyEnter:
|
||||||
|
if event.Modifiers() & tcell.ModShift == 0 && event.Modifiers() & tcell.ModCtrl == 0 && view.inputSubmitFunc != nil {
|
||||||
|
view.inputSubmitFunc(view, view.input.GetText())
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
}
|
||||||
return view.input.OnKeyEvent(event)
|
return view.input.OnKeyEvent(event)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (view *RoomView) OnPasteEvent(event mauview.PasteEvent) bool {
|
func (view *RoomView) OnPasteEvent(event mauview.PasteEvent) bool {
|
||||||
debug.Print("PASTE EVENT", event)
|
|
||||||
return view.input.OnPasteEvent(event)
|
return view.input.OnPasteEvent(event)
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -320,6 +334,20 @@ func (view *RoomView) autocompleteRoom(existingText string) (completions []compl
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (view *RoomView) autocompleteEmoji(word string) (completions []string) {
|
||||||
|
if len(word) == 0 || word[0] != ':' {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
for name, value := range emoji.CodeMap() {
|
||||||
|
if name == word {
|
||||||
|
return []string{value}
|
||||||
|
} else if strings.HasPrefix(name, word) {
|
||||||
|
completions = append(completions, name)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
func (view *RoomView) InputTabComplete(text string, cursorOffset int) {
|
func (view *RoomView) InputTabComplete(text string, cursorOffset int) {
|
||||||
debug.Print("Tab completing", cursorOffset, text)
|
debug.Print("Tab completing", cursorOffset, text)
|
||||||
str := runewidth.Truncate(text, cursorOffset, "")
|
str := runewidth.Truncate(text, cursorOffset, "")
|
||||||
@ -344,6 +372,8 @@ func (view *RoomView) InputTabComplete(text string, cursorOffset int) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
strCompletions = append(strCompletions, view.autocompleteEmoji(word)...)
|
||||||
|
|
||||||
if len(strCompletions) > 0 {
|
if len(strCompletions) > 0 {
|
||||||
strCompletion = util.LongestCommonPrefix(strCompletions)
|
strCompletion = util.LongestCommonPrefix(strCompletions)
|
||||||
sort.Sort(sort.StringSlice(strCompletions))
|
sort.Sort(sort.StringSlice(strCompletions))
|
||||||
|
@ -231,58 +231,30 @@ func (view *MainView) OnKeyEvent(event mauview.KeyEvent) bool {
|
|||||||
case k == tcell.KeyEnd:
|
case k == tcell.KeyEnd:
|
||||||
msgView := view.currentRoom.MessageView()
|
msgView := view.currentRoom.MessageView()
|
||||||
msgView.AddScrollOffset(-msgView.TotalHeight())
|
msgView.AddScrollOffset(-msgView.TotalHeight())
|
||||||
case k == tcell.KeyCtrlN:
|
case c == 'n' || k == tcell.KeyCtrlN:
|
||||||
return view.flex.OnKeyEvent(tcell.NewEventKey(tcell.KeyEnter, '\n', event.Modifiers()))
|
return view.flex.OnKeyEvent(tcell.NewEventKey(tcell.KeyEnter, '\n', event.Modifiers()|tcell.ModShift))
|
||||||
case c == 'a':
|
case c == 'a':
|
||||||
view.SwitchRoom(view.roomList.NextWithActivity())
|
view.SwitchRoom(view.roomList.NextWithActivity())
|
||||||
case c == 'l':
|
case c == 'l' || k == tcell.KeyCtrlL:
|
||||||
view.ShowBare(view.currentRoom)
|
view.ShowBare(view.currentRoom)
|
||||||
default:
|
default:
|
||||||
goto defaultHandler
|
goto defaultHandler
|
||||||
}
|
}
|
||||||
return true
|
return true
|
||||||
} else if k == tcell.KeyAltDown || k == tcell.KeyCtrlDown {
|
|
||||||
view.SwitchRoom(view.roomList.Next())
|
|
||||||
return true
|
|
||||||
} else if k == tcell.KeyAltUp || k == tcell.KeyCtrlUp {
|
|
||||||
view.SwitchRoom(view.roomList.Previous())
|
|
||||||
return true
|
|
||||||
} else if view.currentRoom != nil &&
|
|
||||||
(k == tcell.KeyPgUp || k == tcell.KeyPgDn ||
|
|
||||||
k == tcell.KeyUp || k == tcell.KeyDown ||
|
|
||||||
k == tcell.KeyEnd || k == tcell.KeyHome) {
|
|
||||||
// TODO these should be in the RoomView key handler
|
|
||||||
msgView := view.currentRoom.MessageView()
|
|
||||||
|
|
||||||
if msgView.IsAtTop() && (k == tcell.KeyPgUp || k == tcell.KeyUp) {
|
|
||||||
go view.LoadHistory(view.currentRoom.Room.ID)
|
|
||||||
}
|
|
||||||
|
|
||||||
switch k {
|
|
||||||
case tcell.KeyPgUp:
|
|
||||||
msgView.AddScrollOffset(msgView.Height() / 2)
|
|
||||||
case tcell.KeyPgDn:
|
|
||||||
msgView.AddScrollOffset(-msgView.Height() / 2)
|
|
||||||
default:
|
|
||||||
goto defaultHandler
|
|
||||||
}
|
|
||||||
return true
|
|
||||||
} else if k == tcell.KeyEnter {
|
|
||||||
view.InputSubmit(view.currentRoom, view.currentRoom.input.GetText())
|
|
||||||
return true
|
|
||||||
}
|
}
|
||||||
defaultHandler:
|
defaultHandler:
|
||||||
if view.config.Preferences.HideRoomList {
|
if view.config.Preferences.HideRoomList {
|
||||||
debug.Print("Key event going to default handler (direct to roomview)", event)
|
|
||||||
return view.roomView.OnKeyEvent(event)
|
return view.roomView.OnKeyEvent(event)
|
||||||
}
|
}
|
||||||
debug.Print("Key event going to default handler (flex)", event)
|
|
||||||
return view.flex.OnKeyEvent(event)
|
return view.flex.OnKeyEvent(event)
|
||||||
}
|
}
|
||||||
|
|
||||||
const WheelScrollOffsetDiff = 3
|
const WheelScrollOffsetDiff = 3
|
||||||
|
|
||||||
func (view *MainView) OnMouseEvent(event mauview.MouseEvent) bool {
|
func (view *MainView) OnMouseEvent(event mauview.MouseEvent) bool {
|
||||||
|
if event.HasMotion() {
|
||||||
|
return false
|
||||||
|
}
|
||||||
if view.modal != nil {
|
if view.modal != nil {
|
||||||
return view.modal.OnMouseEvent(event)
|
return view.modal.OnMouseEvent(event)
|
||||||
}
|
}
|
||||||
@ -290,27 +262,6 @@ func (view *MainView) OnMouseEvent(event mauview.MouseEvent) bool {
|
|||||||
return view.roomView.OnMouseEvent(event)
|
return view.roomView.OnMouseEvent(event)
|
||||||
}
|
}
|
||||||
return view.flex.OnMouseEvent(event)
|
return view.flex.OnMouseEvent(event)
|
||||||
/*if event.Buttons() == tcell.ButtonNone || event.HasMotion() {
|
|
||||||
return false
|
|
||||||
}
|
|
||||||
|
|
||||||
view.BumpFocus(view.currentRoom)
|
|
||||||
|
|
||||||
x, y := event.Position()
|
|
||||||
|
|
||||||
switch {
|
|
||||||
case x >= 27:
|
|
||||||
view.roomView.OnMouseEvent(mauview.OffsetMouseEvent(event, -27, 0))
|
|
||||||
view.roomView.Focus()
|
|
||||||
view.focused = view.roomView
|
|
||||||
case x <= 25:
|
|
||||||
view.roomList.OnMouseEvent(event)
|
|
||||||
view.roomList.Focus()
|
|
||||||
view.focused = view.roomList
|
|
||||||
default:
|
|
||||||
debug.Print("Unhandled mouse event:", event.Buttons(), event.Modifiers(), x, y)
|
|
||||||
}
|
|
||||||
return false*/
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (view *MainView) OnPasteEvent(event mauview.PasteEvent) bool {
|
func (view *MainView) OnPasteEvent(event mauview.PasteEvent) bool {
|
||||||
|
Loading…
Reference in New Issue
Block a user