rofigo

package module
v0.0.1 Latest Latest
Warning

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

Go to latest
Published: Oct 1, 2023 License: MIT Imports: 5 Imported by: 0

README

rofigo - Rofi Integration for Command-Line Menus

rofigo is a Go package that simplifies the integration of Rofi, a versatile application launcher and window switcher for X11, into your command-line applications. It allows you to create interactive menus with customizable options, labels, and actions, making it easy for users to navigate and interact with your CLI application.

Overview

  • MenuItem: Represents an item within a menu. Each MenuItem has a label, an associated action, and an optional icon. You can customize menu items to perform specific actions when selected.

  • Menu: Represents a collection of menu items along with an optional prompt. Menus help group related items together and provide a user-friendly interface for selecting actions.

  • RofiRunner: A utility for running Rofi-based menus with custom options. You can create an instance of RofiRunner and execute Rofi menus with specific settings, such as prompts and menu items.

Example

Here's a simple example of how to use rofigo to create and run a menu with Rofi:

// Create a menu
myMenu := rofigo.NewMenu().WithPrompt("Select an option:")

// Add menu items
item1 := rofigo.NewMenuItem("Option 1", func() error {
    // Define the action for Option 1
    // ...
    return nil
}, "")
item2 := rofigo.NewMenuItem("Option 2", func() error {
    // Define the action for Option 2
    // ...
    return nil
}, "")

myMenu.WithItems(item1, item2)

// Create a RofiRunner and run the menu
runner := rofigo.NewRofiRunner(myMenu)
runner.Run()

This code creates a menu with two options and executes it using Rofi. Usage

Step 1: Install Rofi on your system if it's not already installed.
Step 2: Install the rofigo pacakge:
"go get github.com/AlwaysOutofRange/rofigo"

Step 3: Import the rofigo package into your Go project:
"import "github.com/AlwaysOutofRange/rofigo""

Follow the example above to create and run interactive menus in your command-line application.

Package Dependencies

rofigo relies on the external tool Rofi, so ensure you have Rofi installed on your system to use this package effectively. License

License

This project is licensed under the MIT License - see the LICENSE file for details.

Documentation

Overview

Rofi is a versatile application launcher and window switcher for X11. The "rofigo" package allows you to easily create and display interactive menus in your command-line applications using Rofi. With "rofigo," you can define custom menus with items, labels, icons, and actions, providing a user-friendly way to navigate and interact with your application.

Key Components

This package consists of the following key components:

  1. MenuItem: Represents an item within a menu. Each MenuItem has a label, an associated action, and an optional icon. Menu items can be customized to perform specific actions when selected.

  2. Menu: Represents a collection of menu items along with an optional prompt. Menus are used to group related items together and provide a user-friendly interface for selecting actions.

  3. RofiRunner: A utility for running Rofi-based menus with custom options. You can create an instance of RofiRunner and execute Rofi menus with specific settings, such as prompts and menu items.

Usage Example

Here's a simple example of how to use "rofigo" to create a menu and run it with Rofi:

// Create a menu
myMenu := rofigo.NewMenu().WithPrompt("Select an option:")

// Add menu items
item1 := rofigo.NewMenuItem("Option 1", func() error {
    // Define the action for Option 1
    // ...
    return nil
}, "")
item2 := rofigo.NewMenuItem("Option 2", func() error {
    // Define the action for Option 2
    // ...
    return nil
}, "")

myMenu.WithItems(item1, item2)

// Create a RofiRunner and run the menu
runner := rofigo.NewRofiRunner(myMenu)
runner.Run()

This code creates a menu with two options and executes it using Rofi.

Package Dependencies

The "rofigo" package relies on external tools like Rofi, so make sure you have Rofi installed on your system to use this package.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Menu struct {
	Prompt string
	Items  []*MenuItem
}

Menu represents a collection of menu items along with an optional prompt.

func NewMenu

func NewMenu() *Menu

NewMenu creates a new Menu with an empty prompt and an empty list of items.

func (m *Menu) WithItem(item *MenuItem) *Menu

WithItem adds a single MenuItem to the Menu and returns the modified Menu. You can use this method to customize the menu by adding individual items.

func (m *Menu) WithItems(items ...*MenuItem) *Menu

method to add multiple items to the menu in a single call.

func (m *Menu) WithPrompt(prompt string) *Menu

WithPrompt sets the prompt text for the menu and returns the modified Menu.

type MenuItem struct {
	Label  string
	Action func() error
	Icon   string
}

MenuItem represents an item within a menu. Each MenuItem has a label, an associated action, and an optional icon.

func NewMenuItem

func NewMenuItem(label string, action func() error, icon string) *MenuItem

NewMenuItem creates a new MenuItem with the specified label, action, and icon.

type RofiRunner

type RofiRunner struct {
	Menu *Menu
}

RofiRunner is a utility for running Rofi-based menus with custom options.

func NewRofiRunner

func NewRofiRunner(menu *Menu) *RofiRunner

NewRofiRunner creates a new RofiRunner instance with the specified menu.

func (*RofiRunner) Run

func (r *RofiRunner) Run()

Run executes the Rofi menu using the specified options and runs the associated action when an item is selected.

Jump to

Keyboard shortcuts

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