Add real bare view

This commit is contained in:
Tulir Asokan 2018-05-23 00:44:29 +03:00
parent bedb9979a9
commit 1d44d3da1a
4 changed files with 47 additions and 18 deletions

View File

@ -171,7 +171,7 @@ func (view *MessageView) AddMessage(ifcMessage ifc.Message, direction ifc.Messag
view.updateWidestSender(message.Sender()) view.updateWidestSender(message.Sender())
_, _, width, _ := view.GetRect() _, _, width, _ := view.GetRect()
bare := view.parent.parent.bareDisplay bare := view.parent.parent.bareMessages
if !bare { if !bare {
width -= view.TimestampWidth + TimestampSenderGap + view.widestSender + SenderMessageGap width -= view.TimestampWidth + TimestampSenderGap + view.widestSender + SenderMessageGap
} }
@ -264,7 +264,7 @@ func (view *MessageView) replaceBuffer(original messages.UIMessage, new messages
func (view *MessageView) recalculateBuffers() { func (view *MessageView) recalculateBuffers() {
_, _, width, height := view.GetRect() _, _, width, height := view.GetRect()
bareMode := view.parent.parent.bareDisplay bareMode := view.parent.parent.bareMessages
if !bareMode { if !bareMode {
width -= view.TimestampWidth + TimestampSenderGap + view.widestSender + SenderMessageGap width -= view.TimestampWidth + TimestampSenderGap + view.widestSender + SenderMessageGap
} }
@ -456,6 +456,26 @@ func (view *MessageView) getIndexOffset(screen tcell.Screen, height, messageX in
return return
} }
func (view *MessageView) CapturePlaintext(height int) string {
var buf strings.Builder
indexOffset := view.TotalHeight() - view.ScrollOffset - height
var prevMessage messages.UIMessage
for line := 0; line < height; line++ {
index := indexOffset + line
if index < 0 {
continue
}
meta := view.metaBuffer[index]
message, ok := meta.(messages.UIMessage)
if ok && message != prevMessage {
fmt.Fprintf(&buf, "%s <%s> %s\n", message.FormatTime(), message.Sender(), message.PlainText())
prevMessage = message
}
}
return buf.String()
}
func (view *MessageView) Draw(screen tcell.Screen) { func (view *MessageView) Draw(screen tcell.Screen) {
x, y, _, height := view.GetRect() x, y, _, height := view.GetRect()
view.recalculateBuffers() view.recalculateBuffers()
@ -469,7 +489,7 @@ func (view *MessageView) Draw(screen tcell.Screen) {
messageX := usernameX + view.widestSender + SenderMessageGap messageX := usernameX + view.widestSender + SenderMessageGap
separatorX := usernameX + view.widestSender + SenderSeparatorGap separatorX := usernameX + view.widestSender + SenderSeparatorGap
bareMode := view.parent.parent.bareDisplay bareMode := view.parent.parent.bareMessages
if bareMode { if bareMode {
messageX = 0 messageX = 0
} }

View File

@ -29,6 +29,7 @@ type UIMessage interface {
RecalculateBuffer() RecalculateBuffer()
Buffer() []tstring.TString Buffer() []tstring.TString
Height() int Height() int
PlainText() string
RealSender() string RealSender() string
RegisterMatrix(matrix ifc.MatrixContainer) RegisterMatrix(matrix ifc.MatrixContainer)

View File

@ -202,7 +202,7 @@ func (view *RoomView) Draw(screen tcell.Screen) {
statusRow = contentRow + contentHeight statusRow = contentRow + contentHeight
inputRow = statusRow + StatusBarHeight inputRow = statusRow + StatusBarHeight
) )
if !view.parent.ShowUserList() { if view.parent.hideUserList {
contentWidth = width contentWidth = width
} }
@ -210,7 +210,7 @@ func (view *RoomView) Draw(screen tcell.Screen) {
view.topic.SetRect(x, topicRow, width, TopicBarHeight) view.topic.SetRect(x, topicRow, width, TopicBarHeight)
view.content.SetRect(x, contentRow, contentWidth, contentHeight) view.content.SetRect(x, contentRow, contentWidth, contentHeight)
view.status.SetRect(x, statusRow, width, StatusBarHeight) view.status.SetRect(x, statusRow, width, StatusBarHeight)
if view.parent.ShowUserList() && userListColumn > x { if !view.parent.hideUserList && userListColumn > x {
view.userList.SetRect(userListColumn, contentRow, UserListWidth, contentHeight) view.userList.SetRect(userListColumn, contentRow, UserListWidth, contentHeight)
view.ulBorder.SetRect(userListBorderColumn, contentRow, UserListBorderWidth, contentHeight) view.ulBorder.SetRect(userListBorderColumn, contentRow, UserListBorderWidth, contentHeight)
} }
@ -223,7 +223,7 @@ func (view *RoomView) Draw(screen tcell.Screen) {
view.status.SetText(view.GetStatus()) view.status.SetText(view.GetStatus())
view.status.Draw(screen) view.status.Draw(screen)
view.input.Draw(screen) view.input.Draw(screen)
if view.parent.ShowUserList() { if !view.parent.hideUserList {
view.ulBorder.Draw(screen) view.ulBorder.Draw(screen)
view.userList.Draw(screen) view.userList.Draw(screen)
} }

View File

@ -33,6 +33,8 @@ import (
"maunium.net/go/gomuks/ui/widget" "maunium.net/go/gomuks/ui/widget"
"maunium.net/go/tcell" "maunium.net/go/tcell"
"maunium.net/go/tview" "maunium.net/go/tview"
"bufio"
"os"
) )
type MainView struct { type MainView struct {
@ -51,15 +53,7 @@ type MainView struct {
hideUserList bool hideUserList bool
hideRoomList bool hideRoomList bool
bareDisplay bool bareMessages bool
}
func (view *MainView) ShowRoomList() bool {
return !view.bareDisplay && !view.hideRoomList
}
func (view *MainView) ShowUserList() bool {
return !view.bareDisplay && !view.hideUserList
} }
func (ui *GomuksUI) NewMainView() tview.Primitive { func (ui *GomuksUI) NewMainView() tview.Primitive {
@ -88,7 +82,7 @@ func (ui *GomuksUI) NewMainView() tview.Primitive {
} }
func (view *MainView) Draw(screen tcell.Screen) { func (view *MainView) Draw(screen tcell.Screen) {
if !view.ShowRoomList() { if view.hideRoomList {
view.roomView.SetRect(view.GetRect()) view.roomView.SetRect(view.GetRect())
view.roomView.Draw(screen) view.roomView.Draw(screen)
} else { } else {
@ -213,6 +207,21 @@ func (view *MainView) HandleCommand(roomView *RoomView, command string, args []s
} }
} }
func (view *MainView) ShowBare(roomView *RoomView) {
_, height := view.parent.app.GetScreen().Size()
view.parent.app.Suspend(func() {
print("\033[2J\033[0;0H")
// We don't know how much space there exactly is. Too few messages looks weird,
// and too many messages shouldn't cause any problems, so we just show too many.
height *= 2
fmt.Println(roomView.MessageView().CapturePlaintext(height))
fmt.Println("Press enter to return to normal mode.")
reader := bufio.NewReader(os.Stdin)
reader.ReadRune()
print("\033[2J\033[0;0H")
})
}
func (view *MainView) KeyEventHandler(roomView *RoomView, key *tcell.EventKey) *tcell.EventKey { func (view *MainView) KeyEventHandler(roomView *RoomView, key *tcell.EventKey) *tcell.EventKey {
view.BumpFocus(roomView) view.BumpFocus(roomView)
@ -229,8 +238,7 @@ func (view *MainView) KeyEventHandler(roomView *RoomView, key *tcell.EventKey) *
view.parent.views.AddPage("fuzzy-search-modal", searchModal, true, true) view.parent.views.AddPage("fuzzy-search-modal", searchModal, true, true)
view.parent.app.SetFocus(searchModal) view.parent.app.SetFocus(searchModal)
case c == 'l': case c == 'l':
view.bareDisplay = !view.bareDisplay view.ShowBare(roomView)
view.parent.Render()
default: default:
return key return key
} }