Show notifications and highlights in room list. Fixes #8

This commit is contained in:
Tulir Asokan
2018-03-26 17:22:47 +03:00
parent 6095638fbb
commit b31d968814
7 changed files with 110 additions and 42 deletions

View File

@ -276,11 +276,11 @@ func getScrollbarStyle(scrollbarHere, isTop, isBottom bool) (char rune, style tc
func (view *MessageView) Draw(screen tcell.Screen) {
view.Box.Draw(screen)
x, y, width, height := view.GetInnerRect()
x, y, _, height := view.GetInnerRect()
view.recalculateBuffers()
if len(view.textBuffer) == 0 {
writeLine(screen, tview.AlignLeft, "It's quite empty in here.", x, y+height, width, tcell.ColorDefault)
writeLineSimple(screen, "It's quite empty in here.", x, y+height)
return
}
@ -294,7 +294,7 @@ func (view *MessageView) Draw(screen tcell.Screen) {
if view.LoadingMessages {
message = "Loading more messages..."
}
writeLine(screen, tview.AlignLeft, message, messageX, y, width, tcell.ColorGreen)
writeLineSimpleColor(screen, message, messageX, y, tcell.ColorGreen)
}
if len(view.textBuffer) != len(view.metaBuffer) {
@ -339,16 +339,16 @@ func (view *MessageView) Draw(screen tcell.Screen) {
text, meta := view.textBuffer[index], view.metaBuffer[index]
if meta != prevMeta {
if len(meta.GetTimestamp()) > 0 {
writeLine(screen, tview.AlignLeft, meta.GetTimestamp(), x, y+line, width, meta.GetTimestampColor())
writeLineSimpleColor(screen, meta.GetTimestamp(), x, y+line, meta.GetTimestampColor())
}
if prevMeta == nil || meta.GetSender() != prevMeta.GetSender() {
writeLine(
writeLineColor(
screen, tview.AlignRight, meta.GetSender(),
usernameX, y+line, view.widestSender,
meta.GetSenderColor())
}
prevMeta = meta
}
writeLine(screen, tview.AlignLeft, text, messageX, y+line, width, meta.GetTextColor())
writeLineSimpleColor(screen, text, messageX, y+line, meta.GetTextColor())
}
}

View File

@ -17,6 +17,9 @@
package widget
import (
"fmt"
"strconv"
"github.com/gdamore/tcell"
"maunium.net/go/gomuks/matrix/rooms"
"maunium.net/go/tview"
@ -104,21 +107,30 @@ func (list *RoomList) Draw(screen tcell.Screen) {
text := item.GetTitle()
writeLine(screen, tview.AlignLeft, text, x, y, width, list.mainTextColor)
lineWidth := width
// Background color of selected text.
style := tcell.StyleDefault.Foreground(list.mainTextColor)
if item == list.selected {
textWidth := tview.StringWidth(text)
for bx := 0; bx < textWidth && bx < width; bx++ {
m, c, style, _ := screen.GetContent(x+bx, y)
fg, _, _ := style.Decompose()
if fg == list.mainTextColor {
fg = list.selectedTextColor
}
style = style.Background(list.selectedBackgroundColor).Foreground(fg)
screen.SetContent(x+bx, y, m, c, style)
}
style = style.Foreground(list.selectedTextColor).Background(list.selectedBackgroundColor)
}
if item.HasNewMessages {
style = style.Bold(true)
}
if item.UnreadMessages > 0 {
unreadMessageCount := "99+"
if item.UnreadMessages < 100 {
unreadMessageCount = strconv.Itoa(item.UnreadMessages)
}
if item.Highlighted {
unreadMessageCount += "!"
}
unreadMessageCount = fmt.Sprintf("(%s)", unreadMessageCount)
writeLine(screen, tview.AlignRight, unreadMessageCount, x+lineWidth-6, y, 6, style)
lineWidth -= len(unreadMessageCount) + 1
}
writeLine(screen, tview.AlignLeft, text, x, y, lineWidth, style)
y++
if y >= bottomLimit {

View File

@ -22,7 +22,19 @@ import (
"maunium.net/go/tview"
)
func writeLine(screen tcell.Screen, align int, line string, x, y, maxWidth int, color tcell.Color) {
func writeLineSimple(screen tcell.Screen, line string, x, y int) {
writeLine(screen, tview.AlignLeft, line, x, y, 1<<30, tcell.StyleDefault)
}
func writeLineSimpleColor(screen tcell.Screen, line string, x, y int, color tcell.Color) {
writeLine(screen, tview.AlignLeft, line, x, y, 1<<30, tcell.StyleDefault.Foreground(color))
}
func writeLineColor(screen tcell.Screen, align int, line string, x, y, maxWidth int, color tcell.Color) {
writeLine(screen, align, line, x, y, maxWidth, tcell.StyleDefault.Foreground(color))
}
func writeLine(screen tcell.Screen, align int, line string, x, y, maxWidth int, style tcell.Style) {
offsetX := 0
if align == tview.AlignRight {
offsetX = maxWidth - runewidth.StringWidth(line)
@ -37,7 +49,7 @@ func writeLine(screen tcell.Screen, align int, line string, x, y, maxWidth int,
}
for localOffset := 0; localOffset < chWidth; localOffset++ {
screen.SetContent(x+offsetX+localOffset, y, ch, nil, tcell.StyleDefault.Foreground(color))
screen.SetContent(x+offsetX+localOffset, y, ch, nil, style)
}
offsetX += chWidth
if offsetX > maxWidth {