go-rofi
This library allows you to programmatically create outputs apt to be used as input to rofi running in script mode.
For example, my-program
uses go-rofi
to build rofi-script compatible options:
$ rofi -show my-choices -modi "my-choices:my-program"
Usage
var entries []struct{
URL string
Description string
Icon string
} {
{"https://foobar.com", "Some foobar", "nice-icon"},
}
r := rofi.New()
for _, e := range entries {
r.AddEntries(rofi.NewEntry(
e.Description,
rofi.WithInfo(e.URL),
rofi.WithMeta(e.URL),
rofi.WithIcon(e.Icon),
))
}
fmt.Println(r.Build())
You can also have your program execute rofi in script mode by instantiating a Runner
:
r := rofi.NewRunner("program-name", runnable)
output, err := r.Run()
if err != nil {
log.Fatal(err)
}
fmt.Println(output)
You can use dmenu
mode to select something within the flow of your program:
d := dmenu.New(
dmenu.WithPrompt("Choose"),
dmenu.WithMessage("This is a helpful message"),
dmenu.WithWindowID("56623151"),
dmenu.WithEntries(
entry.New("Hello", entry.WithIcon("folder")),
entry.New("World", entry.WithInfo("somethin something")),
entry.New("Hi", entry.WithMeta("find me")),
),
)
ctx := context.Background()
s, err := d.Select(ctx)
if err != nil {
log.Fatal(err)
}
fmt.Println("choice was", s)