mirror of
https://github.com/jesseduffield/lazydocker.git
synced 2026-07-25 08:31:03 +00:00
use lazycore stuff
This commit is contained in:
parent
52d2c1ce8c
commit
82516385c0
9 changed files with 19 additions and 37 deletions
2
go.mod
2
go.mod
|
|
@ -15,7 +15,7 @@ require (
|
||||||
github.com/jesseduffield/asciigraph v0.0.0-20190605104717-6d88e39309ee
|
github.com/jesseduffield/asciigraph v0.0.0-20190605104717-6d88e39309ee
|
||||||
github.com/jesseduffield/gocui v0.3.1-0.20221023185936-ef06450f4fdc
|
github.com/jesseduffield/gocui v0.3.1-0.20221023185936-ef06450f4fdc
|
||||||
github.com/jesseduffield/kill v0.0.0-20220618033138-bfbe04675d10
|
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/jesseduffield/yaml v0.0.0-20190702115811-b900b7e08b56
|
||||||
github.com/mattn/go-runewidth v0.0.14
|
github.com/mattn/go-runewidth v0.0.14
|
||||||
github.com/mcuadros/go-lookup v0.0.0-20171110082742-5650f26be767
|
github.com/mcuadros/go-lookup v0.0.0-20171110082742-5650f26be767
|
||||||
|
|
|
||||||
4
go.sum
4
go.sum
|
|
@ -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/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 h1:jmpr7KpX2+2GRiE91zTgfq49QvgiqB0nbmlwZ8UnOx0=
|
||||||
github.com/jesseduffield/kill v0.0.0-20220618033138-bfbe04675d10/go.mod h1:aA97kHeNA+sj2Hbki0pvLslmE4CbDyhBeSSTUUnOuVo=
|
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-20221023210126-718a4caea996 h1:CH1en6GpXSwnXl5Ehc4WX1NpS3uw9qbi7o9A4T2YYmA=
|
||||||
github.com/jesseduffield/lazycore v0.0.0-20221010211550-2c30efd18b93/go.mod h1:qxN4mHOAyeIDLP7IK7defgPClM/z1Kze8VVQiaEjzsQ=
|
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 h1:33wSxJWU/f2TAozHYtJ8zqBxEnEVYM+22moLoiAkxvg=
|
||||||
github.com/jesseduffield/yaml v0.0.0-20190702115811-b900b7e08b56/go.mod h1:FZJBwOhE+RXz8EVZfY+xnbCw2cVOwxlK3/aIi581z/s=
|
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=
|
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"
|
throttle "github.com/boz/go-throttle"
|
||||||
"github.com/jesseduffield/gocui"
|
"github.com/jesseduffield/gocui"
|
||||||
|
lcUtils "github.com/jesseduffield/lazycore/pkg/utils"
|
||||||
"github.com/jesseduffield/lazydocker/pkg/commands"
|
"github.com/jesseduffield/lazydocker/pkg/commands"
|
||||||
"github.com/jesseduffield/lazydocker/pkg/config"
|
"github.com/jesseduffield/lazydocker/pkg/config"
|
||||||
"github.com/jesseduffield/lazydocker/pkg/i18n"
|
"github.com/jesseduffield/lazydocker/pkg/i18n"
|
||||||
"github.com/jesseduffield/lazydocker/pkg/tasks"
|
"github.com/jesseduffield/lazydocker/pkg/tasks"
|
||||||
"github.com/jesseduffield/lazydocker/pkg/utils"
|
|
||||||
"github.com/sasha-s/go-deadlock"
|
"github.com/sasha-s/go-deadlock"
|
||||||
"github.com/sirupsen/logrus"
|
"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
|
// 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.
|
// 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()
|
gui.g.Close()
|
||||||
})
|
})
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -6,6 +6,7 @@ import (
|
||||||
|
|
||||||
"github.com/go-errors/errors"
|
"github.com/go-errors/errors"
|
||||||
"github.com/jesseduffield/gocui"
|
"github.com/jesseduffield/gocui"
|
||||||
|
lcUtils "github.com/jesseduffield/lazycore/pkg/utils"
|
||||||
"github.com/jesseduffield/lazydocker/pkg/utils"
|
"github.com/jesseduffield/lazydocker/pkg/utils"
|
||||||
"github.com/samber/lo"
|
"github.com/samber/lo"
|
||||||
)
|
)
|
||||||
|
|
@ -19,14 +20,14 @@ type ListPanel[T comparable] struct {
|
||||||
func (self *ListPanel[T]) setSelectedLineIdx(value int) {
|
func (self *ListPanel[T]) setSelectedLineIdx(value int) {
|
||||||
clampedValue := 0
|
clampedValue := 0
|
||||||
if self.list.Len() > 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
|
self.selectedIdx = clampedValue
|
||||||
}
|
}
|
||||||
|
|
||||||
func (self *ListPanel[T]) clampSelectedLineIdx() {
|
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 {
|
if clamped != self.selectedIdx {
|
||||||
self.selectedIdx = clamped
|
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
|
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
|
// Style used on menu items that open another menu
|
||||||
func OpensMenuStyle(str string) string {
|
func OpensMenuStyle(str string) string {
|
||||||
return ColoredString(fmt.Sprintf("%s...", str), color.FgMagenta)
|
return ColoredString(fmt.Sprintf("%s...", str), color.FgMagenta)
|
||||||
|
|
|
||||||
|
|
@ -5,7 +5,6 @@ import (
|
||||||
"sync"
|
"sync"
|
||||||
)
|
)
|
||||||
|
|
||||||
// TODO: extract into lazycore repo.
|
|
||||||
// This wraps a writer and ensures that before we actually write anything we call a given function first
|
// This wraps a writer and ensures that before we actually write anything we call a given function first
|
||||||
|
|
||||||
type OnceWriter struct {
|
type OnceWriter struct {
|
||||||
10
vendor/github.com/jesseduffield/lazycore/pkg/utils/utils.go
generated
vendored
10
vendor/github.com/jesseduffield/lazycore/pkg/utils/utils.go
generated
vendored
|
|
@ -22,6 +22,16 @@ func Max(x, y int) int {
|
||||||
return y
|
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.
|
// GetLazyRootDirectory finds a lazy project root directory.
|
||||||
//
|
//
|
||||||
// It's used for cheatsheet scripts and integration tests. Not to be confused with finding the
|
// It's used for cheatsheet scripts and integration tests. Not to be confused with finding the
|
||||||
|
|
|
||||||
2
vendor/modules.txt
vendored
2
vendor/modules.txt
vendored
|
|
@ -118,7 +118,7 @@ github.com/jesseduffield/gocui
|
||||||
# github.com/jesseduffield/kill v0.0.0-20220618033138-bfbe04675d10
|
# github.com/jesseduffield/kill v0.0.0-20220618033138-bfbe04675d10
|
||||||
## explicit; go 1.18
|
## explicit; go 1.18
|
||||||
github.com/jesseduffield/kill
|
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
|
## explicit; go 1.18
|
||||||
github.com/jesseduffield/lazycore/pkg/boxlayout
|
github.com/jesseduffield/lazycore/pkg/boxlayout
|
||||||
github.com/jesseduffield/lazycore/pkg/utils
|
github.com/jesseduffield/lazycore/pkg/utils
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue