Change things

This commit is contained in:
Tulir Asokan 2019-03-26 19:57:44 +02:00
parent ded4767729
commit c3c7cc9b35
5 changed files with 45 additions and 50 deletions

View File

@ -40,7 +40,6 @@ import (
"maunium.net/go/gomuks/config" "maunium.net/go/gomuks/config"
"maunium.net/go/gomuks/debug" "maunium.net/go/gomuks/debug"
"maunium.net/go/gomuks/interface" "maunium.net/go/gomuks/interface"
"maunium.net/go/gomuks/lib/bfhtml"
"maunium.net/go/gomuks/matrix/pushrules" "maunium.net/go/gomuks/matrix/pushrules"
"maunium.net/go/gomuks/matrix/rooms" "maunium.net/go/gomuks/matrix/rooms"
) )
@ -474,28 +473,18 @@ func (c *Container) SendMessage(roomID string, msgtype mautrix.MessageType, text
} }
func (c *Container) renderMarkdown(text string) string { func (c *Container) renderMarkdown(text string) string {
parser := blackfriday.New( renderer := blackfriday.NewHTMLRenderer(blackfriday.HTMLRendererParameters{
blackfriday.WithExtensions(blackfriday.NoIntraEmphasis |
blackfriday.Tables |
blackfriday.FencedCode |
blackfriday.Strikethrough |
blackfriday.SpaceHeadings |
blackfriday.DefinitionLists))
ast := parser.Parse([]byte(text))
renderer := bfhtml.HTMLRenderer{
HTMLRenderer: blackfriday.NewHTMLRenderer(blackfriday.HTMLRendererParameters{
Flags: blackfriday.UseXHTML, Flags: blackfriday.UseXHTML,
}),
}
var buf strings.Builder
renderer.RenderHeader(&buf, ast)
ast.Walk(func(node *blackfriday.Node, entering bool) blackfriday.WalkStatus {
return renderer.RenderNode(&buf, node, entering)
}) })
renderer.RenderFooter(&buf, ast)
return buf.String() return strings.ReplaceAll(string(blackfriday.Run([]byte(text),
blackfriday.WithExtensions(blackfriday.NoIntraEmphasis|
blackfriday.Tables|
blackfriday.FencedCode|
blackfriday.Strikethrough|
blackfriday.SpaceHeadings|
blackfriday.DefinitionLists),
blackfriday.WithRenderer(renderer))), "\n", "")
} }
var mentionRegex = regexp.MustCompile("\\[(.+?)]\\(https://matrix.to/#/@.+?:.+?\\)") var mentionRegex = regexp.MustCompile("\\[(.+?)]\\(https://matrix.to/#/@.+?:.+?\\)")

View File

@ -183,9 +183,8 @@ func (str TString) AdjustStyleFull(fn func(tcell.Style) tcell.Style) {
} }
func (str TString) Draw(screen mauview.Screen, x, y int) { func (str TString) Draw(screen mauview.Screen, x, y int) {
offsetX := 0
for _, cell := range str { for _, cell := range str {
offsetX += cell.Draw(screen, x+offsetX, y) x += cell.Draw(screen, x, y)
} }
} }

View File

