Change more things
This commit is contained in:
parent
c3c7cc9b35
commit
cc63a197c6
21
go.mod
21
go.mod
@ -1,18 +1,25 @@
|
||||
module maunium.net/go/gomuks
|
||||
|
||||
go 1.12
|
||||
|
||||
require (
|
||||
github.com/disintegration/imaging v1.5.0
|
||||
github.com/kyokomi/emoji v2.0.0+incompatible
|
||||
github.com/disintegration/imaging v1.6.0
|
||||
github.com/kyokomi/emoji v2.1.0+incompatible
|
||||
github.com/lithammer/fuzzysearch v1.0.2
|
||||
github.com/lucasb-eyer/go-colorful v0.0.0-20181028223441-12d3b2882a08
|
||||
github.com/lucasb-eyer/go-colorful v1.0.1
|
||||
github.com/mattn/go-runewidth v0.0.4
|
||||
github.com/russross/blackfriday/v2 v2.0.1
|
||||
github.com/shurcooL/sanitized_anchor_name v1.0.0 // indirect
|
||||
github.com/zyedidia/clipboard v0.0.0-20180718195219-bd31d747117d
|
||||
golang.org/x/image v0.0.0-20181116024801-cd38e8056d9b
|
||||
golang.org/x/net v0.0.0-20190110200230-915654e7eabc
|
||||
golang.org/x/image v0.0.0-20190321063152-3fc05d484e9f
|
||||
golang.org/x/net v0.0.0-20190326090315-15845e8f865b
|
||||
gopkg.in/yaml.v2 v2.2.2
|
||||
maunium.net/go/mautrix v0.1.0-alpha.3
|
||||
maunium.net/go/mautrix v0.1.0-alpha.3.0.20190326200501-48bbec641543
|
||||
maunium.net/go/mauview v0.0.0-20190325223341-4c387be4b686
|
||||
maunium.net/go/tcell v0.0.0-20190111223412-5e74142cb009
|
||||
)
|
||||
|
||||
replace maunium.net/go/mautrix => ../mautrix-go
|
||||
|
||||
replace maunium.net/go/tcell => ../../Go/tcell
|
||||
|
||||
replace maunium.net/go/mauview => ../../Go/mauview
|
||||
|
25
go.sum
25
go.sum
@ -1,13 +1,14 @@
|
||||
github.com/disintegration/imaging v1.5.0 h1:uYqUhwNmLU4K1FN44vhqS4TZJRAA4RhBINgbQlKyGi0=
|
||||
github.com/disintegration/imaging v1.5.0/go.mod h1:9B/deIUIrliYkyMTuXJd6OUFLcrZ2tf+3Qlwnaf/CjU=
|
||||
github.com/disintegration/imaging v1.6.0 h1:nVPXRUUQ36Z7MNf0O77UzgnOb1mkMMor7lmJMJXc/mA=
|
||||
github.com/disintegration/imaging v1.6.0/go.mod h1:xuIt+sRxDFrHS0drzXUlCJthkJ8k7lkkUojDSR247MQ=
|
||||
github.com/gdamore/encoding v1.0.0 h1:+7OoQ1Bc6eTm5niUzBa0Ctsh6JbMW6Ra+YNuAtDBdko=
|
||||
github.com/gdamore/encoding v1.0.0/go.mod h1:alR0ol34c49FCSBLjhosxzcPHQbf2trDkoo5dl+VrEg=
|
||||
github.com/kyokomi/emoji v2.0.0+incompatible h1:ftqSD1PzBkSr3I4/0ZZ7Cluaxv6sNi8CkhYE56Son6A=
|
||||
github.com/kyokomi/emoji v2.0.0+incompatible/go.mod h1:mZ6aGCD7yk8j6QY6KICwnZ2pxoszVseX1DNoGtU2tBA=
|
||||
github.com/kyokomi/emoji v2.1.0+incompatible h1:+DYU2RgpI6OHG4oQkM5KlqD3Wd3UPEsX8jamTo1Mp6o=
|
||||
github.com/kyokomi/emoji v2.1.0+incompatible/go.mod h1:mZ6aGCD7yk8j6QY6KICwnZ2pxoszVseX1DNoGtU2tBA=
|
||||
github.com/lithammer/fuzzysearch v1.0.2 h1:AjCE2iwc5y+8K+h2nXVc0Pmrpjvu+JVqMgiZ0oakXDM=
|
||||
github.com/lithammer/fuzzysearch v1.0.2/go.mod h1:bvAJyokfCQ7Vknrd4Kgc+izmMrPj5CiBAu2t6rK1Kak=
|
||||
github.com/lucasb-eyer/go-colorful v0.0.0-20181028223441-12d3b2882a08 h1:5MnxBC15uMxFv5FY/J/8vzyaBiArCOkMdFT9Jsw78iY=
|
||||
github.com/lucasb-eyer/go-colorful v0.0.0-20181028223441-12d3b2882a08/go.mod h1:NXg0ArsFk0Y01623LgUqoqcouGDB+PwCCQlrwrG6xJ4=
|
||||
github.com/lucasb-eyer/go-colorful v1.0.1 h1:nKJRBvZWPzvkwB4sY8A3U4zgqLf2Y9c02yzPsbXu/5c=
|
||||
github.com/lucasb-eyer/go-colorful v1.0.1/go.mod h1:tLy1nWSoU0DGtxQyNRrUmb6PUiB7usbds6gd97XTXwA=
|
||||
github.com/mattn/go-runewidth v0.0.4 h1:2BvfKmzob6Bmd4YsL0zygOqfdFnK7GR4QL06Do4/p7Y=
|
||||
github.com/mattn/go-runewidth v0.0.4/go.mod h1:LwmH8dsx7+W8Uxz3IHJYH5QSwggIsqBzpuz5H//U1FU=
|
||||
github.com/rivo/uniseg v0.0.0-20190313204849-f699dde9c340 h1:nOZbL5f2xmBAHWYrrHbHV1xatzZirN++oOQ3g83Ypgs=
|
||||
@ -18,10 +19,16 @@ github.com/shurcooL/sanitized_anchor_name v1.0.0 h1:PdmoCO6wvbs+7yrJyMORt4/BmY5I
|
||||
github.com/shurcooL/sanitized_anchor_name v1.0.0/go.mod h1:1NzhyTcUVG4SuEtjjoZeVRXNmyL/1OwPU0+IJeTBvfc=
|
||||
github.com/zyedidia/clipboard v0.0.0-20180718195219-bd31d747117d h1:Lhqt2eo+rgM8aswvM7nTtAMVm8ARPWzkE9n6eZDOccY=
|
||||
github.com/zyedidia/clipboard v0.0.0-20180718195219-bd31d747117d/go.mod h1:WDk3p8GiZV9+xFWlSo8qreeoLhW6Ik692rqXk+cNeRY=
|
||||
golang.org/x/image v0.0.0-20181116024801-cd38e8056d9b h1:VHyIDlv3XkfCa5/a81uzaoDkHH4rr81Z62g+xlnO8uM=
|
||||
golang.org/x/image v0.0.0-20181116024801-cd38e8056d9b/go.mod h1:ux5Hcp/YLpHSI86hEcLt0YII63i6oz57MZXIpbrjZUs=
|
||||
golang.org/x/net v0.0.0-20190110200230-915654e7eabc h1:Yx9JGxI1SBhVLFjpAkWMaO1TF+xyqtHLjZpvQboJGiM=
|
||||
golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w=
|
||||
golang.org/x/crypto v0.0.0-20190325154230-a5d413f7728c/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w=
|
||||
golang.org/x/image v0.0.0-20180708004352-c73c2afc3b81/go.mod h1:ux5Hcp/YLpHSI86hEcLt0YII63i6oz57MZXIpbrjZUs=
|
||||
golang.org/x/image v0.0.0-20190321063152-3fc05d484e9f h1:FO4MZ3N56GnxbqxGKqh+YTzUWQ2sDwtFQEZgLOxh9Jc=
|
||||
golang.org/x/image v0.0.0-20190321063152-3fc05d484e9f/go.mod h1:kZ7UVZpmo3dzQBMxlp+ypCbDeSB+sBbTgSJuh5dn5js=
|
||||
golang.org/x/net v0.0.0-20190110200230-915654e7eabc/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4=
|
||||
golang.org/x/net v0.0.0-20190326090315-15845e8f865b h1:LlDMQZ0I/u8J45sbt31TecpsFNErRGwDgS4WvT9hKzE=
|
||||
golang.org/x/net v0.0.0-20190326090315-15845e8f865b/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg=
|
||||
golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
|
||||
golang.org/x/sys v0.0.0-20190322080309-f49334f85ddc/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
||||
golang.org/x/text v0.3.0 h1:g61tztE5qeGQ89tm6NTjjM9VPIm088od1l6aSorWRWg=
|
||||
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
|
||||
gopkg.in/DATA-DOG/go-sqlmock.v1 v1.3.0/go.mod h1:OdE7CF6DbADk7lN8LIKRzRJTTZXIjtWgA5THM5lhBAw=
|
||||
@ -30,6 +37,8 @@ gopkg.in/yaml.v2 v2.2.2 h1:ZCJp+EgiOT7lHqUV2J862kp8Qj64Jo6az82+3Td9dZw=
|
||||
gopkg.in/yaml.v2 v2.2.2/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
|
||||
maunium.net/go/mautrix v0.1.0-alpha.3 h1:kBz7M63hRetQnAnYK+gVmuSxsmZesX6xERphVgEn324=
|
||||
maunium.net/go/mautrix v0.1.0-alpha.3/go.mod h1:GTVu6WDHR+98DKOrYetWsXorvUeKQV3jsSWO6ScbuFI=
|
||||
maunium.net/go/mautrix v0.1.0-alpha.3.0.20190326200501-48bbec641543 h1:72ljaoFWWT5TlRnLlEyB9xqSnDrUeWCYSD0LMaX7FZo=
|
||||
maunium.net/go/mautrix v0.1.0-alpha.3.0.20190326200501-48bbec641543/go.mod h1:hpKYWY2m61ql7Dxslkg59VgB9BtpvONQ1kjIQSCfs3k=
|
||||
maunium.net/go/mauview v0.0.0-20190325223341-4c387be4b686 h1:kFgijToFPbMQGIMElizZGPQsffu+ZqO0olORXnfj1g4=
|
||||
maunium.net/go/mauview v0.0.0-20190325223341-4c387be4b686/go.mod h1:Uw1CaNoCs9id/rKBF3Eg9KhhFVg+3akJTebZomFKW+4=
|
||||
maunium.net/go/tcell v0.0.0-20190111223412-5e74142cb009 h1:4lojuJmNSun1nUB67m3DGg+RkYg1MUO6aUxgKQU5iZk=
|
||||
|
@ -20,8 +20,8 @@ import "os/exec"
|
||||
|
||||
func Send(title, text string, critical, sound bool) error {
|
||||
args := []string{"-a", "gomuks"}
|
||||
if critical {
|
||||
args = append(args, "-u", "critical")
|
||||
if !critical {
|
||||
args = append(args, "-u", "low")
|
||||
}
|
||||
// if iconPath {
|
||||
// args = append(args, "-i", iconPath)
|
||||
|
@ -20,6 +20,7 @@ package matrix
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"time"
|
||||
|
||||
"maunium.net/go/mautrix"
|
||||
@ -46,6 +47,41 @@ const (
|
||||
EventSourceEphemeral
|
||||
)
|
||||
|
||||
func (es EventSource) String() string {
|
||||
if es == EventSourcePresence {
|
||||
return "presence"
|
||||
} else if es == EventSourceAccountData {
|
||||
return "account data"
|
||||
} else if es & EventSourceJoin != 0 {
|
||||
es -= EventSourceJoin
|
||||
switch es {
|
||||
case EventSourceState:
|
||||
return "joined state"
|
||||
case EventSourceTimeline:
|
||||
return "joined timeline"
|
||||
case EventSourceEphemeral:
|
||||
return "room ephemeral (joined)"
|
||||
case EventSourceAccountData:
|
||||
return "room account data (joined)"
|
||||
}
|
||||
} else if es & EventSourceInvite != 0 {
|
||||
es -= EventSourceInvite
|
||||
switch es {
|
||||
case EventSourceState:
|
||||
return "invited state"
|
||||
}
|
||||
} else if es & EventSourceLeave != 0 {
|
||||
es -= EventSourceLeave
|
||||
switch es {
|
||||
case EventSourceState:
|
||||
return "left state"
|
||||
case EventSourceTimeline:
|
||||
return "left timeline"
|
||||
}
|
||||
}
|
||||
return fmt.Sprintf("unknown (%d)", es)
|
||||
}
|
||||
|
||||
type EventHandler func(source EventSource, event *mautrix.Event)
|
||||
|
||||
// GomuksSyncer is the default syncing implementation. You can either write your own syncer, or selectively
|
||||
@ -120,7 +156,7 @@ func (s *GomuksSyncer) processSyncEvents(room *rooms.Room, events []*mautrix.Eve
|
||||
func (s *GomuksSyncer) processSyncEvent(room *rooms.Room, event *mautrix.Event, source EventSource) {
|
||||
if room != nil {
|
||||
event.RoomID = room.ID
|
||||
if source&EventSourceState != 0 {
|
||||
if source&EventSourceState != 0 || (source&EventSourceTimeline != 0 && event.Type.IsState() && event.StateKey != nil) {
|
||||
room.UpdateState(event)
|
||||
}
|
||||
}
|
||||
@ -138,10 +174,11 @@ func (s *GomuksSyncer) OnEventType(eventType mautrix.EventType, callback EventHa
|
||||
}
|
||||
|
||||
func (s *GomuksSyncer) notifyListeners(source EventSource, event *mautrix.Event) {
|
||||
if event.Type.IsState() && source&EventSourceState == 0 ||
|
||||
event.Type.IsAccountData() && source&EventSourceAccountData == 0 ||
|
||||
event.Type.IsEphemeral() && source&EventSourceEphemeral == 0 {
|
||||
debug.Printf("Event of type %s received from mismatching source %s: %v.", event.Type, source, event)
|
||||
if (event.Type.IsState() && source&EventSourceState == 0 && event.StateKey == nil) ||
|
||||
(event.Type.IsAccountData() && source&EventSourceAccountData == 0) ||
|
||||
(event.Type.IsEphemeral() && source&EventSourceEphemeral == 0) {
|
||||
evtJson, _ := json.Marshal(event)
|
||||
debug.Printf("Event of type %s received from mismatching source %s: %s", event.Type.String(), source.String(), string(evtJson))
|
||||
return
|
||||
}
|
||||
listeners, exists := s.listeners[event.Type]
|
||||
|
@ -61,12 +61,18 @@ func AdjustStyleStrikethrough(style tcell.Style) tcell.Style {
|
||||
return style.Strikethrough(true)
|
||||
}
|
||||
|
||||
func AdjustStyleColor(color tcell.Color) func(tcell.Style) tcell.Style {
|
||||
func AdjustStyleTextColor(color tcell.Color) func(tcell.Style) tcell.Style {
|
||||
return func(style tcell.Style) tcell.Style {
|
||||
return style.Foreground(color)
|
||||
}
|
||||
}
|
||||
|
||||
func AdjustStyleBackgroundColor(color tcell.Color) func(tcell.Style) tcell.Style {
|
||||
return func(style tcell.Style) tcell.Style {
|
||||
return style.Background(color)
|
||||
}
|
||||
}
|
||||
|
||||
func (parser *htmlParser) getAttribute(node *html.Node, attribute string) string {
|
||||
for _, attr := range node.Attr {
|
||||
if attr.Key == attribute {
|
||||
@ -137,28 +143,38 @@ func (parser *htmlParser) basicFormatToTString(node *html.Node, stripLinebreak b
|
||||
return str
|
||||
}
|
||||
|
||||
func (parser *htmlParser) parseColor(node *html.Node, mainName, altName string) (color tcell.Color, ok bool) {
|
||||
hex := parser.getAttribute(node, mainName)
|
||||
if len(hex) == 0 {
|
||||
hex = parser.getAttribute(node, altName)
|
||||
if len(hex) == 0 {
|
||||
return
|
||||
}
|
||||
}
|
||||
|
||||
cful, err := colorful.Hex(hex)
|
||||
if err != nil {
|
||||
color2, found := ColorMap[strings.ToLower(hex)]
|
||||
if !found {
|
||||
return
|
||||
}
|
||||
cful, _ = colorful.MakeColor(color2)
|
||||
}
|
||||
|
||||
r, g, b := cful.RGB255()
|
||||
return tcell.NewRGBColor(int32(r), int32(g), int32(b)), true
|
||||
}
|
||||
|
||||
func (parser *htmlParser) fontToTString(node *html.Node, stripLinebreak bool) tstring.TString {
|
||||
str := parser.nodeToTagAwareTString(node.FirstChild, stripLinebreak)
|
||||
hex := parser.getAttribute(node, "data-mx-color")
|
||||
if len(hex) == 0 {
|
||||
hex = parser.getAttribute(node, "color")
|
||||
if len(hex) == 0 {
|
||||
return str
|
||||
}
|
||||
fgColor, ok := parser.parseColor(node, "data-mx-color", "color")
|
||||
if ok {
|
||||
str.AdjustStyleFull(AdjustStyleTextColor(fgColor))
|
||||
}
|
||||
|
||||
color, err := colorful.Hex(hex)
|
||||
if err != nil {
|
||||
color2, ok := ColorMap[strings.ToLower(hex)]
|
||||
if !ok {
|
||||
return str
|
||||
}
|
||||
color, _ = colorful.MakeColor(color2)
|
||||
bgColor, ok := parser.parseColor(node, "data-mx-bg-color", "background-color")
|
||||
if ok {
|
||||
str.AdjustStyleFull(AdjustStyleBackgroundColor(bgColor))
|
||||
}
|
||||
|
||||
r, g, b := color.RGB255()
|
||||
tcellColor := tcell.NewRGBColor(int32(r), int32(g), int32(b))
|
||||
str.AdjustStyleFull(AdjustStyleColor(tcellColor))
|
||||
return str
|
||||
}
|
||||
|
||||
|
@ -210,8 +210,6 @@ func (view *RoomView) Draw(screen mauview.Screen) {
|
||||
view.prevScreen = screen
|
||||
}
|
||||
|
||||
debug.Print(screen)
|
||||
|
||||
view.input.PrepareDraw(width)
|
||||
inputHeight := view.input.GetTextHeight()
|
||||
if inputHeight > MaxInputHeight {
|
||||
@ -255,6 +253,7 @@ func (view *RoomView) OnKeyEvent(event mauview.KeyEvent) bool {
|
||||
}
|
||||
|
||||
func (view *RoomView) OnPasteEvent(event mauview.PasteEvent) bool {
|
||||
debug.Print("PASTE EVENT", event)
|
||||
return view.input.OnPasteEvent(event)
|
||||
}
|
||||
|
||||
@ -322,6 +321,7 @@ func (view *RoomView) autocompleteRoom(existingText string) (completions []compl
|
||||
}
|
||||
|
||||
func (view *RoomView) InputTabComplete(text string, cursorOffset int) {
|
||||
debug.Print("Tab completing", cursorOffset, text)
|
||||
str := runewidth.Truncate(text, cursorOffset, "")
|
||||
word := findWordToTabComplete(str)
|
||||
startIndex := len(str) - len(word)
|
||||
|
@ -155,7 +155,6 @@ func (view *MainView) InputSubmit(roomView *RoomView, text string) {
|
||||
cmd := view.cmdProcessor.ParseCommand(roomView, text)
|
||||
go view.cmdProcessor.HandleCommand(cmd)
|
||||
} else {
|
||||
debug.Print(text)
|
||||
view.SendMessage(roomView, text)
|
||||
}
|
||||
roomView.SetInputText("")
|
||||
|
Loading…
Reference in New Issue
Block a user