Use maps package for generic keys/values functions
This commit is contained in:
parent
7ce83e7fd0
commit
3803d7e3c2
@ -8,6 +8,8 @@ import (
|
|||||||
|
|
||||||
"kitty/tools/cli/markup"
|
"kitty/tools/cli/markup"
|
||||||
"kitty/tools/utils"
|
"kitty/tools/utils"
|
||||||
|
|
||||||
|
"golang.org/x/exp/maps"
|
||||||
)
|
)
|
||||||
|
|
||||||
var _ = fmt.Print
|
var _ = fmt.Print
|
||||||
@ -21,7 +23,7 @@ func fish_completion_script(commands []string) (string, error) {
|
|||||||
"kitten": true,
|
"kitten": true,
|
||||||
}
|
}
|
||||||
if len(commands) == 0 {
|
if len(commands) == 0 {
|
||||||
commands = append(commands, utils.Keys(all_commands)...)
|
commands = append(commands, maps.Keys(all_commands)...)
|
||||||
}
|
}
|
||||||
script := strings.Builder{}
|
script := strings.Builder{}
|
||||||
script.WriteString(`function __ksi_completions
|
script.WriteString(`function __ksi_completions
|
||||||
|
|||||||
@ -17,6 +17,7 @@ import (
|
|||||||
"kitty/tools/utils"
|
"kitty/tools/utils"
|
||||||
"kitty/tools/utils/images"
|
"kitty/tools/utils/images"
|
||||||
|
|
||||||
|
"golang.org/x/exp/maps"
|
||||||
"golang.org/x/exp/slices"
|
"golang.org/x/exp/slices"
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -363,7 +364,7 @@ func run_get_loop(opts *Options, args []string) (err error) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
if len(requested_mimes) > 0 {
|
if len(requested_mimes) > 0 {
|
||||||
lp.QueueWriteString(encode(basic_metadata, strings.Join(utils.Keys(requested_mimes), " ")))
|
lp.QueueWriteString(encode(basic_metadata, strings.Join(maps.Keys(requested_mimes), " ")))
|
||||||
} else {
|
} else {
|
||||||
lp.Quit(0)
|
lp.Quit(0)
|
||||||
}
|
}
|
||||||
|
|||||||
@ -120,30 +120,6 @@ func Min[T constraints.Ordered](a T, items ...T) (ans T) {
|
|||||||
return ans
|
return ans
|
||||||
}
|
}
|
||||||
|
|
||||||
// Keys returns the keys of the map m.
|
|
||||||
// The keys will be an indeterminate order.
|
|
||||||
func Keys[M ~map[K]V, K comparable, V any](m M) []K {
|
|
||||||
r := make([]K, len(m))
|
|
||||||
i := 0
|
|
||||||
for k := range m {
|
|
||||||
r[i] = k
|
|
||||||
i++
|
|
||||||
}
|
|
||||||
return r
|
|
||||||
}
|
|
||||||
|
|
||||||
// Values returns the values of the map m.
|
|
||||||
// The values will be an indeterminate order.
|
|
||||||
func Values[M ~map[K]V, K comparable, V any](m M) []V {
|
|
||||||
r := make([]V, len(m))
|
|
||||||
i := 0
|
|
||||||
for _, v := range m {
|
|
||||||
r[i] = v
|
|
||||||
i++
|
|
||||||
}
|
|
||||||
return r
|
|
||||||
}
|
|
||||||
|
|
||||||
func Memset[T any](dest []T, pattern ...T) []T {
|
func Memset[T any](dest []T, pattern ...T) []T {
|
||||||
if len(pattern) == 0 {
|
if len(pattern) == 0 {
|
||||||
var zero T
|
var zero T
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user