aboutsummaryrefslogtreecommitdiff
path: root/ui
diff options
context:
space:
mode:
Diffstat (limited to 'ui')
-rw-r--r--ui/commands.go15
-rw-r--r--ui/message-view.go24
-rw-r--r--ui/messages/base.go4
-rw-r--r--ui/messages/expandedtextmessage.go7
-rw-r--r--ui/messages/imagemessage.go11
-rw-r--r--ui/messages/message.go3
-rw-r--r--ui/messages/textbase.go9
-rw-r--r--ui/messages/textmessage.go7
-rw-r--r--ui/room-view.go9
-rw-r--r--ui/ui.go4
-rw-r--r--ui/view-main.go11
11 files changed, 51 insertions, 53 deletions
diff --git a/ui/commands.go b/ui/commands.go
index a72f3c7..5c0e90b 100644
--- a/ui/commands.go
+++ b/ui/commands.go
@@ -131,21 +131,20 @@ func cmdSetState(cmd *Command) {
func cmdUIToggle(cmd *Command) {
if len(cmd.Args) == 0 {
- cmd.Reply("Usage: /uitoggle <rooms/users/baremessages>")
+ cmd.Reply("Usage: /uitoggle <rooms/users/baremessages/images>")
return
}
switch cmd.Args[0] {
case "rooms":
- cmd.MainView.hideRoomList = !cmd.MainView.hideRoomList
- cmd.Config.Preferences.HideRoomList = cmd.MainView.hideRoomList
+ cmd.Config.Preferences.HideRoomList = !cmd.Config.Preferences.HideRoomList
case "users":
- cmd.MainView.hideUserList = !cmd.MainView.hideUserList
- cmd.Config.Preferences.HideUserList = cmd.MainView.hideUserList
+ cmd.Config.Preferences.HideUserList = !cmd.Config.Preferences.HideUserList
case "baremessages":
- cmd.MainView.bareMessages = !cmd.MainView.bareMessages
- cmd.Config.Preferences.BareMessageView = cmd.MainView.bareMessages
+ cmd.Config.Preferences.BareMessageView = !cmd.Config.Preferences.BareMessageView
+ case "images":
+ cmd.Config.Preferences.DisableImages = !cmd.Config.Preferences.DisableImages
default:
- cmd.Reply("Usage: /uitoggle <rooms/users/baremessages>")
+ cmd.Reply("Usage: /uitoggle <rooms/users/baremessages/images>")
return
}
cmd.UI.Render()
diff --git a/ui/message-view.go b/ui/message-view.go
index 9f3d811..c3f5a8a 100644
--- a/ui/message-view.go
+++ b/ui/message-view.go
@@ -30,6 +30,7 @@ import (
"maunium.net/go/gomuks/ui/messages"
"maunium.net/go/gomuks/ui/messages/tstring"
"maunium.net/go/gomuks/ui/widget"
+ "maunium.net/go/gomuks/config"
"maunium.net/go/tcell"
"maunium.net/go/tview"
)
@@ -38,6 +39,7 @@ type MessageView struct {
*tview.Box
parent *RoomView
+ config *config.Config
ScrollOffset int
MaxSenderWidth int
@@ -50,7 +52,7 @@ type MessageView struct {
prevWidth int
prevHeight int
prevMsgCount int
- prevBareMode bool
+ prevPrefs config.UserPreferences
messageIDs map[string]messages.UIMessage
messages []messages.UIMessage
@@ -63,6 +65,7 @@ func NewMessageView(parent *RoomView) *MessageView {
return &MessageView{
Box: tview.NewBox(),
parent: parent,
+ config: parent.config,
MaxSenderWidth: 15,
TimestampWidth: len(messages.TimeFormat),
@@ -77,7 +80,6 @@ func NewMessageView(parent *RoomView) *MessageView {
prevWidth: -1,
prevHeight: -1,
prevMsgCount: -1,
- prevBareMode: false,
}
}
@@ -171,11 +173,11 @@ func (view *MessageView) AddMessage(ifcMessage ifc.Message, direction ifc.Messag
view.updateWidestSender(message.Sender())
_, _, width, _ := view.GetRect()
- bare := view.parent.parent.bareMessages
+ bare := view.config.Preferences.BareMessageView
if !bare {
width -= view.TimestampWidth + TimestampSenderGap + view.widestSender + SenderMessageGap
}
- message.CalculateBuffer(bare, width)
+ message.CalculateBuffer(view.config.Preferences, width)
if direction == ifc.AppendMessage {
if view.ScrollOffset > 0 {
@@ -264,11 +266,13 @@ func (view *MessageView) replaceBuffer(original messages.UIMessage, new messages
func (view *MessageView) recalculateBuffers() {
_, _, width, height := view.GetRect()
- bareMode := view.parent.parent.bareMessages
- if !bareMode {
+ prefs := view.config.Preferences
+ if !prefs.BareMessageView {
width -= view.TimestampWidth + TimestampSenderGap + view.widestSender + SenderMessageGap
}
- recalculateMessageBuffers := width != view.prevWidth || bareMode != view.prevBareMode
+ recalculateMessageBuffers := width != view.prevWidth ||
+ view.prevPrefs.BareMessageView != prefs.BareMessageView ||
+ view.prevPrefs.DisableImages != prefs.DisableImages
if recalculateMessageBuffers || len(view.messages) != view.prevMsgCount {
view.textBuffer = []tstring.TString{}
view.metaBuffer = []ifc.MessageMeta{}
@@ -279,14 +283,14 @@ func (view *MessageView) recalculateBuffers() {
break
}
if recalculateMessageBuffers {
- message.CalculateBuffer(bareMode, width)
+ message.CalculateBuffer(prefs, width)
}
view.appendBuffer(message)
}
}
view.prevHeight = height
view.prevWidth = width
- view.prevBareMode = bareMode
+ view.prevPrefs = prefs
}
func (view *MessageView) handleMessageClick(message ifc.MessageMeta) bool {
@@ -495,7 +499,7 @@ func (view *MessageView) Draw(screen tcell.Screen) {
messageX := usernameX + view.widestSender + SenderMessageGap
separatorX := usernameX + view.widestSender + SenderSeparatorGap
- bareMode := view.parent.parent.bareMessages
+ bareMode := view.config.Preferences.BareMessageView
if bareMode {
messageX = x
}
diff --git a/ui/messages/base.go b/ui/messages/base.go
index ae37431..02bbddb 100644
--- a/ui/messages/base.go
+++ b/ui/messages/base.go
@@ -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,
diff --git a/ui/messages/expandedtextmessage.go b/ui/messages/expandedtextmessage.go
index 6534b04..33e5514 100644
--- a/ui/messages/expandedtextmessage.go
+++ b/ui/messages/expandedtextmessage.go
@@ -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)
}
diff --git a/ui/messages/imagemessage.go b/ui/messages/imagemessage.go
index 3f50193..671148b 100644
--- a/ui/messages/imagemessage.go
+++ b/ui/messages/imagemessage.go
@@ -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)
}
diff --git a/ui/messages/message.go b/ui/messages/message.go
index 0de2835..3f1e694 100644
--- a/ui/messages/message.go
+++ b/ui/messages/message.go
@@ -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
diff --git a/ui/messages/textbase.go b/ui/messages/textbase.go
index 9f34683..e00ebc4 100644
--- a/ui/messages/textbase.go
+++ b/ui/messages/textbase.go
@@ -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
}
diff --git a/ui/messages/textmessage.go b/ui/messages/textmessage.go
index 20dcbfc..add8588 100644
--- a/ui/messages/textmessage.go
+++ b/ui/messages/textmessage.go
@@ -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)
}
diff --git a/ui/room-view.go b/ui/room-view.go
index fc2a049..efd144d 100644
--- a/ui/room-view.go
+++ b/ui/room-view.go
@@ -32,6 +32,7 @@ import (
"maunium.net/go/gomuks/ui/widget"
"maunium.net/go/tcell"
"maunium.net/go/tview"
+ "maunium.net/go/gomuks/config"
)
type RoomView struct {
@@ -46,6 +47,7 @@ type RoomView struct {
Room *rooms.Room
parent *MainView
+ config *config.Config
typing []string
@@ -66,6 +68,7 @@ func NewRoomView(parent *MainView, room *rooms.Room) *RoomView {
input: widget.NewAdvancedInputField(),
Room: room,
parent: parent,
+ config: parent.config,
}
view.content = NewMessageView(view)
@@ -202,7 +205,7 @@ func (view *RoomView) Draw(screen tcell.Screen) {
statusRow = contentRow + contentHeight
inputRow = statusRow + StatusBarHeight
)
- if view.parent.hideUserList {
+ if view.config.Preferences.HideUserList {
contentWidth = width
}
@@ -210,7 +213,7 @@ func (view *RoomView) Draw(screen tcell.Screen) {
view.topic.SetRect(x, topicRow, width, TopicBarHeight)
view.content.SetRect(x, contentRow, contentWidth, contentHeight)
view.status.SetRect(x, statusRow, width, StatusBarHeight)
- if !view.parent.hideUserList && userListColumn > x {
+ if !view.config.Preferences.HideUserList && userListColumn > x {
view.userList.SetRect(userListColumn, contentRow, UserListWidth, contentHeight)
view.ulBorder.SetRect(userListBorderColumn, contentRow, UserListBorderWidth, contentHeight)
}
@@ -223,7 +226,7 @@ func (view *RoomView) Draw(screen tcell.Screen) {
view.status.SetText(view.GetStatus())
view.status.Draw(screen)
view.input.Draw(screen)
- if !view.parent.hideUserList {
+ if !view.config.Preferences.HideUserList {
view.ulBorder.Draw(screen)
view.userList.Draw(screen)
}
diff --git a/ui/ui.go b/ui/ui.go
index 9707274..b2662d7 100644
--- a/ui/ui.go
+++ b/ui/ui.go
@@ -93,10 +93,6 @@ func (ui *GomuksUI) OnLogout() {
}
func (ui *GomuksUI) HandleNewPreferences() {
- prefs := ui.gmx.Config().Preferences
- ui.mainView.bareMessages = prefs.BareMessageView
- ui.mainView.hideUserList = prefs.HideUserList
- ui.mainView.hideRoomList = prefs.HideRoomList
ui.Render()
}
diff --git a/ui/view-main.go b/ui/view-main.go
index 785fb44..b83187e 100644
--- a/ui/view-main.go
+++ b/ui/view-main.go
@@ -50,14 +50,9 @@ type MainView struct {
gmx ifc.Gomuks
config *config.Config
parent *GomuksUI
-
- hideUserList bool
- hideRoomList bool
- bareMessages bool
}
func (ui *GomuksUI) NewMainView() tview.Primitive {
- prefs := ui.gmx.Config().Preferences
mainView := &MainView{
Flex: tview.NewFlex(),
roomList: NewRoomList(),
@@ -68,10 +63,6 @@ func (ui *GomuksUI) NewMainView() tview.Primitive {
gmx: ui.gmx,
config: ui.gmx.Config(),
parent: ui,
-
- hideUserList: prefs.HideUserList,
- hideRoomList: prefs.HideRoomList,
- bareMessages: prefs.BareMessageView,
}
mainView.cmdProcessor = NewCommandProcessor(mainView)
@@ -88,7 +79,7 @@ func (ui *GomuksUI) NewMainView() tview.Primitive {
}
func (view *MainView) Draw(screen tcell.Screen) {
- if view.hideRoomList {
+ if view.config.Preferences.HideRoomList {
view.roomView.SetRect(view.GetRect())
view.roomView.Draw(screen)
} else {