Add real bare view
This commit is contained in:
parent
bedb9979a9
commit
1d44d3da1a
@ -171,7 +171,7 @@ func (view *MessageView) AddMessage(ifcMessage ifc.Message, direction ifc.Messag
|
||||
view.updateWidestSender(message.Sender())
|
||||
|
||||
_, _, width, _ := view.GetRect()
|
||||
bare := view.parent.parent.bareDisplay
|
||||
bare := view.parent.parent.bareMessages
|
||||
if !bare {
|
||||
width -= view.TimestampWidth + TimestampSenderGap + view.widestSender + SenderMessageGap
|
||||
}
|
||||
@ -264,7 +264,7 @@ func (view *MessageView) replaceBuffer(original messages.UIMessage, new messages
|
||||
|
||||
func (view *MessageView) recalculateBuffers() {
|
||||
_, _, width, height := view.GetRect()
|
||||
bareMode := view.parent.parent.bareDisplay
|
||||
bareMode := view.parent.parent.bareMessages
|
||||
if !bareMode {
|
||||
width -= view.TimestampWidth + TimestampSenderGap + view.widestSender + SenderMessageGap
|
||||
}
|
||||
@ -456,6 +456,26 @@ func (view *MessageView) getIndexOffset(screen tcell.Screen, height, messageX in
|
||||
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) {
|
||||
x, y, _, height := view.GetRect()
|
||||
view.recalculateBuffers()
|
||||
@ -469,7 +489,7 @@ func (view *MessageView) Draw(screen tcell.Screen) {
|
||||
messageX := usernameX + view.widestSender + SenderMessageGap
|
||||
separatorX := usernameX + view.widestSender + SenderSeparatorGap
|
||||
|
||||
bareMode := view.parent.parent.bareDisplay
|
||||
bareMode := view.parent.parent.bareMessages
|
||||
if bareMode {
|
||||
messageX = 0
|
||||
}
|
||||
|
@ -29,6 +29,7 @@ type UIMessage interface {
|
||||
RecalculateBuffer()
|
||||
Buffer() []tstring.TString
|
||||
Height() int
|
||||
PlainText() string
|
||||
|
||||
RealSender() string
|
||||
RegisterMatrix(matrix ifc.MatrixContainer)
|
||||
|
@ -202,7 +202,7 @@ func (view *RoomView) Draw(screen tcell.Screen) {
|
||||
statusRow = contentRow + contentHeight
|
||||
inputRow = statusRow + StatusBarHeight
|
||||
)
|
||||
if !view.parent.ShowUserList() {
|
||||
if view.parent.hideUserList {
|
||||
contentWidth = width
|
||||
}
|
||||
|
||||
@ -210,7 +210,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.ShowUserList() && userListColumn > x {
|
||||
if !view.parent.hideUserList && userListColumn > x {
|
||||
view.userList.SetRect(userListColumn, contentRow, UserListWidth, 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.Draw(screen)
|
||||
view.input.Draw(screen)
|
||||
if view.parent.ShowUserList() {
|
||||
if !view.parent.hideUserList {
|
||||
view.ulBorder.Draw(screen)
|
||||
view.userList.Draw(screen)
|
||||
}
|
||||
|
@ -33,6 +33,8 @@ import (
|
||||
"maunium.net/go/gomuks/ui/widget"
|
||||
"maunium.net/go/tcell"
|
||||
"maunium.net/go/tview"
|
||||
"bufio"
|
||||
"os"
|
||||
)
|
||||
|
||||
type MainView struct {
|
||||
@ -51,15 +53,7 @@ type MainView struct {
|
||||
|
||||
hideUserList bool
|
||||
hideRoomList bool
|
||||
bareDisplay bool
|
||||
}
|
||||
|
||||
func (view *MainView) ShowRoomList() bool {
|
||||
return !view.bareDisplay && !view.hideRoomList
|
||||
}
|
||||
|
||||
func (view *MainView) ShowUserList() bool {
|
||||
return !view.bareDisplay && !view.hideUserList
|
||||
bareMessages bool
|
||||
}
|
||||
|
||||
func (ui *GomuksUI) NewMainView() tview.Primitive {
|
||||
@ -88,7 +82,7 @@ func (ui *GomuksUI) NewMainView() tview.Primitive {
|
||||
}
|
||||
|
||||
func (view *MainView) Draw(screen tcell.Screen) {
|
||||
if !view.ShowRoomList() {
|
||||
if view.hideRoomList {
|
||||
view.roomView.SetRect(view.GetRect())
|
||||
view.roomView.Draw(screen)
|
||||
} 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 {
|
||||
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.app.SetFocus(searchModal)
|
||||
case c == 'l':
|
||||
view.bareDisplay = !view.bareDisplay
|
||||
view.parent.Render()
|
||||
view.ShowBare(roomView)
|
||||
default:
|
||||
return key
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user