hotkey

package
v0.0.18 Latest Latest
Warning

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

Go to latest
Published: Aug 13, 2023 License: BSD-3-Clause, BSD-3-Clause Imports: 4 Imported by: 2

README

Go terminal/console hotkeys support

Go Reference

This repository provides Go terminal and console hotkeys support packages.

Download/Install

The easiest way to install is to run go get -u github.com/teonet-go/tru/term. You can also manually git clone the repository to $GOPATH/src/github.com/teonet-go/tru/hotkey.

Report Issues / Send Patches

This repository uses Gerrit for code changes. To learn how to submit changes to this repository, see github.com/teonet-go/tru/issues.

The main issue tracker for the hotkey repository is located at github.com/teonet-go/tru/issues. Prefix your issue with "teo/hotkey: " in the subject line, so it is easy to find.

Documentation

Overview

Package hotkey provides support functions for managing hotkeys in terminal/console application.

Function Add is the most common requirement:

h := hotkey.New()
h.Add("H", func() { fmt.Println("This is Help") })

Note that on non-Unix systems os.Stdin.Fd() may not be 0 and Getch() may run incorrectly

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Hotkey

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

func New

func New() *Hotkey

New Create new hotkey menu

func (*Hotkey) Add

func (h *Hotkey) Add(keys interface{}, description string, action func(h *Hotkey)) *Hotkey

Add hotkey menu

func (*Hotkey) AddUnknown

func (h *Hotkey) AddUnknown(action func(h *Hotkey, ch []byte)) *Hotkey

AddUnknown add action function which executes when unknown key pressed

func (*Hotkey) NextKeyAction

func (h *Hotkey) NextKeyAction(f func(ch []byte))

NextKeyAction set action which execute when key pressed nex time

func (*Hotkey) Run

func (h *Hotkey) Run() *Hotkey

Run execute hotkey menu, wait key pressed and execute it action

func (*Hotkey) SetState

func (h *Hotkey) SetState(state interface{}) *Hotkey

SetState set users menu state. State is some interface which user can use in its hotkey menu. State is place where user can save its own menu parameters

func (*Hotkey) SetStopAction

func (h *Hotkey) SetStopAction(f func())

SetStopAction set callback function which will run when hotkey menu Stop

func (*Hotkey) State

func (h *Hotkey) State() interface{}

State return saved user menu state

func (*Hotkey) Stop

func (h *Hotkey) Stop()

Stop execute hotkey menu

func (*Hotkey) String

func (h *Hotkey) String() (str string)

String return string contains hotkey menu help

type KeyCode

type KeyCode struct {
	Code []byte
	Name string
}

KeyCode define key code and key name which hows in hokey meny

Directories

Path Synopsis
examples

Jump to

Keyboard shortcuts

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