@ -26,6 +26,8 @@ import (
"github.com/mattn/go-runewidth" "github.com/mattn/go-runewidth"
"maunium.net/go/gomuks/debug"
"maunium.net/go/mauview" "maunium.net/go/mauview"
"maunium.net/go/mautrix" "maunium.net/go/mautrix"
@ -98,7 +100,8 @@ func NewRoomView(parent *MainView, room *rooms.Room) *RoomView {
view.topic. view.topic.
SetText(strings.Replace(room.GetTopic(), "\n", " ", -1)). SetText(strings.Replace(room.GetTopic(), "\n", " ", -1)).
SetTextColor(tcell.ColorDarkGreen) SetTextColor(tcell.ColorWhite).
SetBackgroundColor(tcell.ColorDarkGreen)
view.status.SetBackgroundColor(tcell.ColorDimGray) view.status.SetBackgroundColor(tcell.ColorDimGray)
@ -187,10 +190,8 @@ const (
TopicBarHeight = 1 TopicBarHeight = 1
StatusBarHeight = 1 StatusBarHeight = 1
InputBarHeight = 1
StaticVerticalSpace = TopicBarHeight + StatusBarHeight + InputBarHeight
MaxInputHeight MaxInputHeight = 5
) )
func (view *RoomView) Draw(screen mauview.Screen) { func (view *RoomView) Draw(screen mauview.Screen) {
@ -199,15 +200,6 @@ func (view *RoomView) Draw(screen mauview.Screen) {
return return
} }
// Calculate actual grid based on view rectangle and constants defined above.
var (
contentHeight = height - StaticVerticalSpace
contentWidth = width - StaticHorizontalSpace
)
if view.config.Preferences.HideUserList {
contentWidth = width
}
if view.prevScreen != screen { if view.prevScreen != screen {
view.topicScreen.Parent = screen view.topicScreen.Parent = screen
view.contentScreen.Parent = screen view.contentScreen.Parent = screen
@ -218,6 +210,8 @@ func (view *RoomView) Draw(screen mauview.Screen) {
view.prevScreen = screen view.prevScreen = screen
} }
debug.Print(screen)
view.input.PrepareDraw(width) view.input.PrepareDraw(width)
inputHeight := view.input.GetTextHeight() inputHeight := view.input.GetTextHeight()
if inputHeight > MaxInputHeight { if inputHeight > MaxInputHeight {
@ -225,7 +219,11 @@ func (view *RoomView) Draw(screen mauview.Screen) {
} else if inputHeight < 1 { } else if inputHeight < 1 {
inputHeight = 1 inputHeight = 1
} }
contentHeight -= inputHeight contentHeight := height - inputHeight - TopicBarHeight - StatusBarHeight
contentWidth := width - StaticHorizontalSpace
if view.config.Preferences.HideUserList {
contentWidth = width
}
view.topicScreen.Width = width view.topicScreen.Width = width
view.contentScreen.Width = contentWidth view.contentScreen.Width = contentWidth
@ -261,7 +259,15 @@ func (view *RoomView) OnPasteEvent(event mauview.PasteEvent) bool {
} }
func (view *RoomView) OnMouseEvent(event mauview.MouseEvent) bool { func (view *RoomView) OnMouseEvent(event mauview.MouseEvent) bool {
return view.content.OnMouseEvent(event) switch {
case view.contentScreen.IsInArea(event.Position()):
return view.content.OnMouseEvent(view.contentScreen.OffsetMouseEvent(event))
case view.topicScreen.IsInArea(event.Position()):
return view.topic.OnMouseEvent(view.topicScreen.OffsetMouseEvent(event))
case view.inputScreen.IsInArea(event.Position()):
return view.input.OnMouseEvent(view.inputScreen.OffsetMouseEvent(event))
}
return false
} }
func (view *RoomView) SetCompletions(completions []string) { func (view *RoomView) SetCompletions(completions []string) {

View File

@ -155,6 +155,7 @@ func (view *MainView) InputSubmit(roomView *RoomView, text string) {
cmd := view.cmdProcessor.ParseCommand(roomView, text) cmd := view.cmdProcessor.ParseCommand(roomView, text)
go view.cmdProcessor.HandleCommand(cmd) go view.cmdProcessor.HandleCommand(cmd)
} else { } else {
debug.Print(text)
view.SendMessage(roomView, text) view.SendMessage(roomView, text)
} }
roomView.SetInputText("") roomView.SetInputText("")
@ -175,7 +176,7 @@ func (view *MainView) sendTempMessage(roomView *RoomView, tempMessage ifc.Messag
if err != nil { if err != nil {
tempMessage.SetState(ifc.MessageStateFailed) tempMessage.SetState(ifc.MessageStateFailed)
if httpErr, ok := err.(mautrix.HTTPError); ok { if httpErr, ok := err.(mautrix.HTTPError); ok {
if respErr, ok := httpErr.WrappedError.(mautrix.RespError); ok { if respErr := httpErr.RespError; respErr != nil {
// Show shorter version if available // Show shorter version if available
err = respErr err = respErr
} }

View File

@ -57,7 +57,7 @@ func WriteLine(screen mauview.Screen, align int, line string, x, y, maxWidth int
screen.SetContent(x+offsetX+localOffset, y, ch, nil, style) screen.SetContent(x+offsetX+localOffset, y, ch, nil, style)
} }
offsetX += chWidth offsetX += chWidth
if offsetX > maxWidth { if offsetX >= maxWidth {
break break
} }
} }