mirror of
https://github.com/jesseduffield/lazygit.git
synced 2025-04-27 12:32:37 +02:00
more things
This commit is contained in:
parent
e392b9f86a
commit
cb26c7a1f2
2
go.mod
2
go.mod
@ -14,7 +14,7 @@ require (
|
|||||||
github.com/gookit/color v1.4.2
|
github.com/gookit/color v1.4.2
|
||||||
github.com/imdario/mergo v0.3.11
|
github.com/imdario/mergo v0.3.11
|
||||||
github.com/integrii/flaggy v1.4.0
|
github.com/integrii/flaggy v1.4.0
|
||||||
github.com/jesseduffield/generics v0.0.0-20220319083513-5f145a9c0677
|
github.com/jesseduffield/generics v0.0.0-20220319230408-6eaa96457df2
|
||||||
github.com/jesseduffield/go-git/v5 v5.1.2-0.20201006095850-341962be15a4
|
github.com/jesseduffield/go-git/v5 v5.1.2-0.20201006095850-341962be15a4
|
||||||
github.com/jesseduffield/gocui v0.3.1-0.20220227022729-69f0c798eec8
|
github.com/jesseduffield/gocui v0.3.1-0.20220227022729-69f0c798eec8
|
||||||
github.com/jesseduffield/minimal/gitignore v0.3.3-0.20211018110810-9cde264e6b1e
|
github.com/jesseduffield/minimal/gitignore v0.3.3-0.20211018110810-9cde264e6b1e
|
||||||
|
4
go.sum
4
go.sum
@ -66,8 +66,8 @@ github.com/integrii/flaggy v1.4.0 h1:A1x7SYx4jqu5NSrY14z8Z+0UyX2S5ygfJJrfolWR3zM
|
|||||||
github.com/integrii/flaggy v1.4.0/go.mod h1:tnTxHeTJbah0gQ6/K0RW0J7fMUBk9MCF5blhm43LNpI=
|
github.com/integrii/flaggy v1.4.0/go.mod h1:tnTxHeTJbah0gQ6/K0RW0J7fMUBk9MCF5blhm43LNpI=
|
||||||
github.com/jbenet/go-context v0.0.0-20150711004518-d14ea06fba99 h1:BQSFePA1RWJOlocH6Fxy8MmwDt+yVQYULKfN0RoTN8A=
|
github.com/jbenet/go-context v0.0.0-20150711004518-d14ea06fba99 h1:BQSFePA1RWJOlocH6Fxy8MmwDt+yVQYULKfN0RoTN8A=
|
||||||
github.com/jbenet/go-context v0.0.0-20150711004518-d14ea06fba99/go.mod h1:1lJo3i6rXxKeerYnT8Nvf0QmHCRC1n8sfWVwXF2Frvo=
|
github.com/jbenet/go-context v0.0.0-20150711004518-d14ea06fba99/go.mod h1:1lJo3i6rXxKeerYnT8Nvf0QmHCRC1n8sfWVwXF2Frvo=
|
||||||
github.com/jesseduffield/generics v0.0.0-20220319083513-5f145a9c0677 h1:GoP06WWOE4AvTkAavXkF40nhYsg2hI09uVLDIuxzZYI=
|
github.com/jesseduffield/generics v0.0.0-20220319230408-6eaa96457df2 h1:nGS5ysWioxYaPzwuEK3b4NKzBnNhQjiD1fK3bkn43cQ=
|
||||||
github.com/jesseduffield/generics v0.0.0-20220319083513-5f145a9c0677/go.mod h1:+LLj9/WUPAP8LqCchs7P+7X0R98HiFujVFANdNaxhGk=
|
github.com/jesseduffield/generics v0.0.0-20220319230408-6eaa96457df2/go.mod h1:+LLj9/WUPAP8LqCchs7P+7X0R98HiFujVFANdNaxhGk=
|
||||||
github.com/jesseduffield/go-git/v5 v5.1.2-0.20201006095850-341962be15a4 h1:GOQrmaE8i+KEdB8NzAegKYd4tPn/inM0I1uo0NXFerg=
|
github.com/jesseduffield/go-git/v5 v5.1.2-0.20201006095850-341962be15a4 h1:GOQrmaE8i+KEdB8NzAegKYd4tPn/inM0I1uo0NXFerg=
|
||||||
github.com/jesseduffield/go-git/v5 v5.1.2-0.20201006095850-341962be15a4/go.mod h1:nGNEErzf+NRznT+N2SWqmHnDnF9aLgANB1CUNEan09o=
|
github.com/jesseduffield/go-git/v5 v5.1.2-0.20201006095850-341962be15a4/go.mod h1:nGNEErzf+NRznT+N2SWqmHnDnF9aLgANB1CUNEan09o=
|
||||||
github.com/jesseduffield/gocui v0.3.1-0.20220227022729-69f0c798eec8 h1:9N08i5kjvOfkzMj6THmIM110wPTQLdVYEOHMHT2DFiI=
|
github.com/jesseduffield/gocui v0.3.1-0.20220227022729-69f0c798eec8 h1:9N08i5kjvOfkzMj6THmIM110wPTQLdVYEOHMHT2DFiI=
|
||||||
|
@ -14,6 +14,7 @@ import (
|
|||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
"github.com/aybabtme/humanlog"
|
"github.com/aybabtme/humanlog"
|
||||||
|
"github.com/jesseduffield/generics/slices"
|
||||||
"github.com/jesseduffield/lazygit/pkg/commands"
|
"github.com/jesseduffield/lazygit/pkg/commands"
|
||||||
"github.com/jesseduffield/lazygit/pkg/commands/git_config"
|
"github.com/jesseduffield/lazygit/pkg/commands/git_config"
|
||||||
"github.com/jesseduffield/lazygit/pkg/commands/oscommands"
|
"github.com/jesseduffield/lazygit/pkg/commands/oscommands"
|
||||||
@ -284,13 +285,9 @@ func (app *App) Rebase() error {
|
|||||||
|
|
||||||
// Close closes any resources
|
// Close closes any resources
|
||||||
func (app *App) Close() error {
|
func (app *App) Close() error {
|
||||||
for _, closer := range app.closers {
|
return slices.TryForEach(app.closers, func(closer io.Closer) error {
|
||||||
err := closer.Close()
|
return closer.Close()
|
||||||
if err != nil {
|
})
|
||||||
return err
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return nil
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// KnownError takes an error and tells us whether it's an error that we know about where we can print a nicely formatted version of it rather than panicking with a stack trace
|
// KnownError takes an error and tells us whether it's an error that we know about where we can print a nicely formatted version of it rather than panicking with a stack trace
|
||||||
@ -299,10 +296,10 @@ func (app *App) KnownError(err error) (string, bool) {
|
|||||||
|
|
||||||
knownErrorMessages := []string{app.Tr.MinGitVersionError}
|
knownErrorMessages := []string{app.Tr.MinGitVersionError}
|
||||||
|
|
||||||
for _, message := range knownErrorMessages {
|
if message, ok := slices.Find(knownErrorMessages, func(knownErrorMessage string) bool {
|
||||||
if errorMessage == message {
|
return knownErrorMessage == errorMessage
|
||||||
return message, true
|
}); ok {
|
||||||
}
|
return message, true
|
||||||
}
|
}
|
||||||
|
|
||||||
mappings := []errorMapping{
|
mappings := []errorMapping{
|
||||||
@ -312,11 +309,12 @@ func (app *App) KnownError(err error) (string, bool) {
|
|||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
for _, mapping := range mappings {
|
if mapping, ok := slices.Find(mappings, func(mapping errorMapping) bool {
|
||||||
if strings.Contains(errorMessage, mapping.originalError) {
|
return strings.Contains(errorMessage, mapping.originalError)
|
||||||
return mapping.newError, true
|
}); ok {
|
||||||
}
|
return mapping.newError, true
|
||||||
}
|
}
|
||||||
|
|
||||||
return "", false
|
return "", false
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -141,12 +141,11 @@ outer:
|
|||||||
if existing == nil {
|
if existing == nil {
|
||||||
contextAndViewBindingMap[key] = []*types.Binding{binding}
|
contextAndViewBindingMap[key] = []*types.Binding{binding}
|
||||||
} else {
|
} else {
|
||||||
for _, navBinding := range contextAndViewBindingMap[key] {
|
if !slices.Some(contextAndViewBindingMap[key], func(navBinding *types.Binding) bool {
|
||||||
if navBinding.Description == binding.Description {
|
return navBinding.Description == binding.Description
|
||||||
continue outer
|
}) {
|
||||||
}
|
contextAndViewBindingMap[key] = append(contextAndViewBindingMap[key], binding)
|
||||||
}
|
}
|
||||||
contextAndViewBindingMap[key] = append(contextAndViewBindingMap[key], binding)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
continue outer
|
continue outer
|
||||||
|
@ -3,15 +3,14 @@ package gui
|
|||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
|
|
||||||
|
"github.com/jesseduffield/generics/slices"
|
||||||
"github.com/jesseduffield/lazygit/pkg/constants"
|
"github.com/jesseduffield/lazygit/pkg/constants"
|
||||||
"github.com/jesseduffield/lazygit/pkg/gui/style"
|
"github.com/jesseduffield/lazygit/pkg/gui/style"
|
||||||
)
|
)
|
||||||
|
|
||||||
func (gui *Gui) informationStr() string {
|
func (gui *Gui) informationStr() string {
|
||||||
for _, mode := range gui.modeStatuses() {
|
if activeMode, ok := gui.getActiveMode(); ok {
|
||||||
if mode.isActive() {
|
return activeMode.description()
|
||||||
return mode.description()
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if gui.g.Mouse {
|
if gui.g.Mouse {
|
||||||
@ -23,6 +22,12 @@ func (gui *Gui) informationStr() string {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (gui *Gui) getActiveMode() (modeStatus, bool) {
|
||||||
|
return slices.Find(gui.modeStatuses(), func(mode modeStatus) bool {
|
||||||
|
return mode.isActive()
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
func (gui *Gui) handleInfoClick() error {
|
func (gui *Gui) handleInfoClick() error {
|
||||||
if !gui.g.Mouse {
|
if !gui.g.Mouse {
|
||||||
return nil
|
return nil
|
||||||
@ -33,13 +38,11 @@ func (gui *Gui) handleInfoClick() error {
|
|||||||
cx, _ := view.Cursor()
|
cx, _ := view.Cursor()
|
||||||
width, _ := view.Size()
|
width, _ := view.Size()
|
||||||
|
|
||||||
for _, mode := range gui.modeStatuses() {
|
if activeMode, ok := gui.getActiveMode(); ok {
|
||||||
if mode.isActive() {
|
if width-cx > len(gui.c.Tr.ResetInParentheses) {
|
||||||
if width-cx > len(gui.c.Tr.ResetInParentheses) {
|
return nil
|
||||||
return nil
|
|
||||||
}
|
|
||||||
return mode.reset()
|
|
||||||
}
|
}
|
||||||
|
return activeMode.reset()
|
||||||
}
|
}
|
||||||
|
|
||||||
// if we're not in an active mode we show the donate button
|
// if we're not in an active mode we show the donate button
|
||||||
|
149
vendor/github.com/jesseduffield/generics/slices/slices.go
generated
vendored
149
vendor/github.com/jesseduffield/generics/slices/slices.go
generated
vendored
@ -47,6 +47,32 @@ func MapWithIndex[T any, V any](slice []T, f func(T, int) V) []V {
|
|||||||
return result
|
return result
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TryMap[T any, V any](slice []T, f func(T) (V, error)) ([]V, error) {
|
||||||
|
result := make([]V, 0, len(slice))
|
||||||
|
for _, value := range slice {
|
||||||
|
output, err := f(value)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
result = append(result, output)
|
||||||
|
}
|
||||||
|
|
||||||
|
return result, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func TryMapWithIndex[T any, V any](slice []T, f func(T, int) (V, error)) ([]V, error) {
|
||||||
|
result := make([]V, 0, len(slice))
|
||||||
|
for i, value := range slice {
|
||||||
|
output, err := f(value, i)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
result = append(result, output)
|
||||||
|
}
|
||||||
|
|
||||||
|
return result, nil
|
||||||
|
}
|
||||||
|
|
||||||
// Produces a new slice, leaves the input slice untouched.
|
// Produces a new slice, leaves the input slice untouched.
|
||||||
func FlatMap[T any, V any](slice []T, f func(T) []V) []V {
|
func FlatMap[T any, V any](slice []T, f func(T) []V) []V {
|
||||||
// impossible to know how long this slice will be in the end but the length
|
// impossible to know how long this slice will be in the end but the length
|
||||||
@ -59,6 +85,17 @@ func FlatMap[T any, V any](slice []T, f func(T) []V) []V {
|
|||||||
return result
|
return result
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func FlatMapWithIndex[T any, V any](slice []T, f func(T, int) []V) []V {
|
||||||
|
// impossible to know how long this slice will be in the end but the length
|
||||||
|
// of the original slice is the lower bound
|
||||||
|
result := make([]V, 0, len(slice))
|
||||||
|
for i, value := range slice {
|
||||||
|
result = append(result, f(value, i)...)
|
||||||
|
}
|
||||||
|
|
||||||
|
return result
|
||||||
|
}
|
||||||
|
|
||||||
func Flatten[T any](slice [][]T) []T {
|
func Flatten[T any](slice [][]T) []T {
|
||||||
result := make([]T, 0, len(slice))
|
result := make([]T, 0, len(slice))
|
||||||
for _, subSlice := range slice {
|
for _, subSlice := range slice {
|
||||||
@ -96,6 +133,34 @@ func FilterWithIndex[T any](slice []T, f func(T, int) bool) []T {
|
|||||||
return result
|
return result
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TryFilter[T any](slice []T, test func(T) (bool, error)) ([]T, error) {
|
||||||
|
result := make([]T, 0)
|
||||||
|
for _, element := range slice {
|
||||||
|
ok, err := test(element)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
if ok {
|
||||||
|
result = append(result, element)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return result, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func TryFilterWithIndex[T any](slice []T, test func(T, int) (bool, error)) ([]T, error) {
|
||||||
|
result := make([]T, 0)
|
||||||
|
for i, element := range slice {
|
||||||
|
ok, err := test(element, i)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
if ok {
|
||||||
|
result = append(result, element)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return result, nil
|
||||||
|
}
|
||||||
|
|
||||||
// Mutates original slice. Intended usage is to reassign the slice result to the input slice.
|
// Mutates original slice. Intended usage is to reassign the slice result to the input slice.
|
||||||
func FilterInPlace[T any](slice []T, test func(T) bool) []T {
|
func FilterInPlace[T any](slice []T, test func(T) bool) []T {
|
||||||
newLength := 0
|
newLength := 0
|
||||||
@ -125,10 +190,10 @@ func ReverseInPlace[T any](slice []T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Produces a new slice, leaves the input slice untouched.
|
// Produces a new slice, leaves the input slice untouched.
|
||||||
func FilterMap[T any, E any](slice []T, test func(T) (bool, E)) []E {
|
func FilterMap[T any, E any](slice []T, test func(T) (E, bool)) []E {
|
||||||
result := make([]E, 0, len(slice))
|
result := make([]E, 0, len(slice))
|
||||||
for _, element := range slice {
|
for _, element := range slice {
|
||||||
ok, mapped := test(element)
|
mapped, ok := test(element)
|
||||||
if ok {
|
if ok {
|
||||||
result = append(result, mapped)
|
result = append(result, mapped)
|
||||||
}
|
}
|
||||||
@ -137,17 +202,48 @@ func FilterMap[T any, E any](slice []T, test func(T) (bool, E)) []E {
|
|||||||
return result
|
return result
|
||||||
}
|
}
|
||||||
|
|
||||||
// Produces a new slice, leaves the input slice untouched.
|
func FilterMapWithIndex[T any, E any](slice []T, test func(T, int) (E, bool)) []E {
|
||||||
func FilterThenMap[T any, E any](slice []T, test func(T) bool, mapFn func(T) E) []E {
|
|
||||||
result := make([]E, 0, len(slice))
|
result := make([]E, 0, len(slice))
|
||||||
for _, element := range slice {
|
for i, element := range slice {
|
||||||
if test(element) {
|
mapped, ok := test(element, i)
|
||||||
result = append(result, mapFn(element))
|
if ok {
|
||||||
|
result = append(result, mapped)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return result
|
return result
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TryFilterMap[T any, E any](slice []T, test func(T) (E, bool, error)) ([]E, error) {
|
||||||
|
result := make([]E, 0, len(slice))
|
||||||
|
for _, element := range slice {
|
||||||
|
mapped, ok, err := test(element)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
if ok {
|
||||||
|
result = append(result, mapped)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return result, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func TryFilterMapWithIndex[T any, E any](slice []T, test func(T, int) (E, bool, error)) ([]E, error) {
|
||||||
|
result := make([]E, 0, len(slice))
|
||||||
|
for i, element := range slice {
|
||||||
|
mapped, ok, err := test(element, i)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
if ok {
|
||||||
|
result = append(result, mapped)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return result, nil
|
||||||
|
}
|
||||||
|
|
||||||
// Prepends items to the beginning of a slice.
|
// Prepends items to the beginning of a slice.
|
||||||
// E.g. Prepend([]int{1,2}, 3, 4) = []int{3,4,1,2}
|
// E.g. Prepend([]int{1,2}, 3, 4) = []int{3,4,1,2}
|
||||||
// Mutates original slice. Intended usage is to reassign the slice result to the input slice.
|
// Mutates original slice. Intended usage is to reassign the slice result to the input slice.
|
||||||
@ -241,6 +337,45 @@ func MinBy[T any, V constraints.Ordered](slice []T, f func(T) V) V {
|
|||||||
return min
|
return min
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func Find[T any](slice []T, f func(T) bool) (T, bool) {
|
||||||
|
for _, element := range slice {
|
||||||
|
if f(element) {
|
||||||
|
return element, true
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return zero[T](), false
|
||||||
|
}
|
||||||
|
|
||||||
|
func ForEach[T any](slice []T, f func(T)) {
|
||||||
|
for _, element := range slice {
|
||||||
|
f(element)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func ForEachWithIndex[T any](slice []T, f func(T, int)) {
|
||||||
|
for i, element := range slice {
|
||||||
|
f(element, i)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func TryForEach[T any](slice []T, f func(T) error) error {
|
||||||
|
for _, element := range slice {
|
||||||
|
if err := f(element); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func TryForEachWithIndex[T any](slice []T, f func(T, int) error) error {
|
||||||
|
for i, element := range slice {
|
||||||
|
if err := f(element, i); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
func zero[T any]() T {
|
func zero[T any]() T {
|
||||||
var value T
|
var value T
|
||||||
return value
|
return value
|
||||||
|
2
vendor/modules.txt
vendored
2
vendor/modules.txt
vendored
@ -120,7 +120,7 @@ github.com/integrii/flaggy
|
|||||||
# github.com/jbenet/go-context v0.0.0-20150711004518-d14ea06fba99
|
# github.com/jbenet/go-context v0.0.0-20150711004518-d14ea06fba99
|
||||||
## explicit
|
## explicit
|
||||||
github.com/jbenet/go-context/io
|
github.com/jbenet/go-context/io
|
||||||
# github.com/jesseduffield/generics v0.0.0-20220319083513-5f145a9c0677
|
# github.com/jesseduffield/generics v0.0.0-20220319230408-6eaa96457df2
|
||||||
## explicit; go 1.18
|
## explicit; go 1.18
|
||||||
github.com/jesseduffield/generics/maps
|
github.com/jesseduffield/generics/maps
|
||||||
github.com/jesseduffield/generics/set
|
github.com/jesseduffield/generics/set
|
||||||
|
Loading…
x
Reference in New Issue
Block a user