From bc7c09c472359983e0c64fc429e2be74e3557ce2 Mon Sep 17 00:00:00 2001 From: rsteube Date: Sat, 7 Oct 2023 11:09:18 +0200 Subject: [PATCH] tmp --- completers/wezterm_completer/cmd/cli_list.go | 24 +++++++++ .../wezterm_completer/cmd/cli_listClients.go | 24 +++++++++ completers/wezterm_completer/cmd/l.txt | 6 +++ pkg/actions/tools/wezterm/pane.go | 49 +++++++++++++++++++ 4 files changed, 103 insertions(+) create mode 100644 completers/wezterm_completer/cmd/cli_list.go create mode 100644 completers/wezterm_completer/cmd/cli_listClients.go create mode 100644 completers/wezterm_completer/cmd/l.txt create mode 100644 pkg/actions/tools/wezterm/pane.go diff --git a/completers/wezterm_completer/cmd/cli_list.go b/completers/wezterm_completer/cmd/cli_list.go new file mode 100644 index 0000000000..ed71d46acd --- /dev/null +++ b/completers/wezterm_completer/cmd/cli_list.go @@ -0,0 +1,24 @@ +package cmd + +import ( + "github.com/rsteube/carapace" + "github.com/spf13/cobra" +) + +var cli_listCmd = &cobra.Command{ + Use: "list", + Short: "list windows, tabs and panes", + Run: func(cmd *cobra.Command, args []string) {}, +} + +func init() { + carapace.Gen(cli_listCmd).Standalone() + + cli_listCmd.Flags().String("format", "", "Controls the output format") + cli_listCmd.Flags().BoolP("help", "h", false, "Print help") + cliCmd.AddCommand(cli_listCmd) + + carapace.Gen(cli_listCmd).FlagCompletion(carapace.ActionMap{ + "format": carapace.ActionValues("table", "json"), + }) +} diff --git a/completers/wezterm_completer/cmd/cli_listClients.go b/completers/wezterm_completer/cmd/cli_listClients.go new file mode 100644 index 0000000000..0103b59f02 --- /dev/null +++ b/completers/wezterm_completer/cmd/cli_listClients.go @@ -0,0 +1,24 @@ +package cmd + +import ( + "github.com/rsteube/carapace" + "github.com/spf13/cobra" +) + +var cli_listClientsCmd = &cobra.Command{ + Use: "list-clients", + Short: "list clients", + Run: func(cmd *cobra.Command, args []string) {}, +} + +func init() { + carapace.Gen(cli_listClientsCmd).Standalone() + + cli_listClientsCmd.Flags().String("format", "", "Controls the output format") + cli_listClientsCmd.Flags().BoolP("help", "h", false, "Print help") + cliCmd.AddCommand(cli_listClientsCmd) + + carapace.Gen(cli_listClientsCmd).FlagCompletion(carapace.ActionMap{ + "format": carapace.ActionValues("table", "json"), + }) +} diff --git a/completers/wezterm_completer/cmd/l.txt b/completers/wezterm_completer/cmd/l.txt new file mode 100644 index 0000000000..fe048e8e69 --- /dev/null +++ b/completers/wezterm_completer/cmd/l.txt @@ -0,0 +1,6 @@ +list windows, tabs and panes + +Usage: wezterm cli list [OPTIONS] + + --format Controls the output format + -h, --help Print help diff --git a/pkg/actions/tools/wezterm/pane.go b/pkg/actions/tools/wezterm/pane.go new file mode 100644 index 0000000000..1416e83a5e --- /dev/null +++ b/pkg/actions/tools/wezterm/pane.go @@ -0,0 +1,49 @@ +package wezterm + +import ( + "encoding/json" + + "github.com/rsteube/carapace" +) + +type pane struct { + WindowID int `json:"window_id"` + TabID int `json:"tab_id"` + PaneID int `json:"pane_id"` + Workspace string `json:"workspace"` + Size struct { + Rows int `json:"rows"` + Cols int `json:"cols"` + PixelWidth int `json:"pixel_width"` + PixelHeight int `json:"pixel_height"` + Dpi int `json:"dpi"` + } `json:"size"` + Title string `json:"title"` + Cwd string `json:"cwd"` + CursorX int `json:"cursor_x"` + CursorY int `json:"cursor_y"` + CursorShape string `json:"cursor_shape"` + CursorVisibility string `json:"cursor_visibility"` + LeftCol int `json:"left_col"` + TopRow int `json:"top_row"` + TabTitle string `json:"tab_title"` + WindowTitle string `json:"window_title"` + IsActive bool `json:"is_active"` + IsZoomed bool `json:"is_zoomed"` + TtyName string `json:"tty_name"` +} + +func ActionPanes() carapace.Action { + return carapace.ActionExecCommand("wezterm", "cli", "list", "--format", "json")(func(output []byte) carapace.Action { + var panes []pane + if err := json.Unmarshal(output, &panes); err != nil { + return carapace.ActionMessage(err.Error()) + } + + vals := make([]string, 0) + for _, p := range panes { + vals = append(vals, p.PaneID, p.Title) + } + }) + +}