rofi

package module
v0.0.2 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Apr 5, 2023 License: MIT Imports: 6 Imported by: 1

README

go-rofi-script

Go Report Card MIT Go Reference builds.sr.ht status

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-script to build some 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)

Documentation

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

func WithActive

func WithActive(active string) opt

Active row, mark X as active. Where X is a comma-separated list of python(1)-style indices and ranges, e.g. indices start at 0, -1 refers to the last row with -2 preceding it, ranges are left-open and right-close, and so on. You can specify:

  • A single row: '5'
  • A range of (last 3) rows: '-3:'
  • 4 rows starting from row 7: '7:11' (or in legacy notation: '7-10')
  • A set of rows: '2,0,-9'
  • Or any combination: '5,-3:,7:11,2,0,-9'

func WithData

func WithData(data string) opt

Passed data to the next execution of the script via ROFI_DATA.

func WithDelim

func WithDelim(delim string) opt

Set the delimiter for next rows.

func WithEntries

func WithEntries(entries ...*Entry) opt

func WithIcon

func WithIcon(icon string) entryOpt

Set the icon for that row.

func WithInfo

func WithInfo(info string) entryOpt

Info that, on selection, gets placed in the ROFI_INFO environment variable. This entry does not get searched.

func WithKeepSelection

func WithKeepSelection() opt

If set, the selection is not moved to the first entry, but the current position is maintained. The filter is cleared.

func WithMarkupRows

func WithMarkupRows() opt

Render markup in the row.

func WithMessage

func WithMessage(message string) opt

Update the message text.

func WithMeta

func WithMeta(meta string) entryOpt

Specify invisible search terms.

func WithNewSelection

func WithNewSelection() opt

If keep-selection is set, this allows you to override the selected entry (absolute position).

func WithNoCustom

func WithNoCustom() opt

Ignore custom input.

func WithNonSelectable

func WithNonSelectable() entryOpt

Make so that row cannot activated.

func WithPrompt

func WithPrompt(prompt string) opt

Update the prompt text.

func WithTheme

func WithTheme(theme string) opt

Small theme snippet to f.e. change the background color of a widget.

func WithUrgent

func WithUrgent(urgent string) opt

Urgent row, mark X as urgent. Where X is a comma-separated list of python(1)-style indices and ranges, e.g. indices start at 0, -1 refers to the last row with -2 preceding it, ranges are left-open and right-close, and so on. You can specify:

  • A single row: '5'
  • A range of (last 3) rows: '-3:'
  • 4 rows starting from row 7: '7:11' (or in legacy notation: '7-10')
  • A set of rows: '2,0,-9'
  • Or any combination: '5,-3:,7:11,2,0,-9'

func WithUseHotKeys

func WithUseHotKeys() opt

If set to true, it enabled the Custom keybindings for script. Warning this breaks the normal rofi flow.

Types

type Entry

type Entry struct {
	// contains filtered or unexported fields
}

func NewEntry

func NewEntry(text string, opts ...entryOpt) *Entry

func (*Entry) Build

func (e *Entry) Build() string

type Rofi

type Rofi struct {
	// contains filtered or unexported fields
}

func New

func New(opts ...opt) *Rofi

func (*Rofi) AddEntries

func (r *Rofi) AddEntries(entries ...*Entry)

func (*Rofi) Build

func (r *Rofi) Build() string
Example
r := rofi.New()
fmt.Print(r.Build())
Output:

Example (Second)
r := rofi.New(rofi.WithEntries(
	rofi.NewEntry("option 1"),
	rofi.NewEntry("option 2"),
))

fmt.Print(r.Build())
Output:

option 1
option 2

type Runnable added in v0.0.2

type Runnable interface {
	FirstRun() (string, error)
	OnSelection(selection, info, data string) (string, error)
}

Runnable represents an object that can provide options for rofi-script to run successfully.

type Runner

type Runner struct {
	// contains filtered or unexported fields
}

func NewRunner

func NewRunner(name string, runnable Runnable) *Runner

func (*Runner) Run

func (r *Runner) Run() (string, error)

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL