Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix scrolling after gocui update #473

Open
wants to merge 5 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
FROM alpine:3.12
FROM alpine:3.18

ARG DOCKER_CLI_VERSION=${DOCKER_CLI_VERSION}
RUN wget -O- https://download.docker.com/linux/static/stable/$(uname -m)/docker-${DOCKER_CLI_VERSION}.tgz | \
Expand Down
31 changes: 5 additions & 26 deletions runtime/ui/view/cursor.go
Original file line number Diff line number Diff line change
@@ -1,38 +1,17 @@
package view

import (
"errors"

"github.com/awesome-gocui/gocui"
)

// CursorDown moves the cursor down in the currently selected gocui pane, scrolling the screen as needed.
func CursorDown(g *gocui.Gui, v *gocui.View) error {
return CursorStep(g, v, 1)
func CursorDown(v *gocui.View, step uint) error {
v.MoveCursor(0, int(step))
return nil
}

// CursorUp moves the cursor up in the currently selected gocui pane, scrolling the screen as needed.
func CursorUp(g *gocui.Gui, v *gocui.View) error {
return CursorStep(g, v, -1)
}

// Moves the cursor the given step distance, setting the origin to the new cursor line
func CursorStep(g *gocui.Gui, v *gocui.View, step int) error {
cx, cy := v.Cursor()

// if there isn't a next line
line, err := v.Line(cy + step)
if err != nil {
return err
}
if len(line) == 0 {
return errors.New("unable to move the cursor, empty line")
}
if err := v.SetCursor(cx, cy+step); err != nil {
ox, oy := v.Origin()
if err := v.SetOrigin(ox, oy+step); err != nil {
return err
}
}
func CursorUp(v *gocui.View, step uint) error {
v.MoveCursor(0, int(-step))
return nil
}
20 changes: 4 additions & 16 deletions runtime/ui/view/image_details.go
Original file line number Diff line number Diff line change
Expand Up @@ -136,32 +136,20 @@ func (v *ImageDetails) IsVisible() bool {

func (v *ImageDetails) PageUp() error {
_, height := v.body.Size()
if err := CursorStep(v.gui, v.body, -height); err != nil {
logrus.Debugf("Couldn't move the cursor up by %d steps", height)
}
return nil
return CursorUp(v.body, uint(height))
}

func (v *ImageDetails) PageDown() error {
_, height := v.body.Size()
if err := CursorStep(v.gui, v.body, height); err != nil {
logrus.Debugf("Couldn't move the cursor down by %d steps", height)
}
return nil
return CursorDown(v.body, uint(height))
}

func (v *ImageDetails) CursorUp() error {
if err := CursorUp(v.gui, v.body); err != nil {
logrus.Debug("Couldn't move the cursor up")
}
return nil
return CursorUp(v.body, 1)
}

func (v *ImageDetails) CursorDown() error {
if err := CursorDown(v.gui, v.body); err != nil {
logrus.Debug("Couldn't move the cursor down")
}
return nil
return CursorDown(v.body, 1)
}

// KeyHelp indicates all the possible actions a user can take while the current pane is selected (currently does nothing).
Expand Down
106 changes: 34 additions & 72 deletions runtime/ui/view/layer.go
Original file line number Diff line number Diff line change
Expand Up @@ -141,11 +141,16 @@
}
v.helpKeys = helpKeys

return v.Render()
_, height := v.body.Size()
v.vm.Setup(0, height)
_ = v.Update()
_ = v.Render()

return nil
}

// height obtains the height of the current pane (taking into account the lost space due to the header).
func (v *Layer) height() uint {

Check failure on line 153 in runtime/ui/view/layer.go

View workflow job for this annotation

GitHub Actions / Static analysis

func `(*Layer).height` is unused (unused)
_, height := v.body.Size()
return uint(height - 1)
}
Expand All @@ -161,62 +166,48 @@

// PageDown moves to next page putting the cursor on top
func (v *Layer) PageDown() error {
step := int(v.height()) + 1
targetLayerIndex := v.vm.LayerIndex + step

if targetLayerIndex > len(v.vm.Layers) {
step -= targetLayerIndex - (len(v.vm.Layers) - 1)
}

if step > 0 {
// err := CursorStep(v.gui, v.body, step)
err := error(nil)
if err == nil {
return v.SetCursor(v.vm.LayerIndex + step)
if v.vm.PageDown() {
err := v.notifyLayerChangeListeners()
if err != nil {
return err
}
return v.Render()
}
return nil
}

// PageUp moves to previous page putting the cursor on top
func (v *Layer) PageUp() error {
step := int(v.height()) + 1
targetLayerIndex := v.vm.LayerIndex - step

if targetLayerIndex < 0 {
step += targetLayerIndex
}

if step > 0 {
// err := CursorStep(v.gui, v.body, -step)
err := error(nil)
if err == nil {
return v.SetCursor(v.vm.LayerIndex - step)
if v.vm.PageUp() {
err := v.notifyLayerChangeListeners()
if err != nil {
return err
}
return v.Render()
}
return nil
}

// CursorDown moves the cursor down in the layer pane (selecting a higher layer).
func (v *Layer) CursorDown() error {
if v.vm.LayerIndex < len(v.vm.Layers)-1 {
// err := CursorDown(v.gui, v.body)
err := error(nil)
if err == nil {
return v.SetCursor(v.vm.LayerIndex + 1)
if v.vm.CursorDown() {
err := v.notifyLayerChangeListeners()
if err != nil {
return err
}
return v.Render()
}
return nil
}

// CursorUp moves the cursor up in the layer pane (selecting a lower layer).
func (v *Layer) CursorUp() error {
if v.vm.LayerIndex > 0 {
// err := CursorUp(v.gui, v.body)
err := error(nil)
if err == nil {
return v.SetCursor(v.vm.LayerIndex - 1)
if v.vm.CursorUp() {
err := v.notifyLayerChangeListeners()
if err != nil {
return err
}
return v.Render()
}
return nil
}
Expand All @@ -243,21 +234,6 @@
return v.notifyLayerChangeListeners()
}

// renderCompareBar returns the formatted string for the given layer.
func (v *Layer) renderCompareBar(layerIdx int) string {
bottomTreeStart, bottomTreeStop, topTreeStart, topTreeStop := v.vm.GetCompareIndexes()
result := " "

if layerIdx >= bottomTreeStart && layerIdx <= bottomTreeStop {
result = format.CompareBottom(" ")
}
if layerIdx >= topTreeStart && layerIdx <= topTreeStop {
result = format.CompareTop(" ")
}

return result
}

func (v *Layer) ConstrainLayout() {
if !v.constrainedRealEstate {
logrus.Debugf("constraining layer layout")
Expand Down Expand Up @@ -293,7 +269,7 @@
logrus.Tracef("view.Render() %s", v.Name())

// indicate when selected
title := "Layers"
title := fmt.Sprintf("Layers (%d / %d)", v.vm.LayerIndex+1, len(v.vm.Layers))
isSelected := v.gui.CurrentView() == v.body

v.gui.Update(func(g *gocui.Gui) error {
Expand All @@ -319,28 +295,14 @@

// update contents
v.body.Clear()
for idx, layer := range v.vm.Layers {
var layerStr string
if v.constrainedRealEstate {
layerStr = fmt.Sprintf("%-4d", layer.Index)
} else {
layerStr = layer.String()
}

compareBar := v.renderCompareBar(idx)

if idx == v.vm.LayerIndex {
_, err = fmt.Fprintln(v.body, compareBar+" "+format.Selected(layerStr))
} else {
_, err = fmt.Fprintln(v.body, compareBar+" "+layerStr)
}

if err != nil {
logrus.Debug("unable to write to buffer: ", err)
return err
}
v.vm.Update(v.constrainedRealEstate)

Check failure on line 298 in runtime/ui/view/layer.go

View workflow job for this annotation

GitHub Actions / Static analysis

Error return value of `v.vm.Update` is not checked (errcheck)
err = v.vm.Render()
if err != nil {
return err
}
return nil
_, err = fmt.Fprint(v.body, v.vm.Buffer.String())

return err
})
return nil
}
Expand Down
10 changes: 2 additions & 8 deletions runtime/ui/view/layer_details.go
Original file line number Diff line number Diff line change
Expand Up @@ -113,18 +113,12 @@ func (v *LayerDetails) IsVisible() bool {

// CursorUp moves the cursor up in the details pane
func (v *LayerDetails) CursorUp() error {
if err := CursorUp(v.gui, v.body); err != nil {
logrus.Debug("Couldn't move the cursor up")
}
return nil
return CursorUp(v.body, 1)
}

// CursorDown moves the cursor up in the details pane
func (v *LayerDetails) CursorDown() error {
if err := CursorDown(v.gui, v.body); err != nil {
logrus.Debug("Couldn't move the cursor down")
}
return nil
return CursorDown(v.body, 1)
}

// KeyHelp indicates all the possible actions a user can take while the current pane is selected (currently does nothing).
Expand Down
Loading
Loading