github.com/lmorg/murex@v0.0.0-20240217211045-e081c89cd4ef/utils/readline/events.go (about)

     1  package readline
     2  
     3  // EventReturn is a structure returned by the callback event function.
     4  // This is used by readline to determine what state the API should
     5  // return to after the readline event.
     6  type EventReturn struct {
     7  	ForwardKey     bool
     8  	ClearHelpers   bool
     9  	CloseReadline  bool
    10  	DisplayPreview bool
    11  	HintText       []rune
    12  	NewLine        []rune
    13  	NewPos         int
    14  	Callback       func() error
    15  }
    16  
    17  // AddEvent registers a new keypress handler
    18  func (rl *Instance) AddEvent(keyPress string, callback func(string, []rune, int) *EventReturn) {
    19  	rl.evtKeyPress[keyPress] = callback
    20  }
    21  
    22  // DelEvent deregisters an existing keypress handler
    23  func (rl *Instance) DelEvent(keyPress string) {
    24  	delete(rl.evtKeyPress, keyPress)
    25  }