Add ui toggle for image rendering

This commit is contained in:
Tulir Asokan
2018-06-02 00:43:56 +03:00
parent 7868bd90fa
commit 134604edce
12 changed files with 52 additions and 53 deletions

View File

@ -24,6 +24,7 @@ import (
"maunium.net/go/gomuks/ui/messages/tstring"
"maunium.net/go/gomuks/ui/widget"
"maunium.net/go/tcell"
"maunium.net/go/gomuks/config"
)
func init() {
@ -43,7 +44,7 @@ type BaseMessage struct {
buffer []tstring.TString
plainBuffer []tstring.TString
prevBufferWidth int
prevBareMode bool
prevPrefs config.UserPreferences
}
func newBaseMessage(id, sender, displayname, msgtype string, timestamp time.Time) BaseMessage {
@ -55,7 +56,6 @@ func newBaseMessage(id, sender, displayname, msgtype string, timestamp time.Time
MsgType: msgtype,
MsgID: id,
prevBufferWidth: 0,
prevBareMode: false,
MsgState: ifc.MessageStateDefault,
MsgIsHighlight: false,
MsgIsService: false,

View File

@ -21,6 +21,7 @@ import (
"time"
"maunium.net/go/gomuks/ui/messages/tstring"
"maunium.net/go/gomuks/config"
)
func init() {
@ -52,11 +53,11 @@ func (msg *ExpandedTextMessage) PlainText() string {
return msg.MsgText.String()
}
func (msg *ExpandedTextMessage) CalculateBuffer(bare bool, width int) {
msg.calculateBufferWithText(bare, msg.MsgText, width)
func (msg *ExpandedTextMessage) CalculateBuffer(prefs config.UserPreferences, width int) {
msg.calculateBufferWithText(prefs, msg.MsgText, width)
}
// RecalculateBuffer calculates the buffer again with the previously provided width.
func (msg *ExpandedTextMessage) RecalculateBuffer() {
msg.CalculateBuffer(msg.prevBareMode, msg.prevBufferWidth)
msg.CalculateBuffer(msg.prevPrefs, msg.prevBufferWidth)
}

View File

@ -29,6 +29,7 @@ import (
"maunium.net/go/gomuks/lib/ansimage"
"maunium.net/go/gomuks/ui/messages/tstring"
"maunium.net/go/tcell"
"maunium.net/go/gomuks/config"
)
func init() {
@ -92,13 +93,13 @@ func (msg *ImageMessage) Path() string {
// CalculateBuffer generates the internal buffer for this message that consists
// of the text of this message split into lines at most as wide as the width
// parameter.
func (msg *ImageMessage) CalculateBuffer(bare bool, width int) {
func (msg *ImageMessage) CalculateBuffer(prefs config.UserPreferences, width int) {
if width < 2 {
return
}
if bare {
msg.calculateBufferWithText(bare, tstring.NewTString(msg.PlainText()), width)
if prefs.BareMessageView || prefs.DisableImages {
msg.calculateBufferWithText(prefs, tstring.NewTString(msg.PlainText()), width)
return
}
@ -111,10 +112,10 @@ func (msg *ImageMessage) CalculateBuffer(bare bool, width int) {
msg.buffer = image.Render()
msg.prevBufferWidth = width
msg.prevBareMode = false
msg.prevPrefs = prefs
}
// RecalculateBuffer calculates the buffer again with the previously provided width.
func (msg *ImageMessage) RecalculateBuffer() {
msg.CalculateBuffer(msg.prevBareMode, msg.prevBufferWidth)
msg.CalculateBuffer(msg.prevPrefs, msg.prevBufferWidth)
}

View File

@ -19,13 +19,14 @@ package messages
import (
"maunium.net/go/gomuks/interface"
"maunium.net/go/gomuks/ui/messages/tstring"
"maunium.net/go/gomuks/config"
)
// UIMessage is a wrapper for the content and metadata of a Matrix message intended to be displayed.
type UIMessage interface {
ifc.Message
CalculateBuffer(bare bool, width int)
CalculateBuffer(preferences config.UserPreferences, width int)
RecalculateBuffer()
Buffer() []tstring.TString
Height() int

View File

@ -20,6 +20,7 @@ import (
"regexp"
"maunium.net/go/gomuks/ui/messages/tstring"
"fmt"
"maunium.net/go/gomuks/config"
)
// Regular expressions used to split lines when calculating the buffer.
@ -50,14 +51,14 @@ func matchBoundaryPattern(bare bool, extract tstring.TString) tstring.TString {
// CalculateBuffer generates the internal buffer for this message that consists
// of the text of this message split into lines at most as wide as the width
// parameter.
func (msg *BaseMessage) calculateBufferWithText(bare bool, text tstring.TString, width int) {
func (msg *BaseMessage) calculateBufferWithText(prefs config.UserPreferences, text tstring.TString, width int) {
if width < 2 {
return
}
msg.buffer = []tstring.TString{}
if bare {
if prefs.BareMessageView {
newText := tstring.NewTString(msg.FormatTime())
if len(msg.Sender()) > 0 {
newText = newText.AppendTString(tstring.NewColorTString(fmt.Sprintf(" <%s> ", msg.Sender()), msg.SenderColor()))
@ -84,12 +85,12 @@ func (msg *BaseMessage) calculateBufferWithText(bare bool, text tstring.TString,
if spaces := spacePattern.FindStringIndex(str[len(extract):].String()); spaces != nil && spaces[0] == 0 {
extract = str[:len(extract)+spaces[1]]
}
extract = matchBoundaryPattern(bare, extract)
extract = matchBoundaryPattern(prefs.BareMessageView, extract)
}
msg.buffer = append(msg.buffer, extract)
str = str[len(extract):]
}
}
msg.prevBufferWidth = width
msg.prevBareMode = bare
msg.prevPrefs = prefs
}

View File

@ -23,6 +23,7 @@ import (
"maunium.net/go/gomuks/interface"
"maunium.net/go/gomuks/ui/messages/tstring"
"maunium.net/go/gomuks/config"
)
func init() {
@ -84,11 +85,11 @@ func (msg *TextMessage) PlainText() string {
return msg.MsgText
}
func (msg *TextMessage) CalculateBuffer(bare bool, width int) {
msg.calculateBufferWithText(bare, msg.getCache(), width)
func (msg *TextMessage) CalculateBuffer(prefs config.UserPreferences, width int) {
msg.calculateBufferWithText(prefs, msg.getCache(), width)
}
// RecalculateBuffer calculates the buffer again with the previously provided width.
func (msg *TextMessage) RecalculateBuffer() {
msg.CalculateBuffer(msg.prevBareMode, msg.prevBufferWidth)
msg.CalculateBuffer(msg.prevPrefs, msg.prevBufferWidth)
}