aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTulir Asokan <tulir@maunium.net>2018-05-23 00:44:29 +0300
committerTulir Asokan <tulir@maunium.net>2018-05-23 00:44:29 +0300
commit1d44d3da1a383121318ac64fe76fb741d3b85375 (patch)
tree86e160a481e44d8657ed537e50e2edc1afa69f78
parentbedb9979a9b65dad9d72dcbdb3174508d3714f36 (diff)
Add real bare view
-rw-r--r--ui/message-view.go26
-rw-r--r--ui/messages/message.go1
-rw-r--r--ui/room-view.go6
-rw-r--r--ui/view-main.go32
4 files changed, 47 insertions, 18 deletions
diff --git a/ui/message-view.go b/ui/message-view.go
index 6ee92f5..b6b7ee4 100644
--- a/ui/message-view.go
+++ b/ui/message-view.go
@@ -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
}
diff --git a/ui/messages/message.go b/ui/messages/message.go
index 98a84e0..0de2835 100644
--- a/ui/messages/message.go
+++ b/ui/messages/message.go
@@ -29,6 +29,7 @@ type UIMessage interface {
RecalculateBuffer()
Buffer() []tstring.TString
Height() int
+ PlainText() string
RealSender() string
RegisterMatrix(matrix ifc.MatrixContainer)
diff --git a/ui/room-view.go b/ui/room-view.go
index e39506a..fc2a049 100644
--- a/ui/room-view.go
+++ b/ui/room-view.go
@@ -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)
}
diff --git a/ui/view-main.go b/ui/view-main.go
index bda5d80..fd9d606 100644
--- a/ui/view-main.go
+++ b/ui/view-main.go
@@ -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
}