Merge branch 'v0.3.2'
* v0.3.2: Re-enable adding of line and supply documentation Fix problem with scrolling and offset chat view
This commit is contained in:
commit
f30310efa6
@ -81,11 +81,16 @@ func (c *Chat) Buffer() termui.Buffer {
|
|||||||
lines := []Line{}
|
lines := []Line{}
|
||||||
line := Line{}
|
line := Line{}
|
||||||
|
|
||||||
|
// When we encounter a newline or are at the bounds of the chat view we
|
||||||
|
// stop iterating over the cells and add the line to the line array
|
||||||
x := 0
|
x := 0
|
||||||
for _, cell := range cells {
|
for _, cell := range cells {
|
||||||
|
|
||||||
|
// When we encounter a newline we add the line to the array
|
||||||
if cell.Ch == '\n' {
|
if cell.Ch == '\n' {
|
||||||
lines = append(lines, line)
|
lines = append(lines, line)
|
||||||
|
|
||||||
|
// Reset for new line
|
||||||
line = Line{}
|
line = Line{}
|
||||||
x = 0
|
x = 0
|
||||||
continue
|
continue
|
||||||
@ -93,6 +98,8 @@ func (c *Chat) Buffer() termui.Buffer {
|
|||||||
|
|
||||||
if x+cell.Width() > c.List.InnerBounds().Dx() {
|
if x+cell.Width() > c.List.InnerBounds().Dx() {
|
||||||
lines = append(lines, line)
|
lines = append(lines, line)
|
||||||
|
|
||||||
|
// Reset for new line
|
||||||
line = Line{}
|
line = Line{}
|
||||||
x = 0
|
x = 0
|
||||||
}
|
}
|
||||||
@ -100,6 +107,9 @@ func (c *Chat) Buffer() termui.Buffer {
|
|||||||
line.cells = append(line.cells, cell)
|
line.cells = append(line.cells, cell)
|
||||||
x++
|
x++
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Append the last line to the array when we didn't encounter any
|
||||||
|
// newlines or were at the bounds of the chat view
|
||||||
lines = append(lines, line)
|
lines = append(lines, line)
|
||||||
|
|
||||||
// We will print lines bottom up, it will loop over the lines
|
// We will print lines bottom up, it will loop over the lines
|
||||||
@ -113,6 +123,7 @@ func (c *Chat) Buffer() termui.Buffer {
|
|||||||
|
|
||||||
currentY := paneMaxY - 1
|
currentY := paneMaxY - 1
|
||||||
for i := (linesHeight - 1) - c.Offset; i >= 0; i-- {
|
for i := (linesHeight - 1) - c.Offset; i >= 0; i-- {
|
||||||
|
|
||||||
if currentY < paneMinY {
|
if currentY < paneMinY {
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
@ -190,6 +201,10 @@ func (c *Chat) GetMaxItems() int {
|
|||||||
// SetMessages will put the provided messages into the Items field of the
|
// SetMessages will put the provided messages into the Items field of the
|
||||||
// Chat view
|
// Chat view
|
||||||
func (c *Chat) SetMessages(messages []string) {
|
func (c *Chat) SetMessages(messages []string) {
|
||||||
|
// Reset offset first, when scrolling in view and changing channels we
|
||||||
|
// want the offset to be 0 when loading new messages
|
||||||
|
c.Offset = 0
|
||||||
|
|
||||||
for _, msg := range messages {
|
for _, msg := range messages {
|
||||||
c.List.Items = append(c.List.Items, html.UnescapeString(msg))
|
c.List.Items = append(c.List.Items, html.UnescapeString(msg))
|
||||||
}
|
}
|
||||||
@ -216,8 +231,8 @@ func (c *Chat) ScrollUp() {
|
|||||||
c.Offset = c.Offset + 10
|
c.Offset = c.Offset + 10
|
||||||
|
|
||||||
// Protect overscrolling
|
// Protect overscrolling
|
||||||
if c.Offset > len(c.List.Items)-1 {
|
if c.Offset > len(c.List.Items) {
|
||||||
c.Offset = len(c.List.Items) - 1
|
c.Offset = len(c.List.Items)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
4
main.go
4
main.go
@ -16,7 +16,7 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
const (
|
const (
|
||||||
VERSION = "v0.3.1"
|
VERSION = "v0.3.2"
|
||||||
USAGE = `NAME:
|
USAGE = `NAME:
|
||||||
slack-term - slack client for your terminal
|
slack-term - slack client for your terminal
|
||||||
|
|
||||||
@ -27,7 +27,7 @@ VERSION:
|
|||||||
%s
|
%s
|
||||||
|
|
||||||
WEBSITE:
|
WEBSITE:
|
||||||
https://github.com/erroneousboat/slack-term
|
https://github.com/erroneousboat/slack-term
|
||||||
|
|
||||||
GLOBAL OPTIONS:
|
GLOBAL OPTIONS:
|
||||||
--help, -h
|
--help, -h
|
||||||
|
Loading…
x
Reference in New Issue
Block a user