summaryrefslogtreecommitdiff
path: root/ui
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--ui/buffers.go29
-rw-r--r--ui/ui.go48
2 files changed, 66 insertions, 11 deletions
diff --git a/ui/buffers.go b/ui/buffers.go
index 0141a04..7b24831 100644
--- a/ui/buffers.go
+++ b/ui/buffers.go
@@ -52,11 +52,11 @@ func NewLineNow(content string) (line Line) {
}
func (line *Line) Invalidate() {
- line.renderedHeight = -1
+ line.renderedHeight = 0
}
func (line *Line) RenderedHeight(screenWidth int) (height int) {
- if line.renderedHeight < 0 {
+ if line.renderedHeight <= 0 {
line.computeRenderedHeight(screenWidth)
}
height = line.renderedHeight
@@ -250,6 +250,31 @@ func (bs *BufferList) AddLine(idx int, line string, t time.Time, isStatus bool)
}
}
+func (bs *BufferList) AddHistoryLines(idx int, lines []Line) {
+ if len(lines) == 0 {
+ return
+ }
+
+ b := &bs.List[idx]
+ limit := -1
+
+ if len(b.Content) != 0 {
+ firstTime := b.Content[0].Time.Round(time.Millisecond)
+ for i := len(lines) - 1; i >= 0; i-- {
+ if firstTime == lines[i].Time.Round(time.Millisecond) {
+ limit = i
+ break
+ }
+ }
+ }
+
+ if limit == -1 {
+ limit = len(lines)
+ }
+
+ bs.List[idx].Content = append(lines[:limit], b.Content...)
+}
+
func (bs *BufferList) Invalidate() {
for i := range bs.List {
for j := range bs.List[i].Content {
diff --git a/ui/ui.go b/ui/ui.go
index edc805c..75fe8fe 100644
--- a/ui/ui.go
+++ b/ui/ui.go
@@ -80,24 +80,36 @@ func (ui *UI) CurrentBuffer() (title string) {
return
}
-func (ui *UI) NextBuffer() {
- ok := ui.bufferList.Next()
+func (ui *UI) CurrentBufferOldestTime() (t time.Time) {
+ b := ui.bufferList.List[ui.bufferList.Current].Content
+ if len(b) == 0 {
+ t = time.Now()
+ } else {
+ t = b[0].Time
+ }
+ return
+}
+
+func (ui *UI) NextBuffer() (ok bool) {
+ ok = ui.bufferList.Next()
if ok {
ui.scrollAmt = 0
ui.scrollAtTop = false
ui.drawBuffer()
ui.drawStatus()
}
+ return
}
-func (ui *UI) PreviousBuffer() {
- ok := ui.bufferList.Previous()
+func (ui *UI) PreviousBuffer() (ok bool) {
+ ok = ui.bufferList.Previous()
if ok {
ui.scrollAmt = 0
ui.scrollAtTop = false
ui.drawBuffer()
ui.drawStatus()
}
+ return
}
func (ui *UI) ScrollUp() {
@@ -105,8 +117,8 @@ func (ui *UI) ScrollUp() {
return
}
- w, _ := ui.screen.Size()
- ui.scrollAmt += w / 2
+ _, h := ui.screen.Size()
+ ui.scrollAmt += h / 2
ui.drawBuffer()
}
@@ -115,8 +127,8 @@ func (ui *UI) ScrollDown() {
return
}
- w, _ := ui.screen.Size()
- ui.scrollAmt -= w / 2
+ _, h := ui.screen.Size()
+ ui.scrollAmt -= h / 2
if ui.scrollAmt < 0 {
ui.scrollAmt = 0
}
@@ -125,6 +137,10 @@ func (ui *UI) ScrollDown() {
ui.drawBuffer()
}
+func (ui *UI) IsAtTop() bool {
+ return ui.scrollAtTop
+}
+
func (ui *UI) AddBuffer(title string) {
_, ok := ui.bufferList.Add(title)
if ok {
@@ -158,6 +174,20 @@ func (ui *UI) AddLine(buffer string, line string, t time.Time, isStatus bool) {
}
}
+func (ui *UI) AddHistoryLines(buffer string, lines []Line) {
+ idx := ui.bufferList.Idx(buffer)
+ if idx < 0 {
+ return
+ }
+
+ ui.bufferList.AddHistoryLines(idx, lines)
+
+ if idx == ui.bufferList.Current {
+ ui.scrollAtTop = false
+ ui.drawBuffer()
+ }
+}
+
func (ui *UI) Input() string {
return string(ui.textInput)
}
@@ -430,7 +460,7 @@ func (ui *UI) drawBuffer() {
colorState = 0
}
- ui.scrollAtTop = true
+ ui.scrollAtTop = 0 <= y0
ui.screen.Show()
}