use lazycore stuff

pull/392/head
Jesse Duffield 2 years ago
parent 52d2c1ce8c
commit 82516385c0

@ -15,7 +15,7 @@ require (
github.com/jesseduffield/asciigraph v0.0.0-20190605104717-6d88e39309ee
github.com/jesseduffield/gocui v0.3.1-0.20221023185936-ef06450f4fdc
github.com/jesseduffield/kill v0.0.0-20220618033138-bfbe04675d10
github.com/jesseduffield/lazycore v0.0.0-20221010211550-2c30efd18b93
github.com/jesseduffield/lazycore v0.0.0-20221023210126-718a4caea996
github.com/jesseduffield/yaml v0.0.0-20190702115811-b900b7e08b56
github.com/mattn/go-runewidth v0.0.14
github.com/mcuadros/go-lookup v0.0.0-20171110082742-5650f26be767

@ -52,8 +52,8 @@ github.com/jesseduffield/gocui v0.3.1-0.20221023185936-ef06450f4fdc h1:Gi/uDpmlB
github.com/jesseduffield/gocui v0.3.1-0.20221023185936-ef06450f4fdc/go.mod h1:znJuCDnF2Ph40YZSlBwdX/4GEofnIoWLGdT4mK5zRAU=
github.com/jesseduffield/kill v0.0.0-20220618033138-bfbe04675d10 h1:jmpr7KpX2+2GRiE91zTgfq49QvgiqB0nbmlwZ8UnOx0=
github.com/jesseduffield/kill v0.0.0-20220618033138-bfbe04675d10/go.mod h1:aA97kHeNA+sj2Hbki0pvLslmE4CbDyhBeSSTUUnOuVo=
github.com/jesseduffield/lazycore v0.0.0-20221010211550-2c30efd18b93 h1:zY7ymCjXC7fZeJVXDpiicYx6c2YFgvsdZSOdch2f7gU=
github.com/jesseduffield/lazycore v0.0.0-20221010211550-2c30efd18b93/go.mod h1:qxN4mHOAyeIDLP7IK7defgPClM/z1Kze8VVQiaEjzsQ=
github.com/jesseduffield/lazycore v0.0.0-20221023210126-718a4caea996 h1:CH1en6GpXSwnXl5Ehc4WX1NpS3uw9qbi7o9A4T2YYmA=
github.com/jesseduffield/lazycore v0.0.0-20221023210126-718a4caea996/go.mod h1:qxN4mHOAyeIDLP7IK7defgPClM/z1Kze8VVQiaEjzsQ=
github.com/jesseduffield/yaml v0.0.0-20190702115811-b900b7e08b56 h1:33wSxJWU/f2TAozHYtJ8zqBxEnEVYM+22moLoiAkxvg=
github.com/jesseduffield/yaml v0.0.0-20190702115811-b900b7e08b56/go.mod h1:FZJBwOhE+RXz8EVZfY+xnbCw2cVOwxlK3/aIi581z/s=
github.com/kisielk/errcheck v1.2.0/go.mod h1:/BMXB+zMLi60iA8Vv6Ksmxu/1UDYcXs4uQLJ+jE2L00=

@ -12,11 +12,11 @@ import (
throttle "github.com/boz/go-throttle"
"github.com/jesseduffield/gocui"
lcUtils "github.com/jesseduffield/lazycore/pkg/utils"
"github.com/jesseduffield/lazydocker/pkg/commands"
"github.com/jesseduffield/lazydocker/pkg/config"
"github.com/jesseduffield/lazydocker/pkg/i18n"
"github.com/jesseduffield/lazydocker/pkg/tasks"
"github.com/jesseduffield/lazydocker/pkg/utils"
"github.com/sasha-s/go-deadlock"
"github.com/sirupsen/logrus"
)
@ -188,7 +188,7 @@ func (gui *Gui) Run() error {
// if the deadlock package wants to report a deadlock, we first need to
// close the gui so that we can actually read what it prints.
deadlock.Opts.LogBuf = utils.NewOnceWriter(os.Stderr, func() {
deadlock.Opts.LogBuf = lcUtils.NewOnceWriter(os.Stderr, func() {
gui.g.Close()
})

@ -6,6 +6,7 @@ import (
"github.com/go-errors/errors"
"github.com/jesseduffield/gocui"
lcUtils "github.com/jesseduffield/lazycore/pkg/utils"
"github.com/jesseduffield/lazydocker/pkg/utils"
"github.com/samber/lo"
)
@ -19,14 +20,14 @@ type ListPanel[T comparable] struct {
func (self *ListPanel[T]) setSelectedLineIdx(value int) {
clampedValue := 0
if self.list.Len() > 0 {
clampedValue = utils.Clamp(value, 0, self.list.Len()-1)
clampedValue = lcUtils.Clamp(value, 0, self.list.Len()-1)
}
self.selectedIdx = clampedValue
}
func (self *ListPanel[T]) clampSelectedLineIdx() {
clamped := utils.Clamp(self.selectedIdx, 0, self.list.Len()-1)
clamped := lcUtils.Clamp(self.selectedIdx, 0, self.list.Len()-1)
if clamped != self.selectedIdx {
self.selectedIdx = clamped

@ -1,19 +0,0 @@
package utils
import (
"bytes"
"testing"
)
func TestOnceWriter(t *testing.T) {
innerWriter := bytes.NewBuffer(nil)
counter := 0
onceWriter := NewOnceWriter(innerWriter, func() {
counter += 1
})
_, _ = onceWriter.Write([]byte("hello"))
_, _ = onceWriter.Write([]byte("hello"))
if counter != 1 {
t.Errorf("expected counter to be 1, got %d", counter)
}
}

@ -335,15 +335,6 @@ func IsValidHexValue(v string) bool {
return true
}
func Clamp(x int, min int, max int) int {
if x < min {
return min
} else if x > max {
return max
}
return x
}
// Style used on menu items that open another menu
func OpensMenuStyle(str string) string {
return ColoredString(fmt.Sprintf("%s...", str), color.FgMagenta)

@ -5,7 +5,6 @@ import (
"sync"
)
// TODO: extract into lazycore repo.
// This wraps a writer and ensures that before we actually write anything we call a given function first
type OnceWriter struct {

@ -22,6 +22,16 @@ func Max(x, y int) int {
return y
}
// Clamp returns a value x restricted between min and max
func Clamp(x int, min int, max int) int {
if x < min {
return min
} else if x > max {
return max
}
return x
}
// GetLazyRootDirectory finds a lazy project root directory.
//
// It's used for cheatsheet scripts and integration tests. Not to be confused with finding the

@ -118,7 +118,7 @@ github.com/jesseduffield/gocui
# github.com/jesseduffield/kill v0.0.0-20220618033138-bfbe04675d10
## explicit; go 1.18
github.com/jesseduffield/kill
# github.com/jesseduffield/lazycore v0.0.0-20221010211550-2c30efd18b93
# github.com/jesseduffield/lazycore v0.0.0-20221023210126-718a4caea996
## explicit; go 1.18
github.com/jesseduffield/lazycore/pkg/boxlayout
github.com/jesseduffield/lazycore/pkg/utils

Loading…
Cancel
Save