aboutsummaryrefslogtreecommitdiff
path: root/ui
diff options
context:
space:
mode:
authorTulir Asokan <tulir@maunium.net>2019-03-26 22:09:10 +0200
committerTulir Asokan <tulir@maunium.net>2019-03-26 22:09:10 +0200
commitcc63a197c60bb77c2d020b525bae13d701ccf5a4 (patch)
treeb9bcee552a22bdfc546c71ad328cdebe96950036 /ui
parentc3c7cc9b3503417afe11a8067095534a751dfd04 (diff)
Change more things
Diffstat (limited to 'ui')
-rw-r--r--ui/messages/parser/htmlparser.go44
-rw-r--r--ui/room-view.go4
-rw-r--r--ui/view-main.go1
3 files changed, 32 insertions, 17 deletions
diff --git a/ui/messages/parser/htmlparser.go b/ui/messages/parser/htmlparser.go
index ddf6d36..f01d3cb 100644
--- a/ui/messages/parser/htmlparser.go
+++ b/ui/messages/parser/htmlparser.go
@@ -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) fontToTString(node *html.Node, stripLinebreak bool) tstring.TString {
- str := parser.nodeToTagAwareTString(node.FirstChild, stripLinebreak)
- hex := parser.getAttribute(node, "data-mx-color")
+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, "color")
+ hex = parser.getAttribute(node, altName)
if len(hex) == 0 {
- return str
+ return
}
}
- color, err := colorful.Hex(hex)
+ cful, err := colorful.Hex(hex)
if err != nil {
- color2, ok := ColorMap[strings.ToLower(hex)]
- if !ok {
- return str
+ color2, found := ColorMap[strings.ToLower(hex)]
+ if !found {
+ return
}
- color, _ = colorful.MakeColor(color2)
+ cful, _ = colorful.MakeColor(color2)
}
- r, g, b := color.RGB255()
- tcellColor := tcell.NewRGBColor(int32(r), int32(g), int32(b))
- str.AdjustStyleFull(AdjustStyleColor(tcellColor))
+ 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)
+ fgColor, ok := parser.parseColor(node, "data-mx-color", "color")
+ if ok {
+ str.AdjustStyleFull(AdjustStyleTextColor(fgColor))
+ }
+ bgColor, ok := parser.parseColor(node, "data-mx-bg-color", "background-color")
+ if ok {
+ str.AdjustStyleFull(AdjustStyleBackgroundColor(bgColor))
+ }
return str
}
diff --git a/ui/room-view.go b/ui/room-view.go
index 78ace59..7c561cc 100644
--- a/ui/room-view.go
+++ b/ui/room-view.go
@@ -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)
diff --git a/ui/view-main.go b/ui/view-main.go
index 2cbd203..d081d13 100644
--- a/ui/view-main.go
+++ b/ui/view-main.go
@@ -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("")