Merge pull request #23 from rkfg/cursor_fix

Constrain the cursor and prevent segfaults
pull/24/head
Edouard 3 years ago committed by GitHub
commit bee3118ee2
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -83,6 +83,9 @@ func (c Channels) currentColumnIndex() int {
func (c Channels) Sort(column string, order models.Order) { func (c Channels) Sort(column string, order models.Order) {
if column == "" { if column == "" {
index := c.currentColumnIndex() index := c.currentColumnIndex()
if index >= len(c.columns) {
return
}
col := c.columns[index] col := c.columns[index]
if col.sort == nil { if col.sort == nil {
return return
@ -134,15 +137,23 @@ func (c *Channels) SetOrigin(ox, oy int) error {
func (c *Channels) Speed() (int, int, int, int) { func (c *Channels) Speed() (int, int, int, int) {
current := c.currentColumnIndex() current := c.currentColumnIndex()
up := 0
down := 0
if c.Index() > 0 {
up = 1
}
if c.Index() < c.channels.Len()-1 {
down = 1
}
if current > len(c.columns)-1 { if current > len(c.columns)-1 {
return 0, c.columns[current-1].width + 1, 1, 1 return 0, c.columns[current-1].width + 1, down, up
} }
if current == 0 { if current == 0 {
return c.columns[0].width + 1, 0, 1, 1 return c.columns[0].width + 1, 0, down, up
} }
return c.columns[current].width + 1, return c.columns[current].width + 1,
c.columns[current-1].width + 1, c.columns[current-1].width + 1,
1, 1 down, up
} }
func (c Channels) Index() int { func (c Channels) Index() int {

@ -42,7 +42,11 @@ func (h Menu) Cursor() (int, int) {
} }
func (h Menu) Speed() (int, int, int, int) { func (h Menu) Speed() (int, int, int, int) {
return 0, 0, 1, 1 down := 0
if h.cy+h.oy < len(menu)-1 {
down = 1
}
return 0, 0, down, 1
} }
func (h *Menu) SetCursor(x, y int) error { func (h *Menu) SetCursor(x, y int) error {

@ -117,20 +117,31 @@ func (c *Transactions) SetOrigin(ox, oy int) error {
func (c *Transactions) Speed() (int, int, int, int) { func (c *Transactions) Speed() (int, int, int, int) {
current := c.currentColumnIndex() current := c.currentColumnIndex()
up := 0
down := 0
if c.Index() > 0 {
up = 1
}
if c.Index() < c.transactions.Len()-1 {
down = 1
}
if current > len(c.columns)-1 { if current > len(c.columns)-1 {
return 0, c.columns[current-1].width + 1, 1, 1 return 0, c.columns[current-1].width + 1, down, up
} }
if current == 0 { if current == 0 {
return c.columns[0].width + 1, 0, 1, 1 return c.columns[0].width + 1, 0, down, up
} }
return c.columns[current].width + 1, return c.columns[current].width + 1,
c.columns[current-1].width + 1, c.columns[current-1].width + 1,
1, 1 down, up
} }
func (c *Transactions) Sort(column string, order models.Order) { func (c *Transactions) Sort(column string, order models.Order) {
if column == "" { if column == "" {
index := c.currentColumnIndex() index := c.currentColumnIndex()
if index >= len(c.columns) {
return
}
col := c.columns[index] col := c.columns[index]
if col.sort == nil { if col.sort == nil {
return return

Loading…
Cancel
Save