diff --git a/tools/cli/completion-main.go b/tools/cli/completion-main.go index 55821fd1f..07c3cac32 100644 --- a/tools/cli/completion-main.go +++ b/tools/cli/completion-main.go @@ -7,9 +7,9 @@ import ( "fmt" "io" "os" + "strings" "kitty/tools/tty" - "kitty/tools/utils" ) func debug(args ...any) { @@ -81,7 +81,7 @@ func GenerateCompletions(args []string) error { } shell_state := make(map[string]string, n) for _, arg := range args { - k, v, found := utils.Cut(arg, "=") + k, v, found := strings.Cut(arg, "=") if !found { return fmt.Errorf("Invalid shell state specification: %s", arg) } diff --git a/tools/cli/completion.go b/tools/cli/completion.go index 260c213f3..68c9dd2da 100644 --- a/tools/cli/completion.go +++ b/tools/cli/completion.go @@ -36,7 +36,7 @@ func (self *MatchGroup) remove_common_prefix() string { } } } else if len(self.Matches) > 1 && strings.HasPrefix(self.Matches[0].Word, "--") && strings.Contains(self.Matches[0].Word, "=") { - lcp, _, _ := utils.Cut(self.longest_common_prefix(), "=") + lcp, _, _ := strings.Cut(self.longest_common_prefix(), "=") lcp += "=" if len(lcp) > 3 { self.remove_prefix_from_all_matches(lcp) diff --git a/tools/cli/zsh.go b/tools/cli/zsh.go index f810062fe..8f8aacf40 100644 --- a/tools/cli/zsh.go +++ b/tools/cli/zsh.go @@ -76,7 +76,7 @@ func (self *Match) FormatForCompletionList(max_word_len int, f *markup.Context, return word } word_len := wcswidth.Stringwidth(word) - line, _, _ := utils.Cut(strings.TrimSpace(desc), "\n") + line, _, _ := strings.Cut(strings.TrimSpace(desc), "\n") desc = f.Prettify(line) multiline := false diff --git a/tools/cmd/at/env.go b/tools/cmd/at/env.go index 33ab77a78..71aa5cecd 100644 --- a/tools/cmd/at/env.go +++ b/tools/cmd/at/env.go @@ -3,13 +3,13 @@ package at import ( - "kitty/tools/utils" + "strings" ) func parse_key_val_args(args []string) map[escaped_string]escaped_string { ans := make(map[escaped_string]escaped_string, len(args)) for _, arg := range args { - key, value, found := utils.Cut(arg, "=") + key, value, found := strings.Cut(arg, "=") if found { ans[escaped_string(key)] = escaped_string(value) } else { diff --git a/tools/cmd/at/main.go b/tools/cmd/at/main.go index 6a32fefd1..f3e5bfa1b 100644 --- a/tools/cmd/at/main.go +++ b/tools/cmd/at/main.go @@ -80,7 +80,7 @@ func get_pubkey(encoded_key string) (encryption_version string, pubkey []byte, e return } } - encryption_version, encoded_key, found := utils.Cut(encoded_key, ":") + encryption_version, encoded_key, found := strings.Cut(encoded_key, ":") if !found { err = fmt.Errorf("KITTY_PUBLIC_KEY environment variable does not have a : in it") return diff --git a/tools/cmd/at/set_colors.go b/tools/cmd/at/set_colors.go index 4f321c101..0dbe5ddc0 100644 --- a/tools/cmd/at/set_colors.go +++ b/tools/cmd/at/set_colors.go @@ -48,7 +48,7 @@ func set_color_in_color_map(key, val string, ans map[string]any, check_nullable, func parse_colors_and_files(args []string) (map[string]any, error) { ans := make(map[string]any, len(args)) for _, arg := range args { - key, val, found := utils.Cut(strings.ToLower(arg), "=") + key, val, found := strings.Cut(strings.ToLower(arg), "=") if found { err := set_color_in_color_map(key, val, ans, true, false) if err != nil { @@ -63,7 +63,7 @@ func parse_colors_and_files(args []string) (map[string]any, error) { defer f.Close() scanner := bufio.NewScanner(f) for scanner.Scan() { - key, val, found := utils.Cut(scanner.Text(), " ") + key, val, found := strings.Cut(scanner.Text(), " ") if found { set_color_in_color_map(strings.ToLower(key), strings.ToLower(strings.TrimSpace(val)), ans, true, true) } diff --git a/tools/cmd/at/set_spacing.go b/tools/cmd/at/set_spacing.go index d2953ea8f..cfb093f00 100644 --- a/tools/cmd/at/set_spacing.go +++ b/tools/cmd/at/set_spacing.go @@ -6,8 +6,6 @@ import ( "fmt" "strconv" "strings" - - "kitty/tools/utils" ) func parse_set_spacing(args []string) (map[string]any, error) { @@ -24,7 +22,7 @@ func parse_set_spacing(args []string) (map[string]any, error) { mapper[q+"-bottom"] = []string{q + "bottom"} } for _, arg := range args { - k, v, found := utils.Cut(arg, "=") + k, v, found := strings.Cut(arg, "=") if !found { return nil, fmt.Errorf("%s is not a valid setting", arg) } diff --git a/tools/cmd/at/set_tab_color.go b/tools/cmd/at/set_tab_color.go index 8af30657d..b9c36f181 100644 --- a/tools/cmd/at/set_tab_color.go +++ b/tools/cmd/at/set_tab_color.go @@ -5,8 +5,6 @@ package at import ( "fmt" "strings" - - "kitty/tools/utils" ) var valid_color_names = map[string]bool{"active_fg": true, "active_bg": true, "inactive_fg": true, "inactive_bg": true} @@ -14,7 +12,7 @@ var valid_color_names = map[string]bool{"active_fg": true, "active_bg": true, "i func parse_tab_colors(args []string) (map[string]any, error) { ans := make(map[string]any, len(args)) for _, arg := range args { - key, val, found := utils.Cut(strings.ToLower(arg), "=") + key, val, found := strings.Cut(strings.ToLower(arg), "=") if !found { return nil, fmt.Errorf("%s is not a valid setting", arg) } diff --git a/tools/cmd/clipboard/read.go b/tools/cmd/clipboard/read.go index 2014b5c85..664e7ab02 100644 --- a/tools/cmd/clipboard/read.go +++ b/tools/cmd/clipboard/read.go @@ -269,7 +269,7 @@ func parse_escape_code(etype loop.EscapeCodeType, data []byte) (metadata map[str func parse_aliases(raw []string) (map[string][]string, error) { ans := make(map[string][]string, len(raw)) for _, x := range raw { - k, v, found := utils.Cut(x, "=") + k, v, found := strings.Cut(x, "=") if !found { return nil, fmt.Errorf("%s is not valid MIME alias specification", x) } diff --git a/tools/cmd/icat/magick.go b/tools/cmd/icat/magick.go index d3390730f..4fb30ed24 100644 --- a/tools/cmd/icat/magick.go +++ b/tools/cmd/icat/magick.go @@ -70,16 +70,16 @@ func parse_identify_record(ans *IdentifyRecord, raw *IdentifyOutput) (err error) } ans.Gap = utils.Max(0, ans.Gap) } - area, pos, found := utils.Cut(raw.Canvas, "+") + area, pos, found := strings.Cut(raw.Canvas, "+") ok := false if found { - w, h, found := utils.Cut(area, "x") + w, h, found := strings.Cut(area, "x") if found { ans.Canvas.Width, err = strconv.Atoi(w) if err == nil { ans.Canvas.Height, err = strconv.Atoi(h) if err == nil { - x, y, found := utils.Cut(pos, "+") + x, y, found := strings.Cut(pos, "+") if found { ans.Canvas.Left, err = strconv.Atoi(x) if err == nil { @@ -94,7 +94,7 @@ func parse_identify_record(ans *IdentifyRecord, raw *IdentifyOutput) (err error) if !ok { return fmt.Errorf("Invalid canvas value in identify output: %s", raw.Canvas) } - w, h, found := utils.Cut(raw.Size, "x") + w, h, found := strings.Cut(raw.Size, "x") ok = false if found { ans.Width, err = strconv.Atoi(w) @@ -106,7 +106,7 @@ func parse_identify_record(ans *IdentifyRecord, raw *IdentifyOutput) (err error) if !ok { return fmt.Errorf("Invalid size value in identify output: %s", raw.Size) } - x, y, found := utils.Cut(raw.Dpi, "x") + x, y, found := strings.Cut(raw.Dpi, "x") ok = false if found { ans.Dpi.X, err = strconv.ParseFloat(x, 64) @@ -302,7 +302,7 @@ func Render(path string, ro *RenderOptions, frames []IdentifyRecord) (ans []*ima min_gap := calc_min_gap(gaps) for _, entry := range entries { fname := entry.Name() - p, _, _ := utils.Cut(fname, ".") + p, _, _ := strings.Cut(fname, ".") parts := strings.Split(p, "-") if len(parts) < 5 { continue @@ -319,11 +319,11 @@ func Render(path string, ro *RenderOptions, frames []IdentifyRecord) (ans []*ima if cerr != nil { continue } - _, pos, found := utils.Cut(parts[3], "+") + _, pos, found := strings.Cut(parts[3], "+") if !found { continue } - px, py, found := utils.Cut(pos, "+") + px, py, found := strings.Cut(pos, "+") if !found { continue } diff --git a/tools/cmd/icat/main.go b/tools/cmd/icat/main.go index 301d3a49b..6ae0134a9 100644 --- a/tools/cmd/icat/main.go +++ b/tools/cmd/icat/main.go @@ -91,15 +91,15 @@ func parse_place() (err error) { if opts.Place == "" { return nil } - area, pos, found := utils.Cut(opts.Place, "@") + area, pos, found := strings.Cut(opts.Place, "@") if !found { return fmt.Errorf("Invalid --place specification: %s", opts.Place) } - w, h, found := utils.Cut(area, "x") + w, h, found := strings.Cut(area, "x") if !found { return fmt.Errorf("Invalid --place specification: %s", opts.Place) } - l, t, found := utils.Cut(pos, "x") + l, t, found := strings.Cut(pos, "x") if !found { return fmt.Errorf("Invalid --place specification: %s", opts.Place) } diff --git a/tools/utils/sockets.go b/tools/utils/sockets.go index c5823a2fb..fd23eadbe 100644 --- a/tools/utils/sockets.go +++ b/tools/utils/sockets.go @@ -10,15 +10,8 @@ import ( "github.com/seancfoley/ipaddress-go/ipaddr" ) -func Cut(s string, sep string) (string, string, bool) { - if i := strings.Index(s, sep); i >= 0 { - return s[:i], s[i+len(sep):], true - } - return s, "", false -} - func ParseSocketAddress(spec string) (network string, addr string, err error) { - network, addr, found := Cut(spec, ":") + network, addr, found := strings.Cut(spec, ":") if !found { err = fmt.Errorf("Invalid socket address: %s must be prefix by a protocol such as unix:", spec) return