...

Source file src/github.com/c-bata/go-prompt/key_bind.go

Documentation: github.com/c-bata/go-prompt

     1  package prompt
     2  
     3  // KeyBindFunc receives buffer and processed it.
     4  type KeyBindFunc func(*Buffer)
     5  
     6  // KeyBind represents which key should do what operation.
     7  type KeyBind struct {
     8  	Key Key
     9  	Fn  KeyBindFunc
    10  }
    11  
    12  // ASCIICodeBind represents which []byte should do what operation
    13  type ASCIICodeBind struct {
    14  	ASCIICode []byte
    15  	Fn        KeyBindFunc
    16  }
    17  
    18  // KeyBindMode to switch a key binding flexibly.
    19  type KeyBindMode string
    20  
    21  const (
    22  	// CommonKeyBind is a mode without any keyboard shortcut
    23  	CommonKeyBind KeyBindMode = "common"
    24  	// EmacsKeyBind is a mode to use emacs-like keyboard shortcut
    25  	EmacsKeyBind KeyBindMode = "emacs"
    26  )
    27  
    28  var commonKeyBindings = []KeyBind{
    29  	// Go to the End of the line
    30  	{
    31  		Key: End,
    32  		Fn:  GoLineEnd,
    33  	},
    34  	// Go to the beginning of the line
    35  	{
    36  		Key: Home,
    37  		Fn:  GoLineBeginning,
    38  	},
    39  	// Delete character under the cursor
    40  	{
    41  		Key: Delete,
    42  		Fn:  DeleteChar,
    43  	},
    44  	// Backspace
    45  	{
    46  		Key: Backspace,
    47  		Fn:  DeleteBeforeChar,
    48  	},
    49  	// Right allow: Forward one character
    50  	{
    51  		Key: Right,
    52  		Fn:  GoRightChar,
    53  	},
    54  	// Left allow: Backward one character
    55  	{
    56  		Key: Left,
    57  		Fn:  GoLeftChar,
    58  	},
    59  }
    60  

View as plain text