Skip to content

Commit

Permalink
tmp
Browse files Browse the repository at this point in the history
  • Loading branch information
rsteube committed Mar 14, 2024
1 parent de340e4 commit b82ad93
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 0 deletions.
5 changes: 5 additions & 0 deletions completers/wl-mirror_completer/cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package cmd

import (
"github.com/carapace-sh/carapace"
"github.com/carapace-sh/carapace-bin/pkg/actions/tools/sway"
"github.com/spf13/cobra"
)

Expand Down Expand Up @@ -73,4 +74,8 @@ func init() {
"270", "apply a clockwise rotation",
).UniqueList("-"),
})

carapace.Gen(rootCmd).PositionalCompletion(
sway.ActionOutputs(), // TODO other sources
)
}
38 changes: 38 additions & 0 deletions pkg/actions/tools/sway/output.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
package sway

import (
"encoding/json"
"fmt"

"github.com/carapace-sh/carapace"
)

type swayOutput struct {
Name string
Make string
Modes []struct {
Width int
Height int
Refresh int
}
}

// ActionOutputs completes outputs
func ActionOutputs() carapace.Action {
return carapace.ActionExecCommand("swaymsg", "-t", "get_outputs")(func(output []byte) carapace.Action {
var outputs []swayOutput
if err := json.Unmarshal(output, &outputs); err != nil {
return carapace.ActionMessage(err.Error())
}

vals := make([]string, 0)
for _, o := range outputs {
description := o.Make
if len(o.Modes) > 0 {
description += fmt.Sprintf(" %vx%v @ %v Hz", o.Modes[0].Width, o.Modes[0].Height, float64(o.Modes[0].Refresh)/1000)
}
vals = append(vals, o.Name, description)
}
return carapace.ActionValuesDescribed(vals...)
})
}

0 comments on commit b82ad93

Please sign in to comment.